A Zod utility library to generate default values for Zod schemas.
This is not an official Zod library. This is a personal project which is mainly meant to be used by my other projects. However, you are free to use it if you find it useful.
This library is currently in development and not all functionality from zod is supported yet.
This package expects Zod to be installed.
Using npm (or yarn/pnpm/bun):
npm install zod-defaults
Create a schema and call the getDefaultsForSchema
function to generate an object
filled with the default or empty values matching your schema.
import {z} from 'zod';
import {getDefaultsForSchema} from 'zod-defaults';
const schema = z.object({
name: z.string().default('John Doe'),
age: z.number(),
isStudent: z.boolean(),
});
const person = getDefaultsForSchema(schema);
console.log(person);
// { name: 'John Doe', age: 0, isStudent: false }
This project is licensed under the MIT License - see the LICENSE file for details.