1.0.0 • Published 1 year ago

is-zod v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

If I should maintain this repo, please ⭐️

DM me on Twitter if you have questions or suggestions.


Installation

npm install is-zod
yarn add is-zod
pnpm add is-zod

Usage

Is

import { z } from 'zod';
import is from 'is-zod';

const user = z.object({
  name: z.string(),
  age: z.number()
});

const value = {
  name: 'Bob',
  age: 42
};

if(is(value, user)) {
  // value is typed as { name: string; age: number; }
}

Validate

import { z } from 'zod';
import { validate } from 'is-zod';

const user = z.object({
  name: z.string(),
  age: z.number(),
});

const isUser = validate(user);

const value = {
  name: 'Bob',
  age: 42,
};

if(isUser(value)) {
  // value is typed as { name: string; age: number; }
}
  • zod: TypeScript-first schema declaration and validation library with static type inference
  • autorepo: Autorepo abstracts away your dev dependencies, providing a single command to run all of your scripts.

MIT