zod-schema-utils
v1.0.2
Published
Reusable Zod schema utility functions for JavaScript.
Downloads
5
Readme
zod-schema-utils
Reusable utility functions for building and validating Zod schemas in JavaScript.
✨ Features
- Create reusable Zod object schemas
- Validate numbers with constraints like positive, min, max
- Will be adding more
- Lightweight and simple utility
📦 Installation
npm install zod-schema-utilsMake sure
zodis installed if it’s not already.
📚 Usage
import { createZodSchema, positiveNumber, rangedNumber } from 'zod-schema-utils';
const schema = createZodSchema({
age: positiveNumber(),
score: rangedNumber(0, 100)
});
schema.parse({ age: 25, score: 88 }); // ✅🧩 API
createZodSchema(shape: object): ZodObject
Wraps a plain shape object into a z.object.
positiveNumber(): ZodNumber
Returns a Zod number schema that only allows positive numbers.
rangedNumber(min?: number, max?: number): ZodNumber
Returns a Zod number schema with optional min and max range.
📄 License
MIT © Maung Shine
