zod-mod
v1.0.1
Published
ZodMod is an extension for Zod that allows you to dynamically modify validation schemas
Maintainers
Readme
📚 Features
- 🔄 Dynamically modify schemas – add extra validation rules on the fly
- 🚀 Seamless integration – fully compatible with existing Zod schemas
- ⚡ Simple syntax – modify only what you need
📖 Table of Contents
🎯 Getting Started
⚙️ Installation
npm install zod-modUsage
import { z } from "zod";
import { modifySchema } from "zod-mod";
const baseSchema = z.object({
username: z.string(),
age: z.number()
});
const modifiedSchema = modifySchema(baseSchema, [
{
type: "NOT_EQUAL",
path: "age",
value: 18,
errorMessage: "Age cannot be 18"
}
]);
console.log(modifiedSchema.parse({ username: "John", age: 18 }));
// => ZodError: [
// {
// "code": "custom",
// "message": "Age cannot be 18",
// "path": [
// "age"
// ]
// }
// ]Supported Validations
notEqual– ensures the value is not equal to a specified value
