zod-metadata
Metadata support for Zod schemas.
Installation
npm install zod-metadata
yarn add zod-metadata
pnpn add zod-metadata
Basic Usage
import 'zod-metadata/register';
import { z } from 'zod';
const schema = z.string().meta({
example: 'John',
number: 42,
});
schema.getMeta();
Registration
Automatic
Import zod-metadata/register
at the top of your entry files:
JavaScript
require('zod-metadata/register');
TypeScript
import 'zod-metadata/register';
Manual
JavaScript
const { register } = require('zod-metadata');
const zod = require('zod');
register(zod);
TypeScript
import { register } from 'zod-metadata';
import zod from 'zod';
register(zod);
Preload
JavaScript
node -r zod-metadata/register my-script.js
require('zod-metadata');
TypeScript
ts-node -r zod-metadata/register my-script.js
import {} from 'zod-metadata';