Skip to content

ZodMod is an extension for Zod that allows you to dynamically modify validation schemas. With it, you can easily add extra rules, such as notEqual, to existing schemas without rewriting them manually.

License

Notifications You must be signed in to change notification settings

JanSzewczyk/zod-mod

Repository files navigation

ZodMod 📏✨

ZodMod is an extension for Zod that allows you to dynamically modify validation schemas. With it, you can easily add extra rules, such as notEqual, to existing schemas without rewriting them manually.

📚 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-mod

Usage

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

🛠️ Developer Info

Peer Dependencies

NPM dev or peer Dependency Version

About

ZodMod is an extension for Zod that allows you to dynamically modify validation schemas. With it, you can easily add extra rules, such as notEqual, to existing schemas without rewriting them manually.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •