zod-mod
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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

Package Sidebar

Install

npm i zod-mod

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

13.3 kB

Total Files

7

Last publish

Collaborators

  • szum-tech