npm.io
2.0.1 • Published 5 months ago

is-zod

Licence
MIT
Version
2.0.1
Deps
1
Size
6 kB
Vulns
0
Weekly
0
Stars
1

is-zod

NPM TypeScript

Typeguard to check if a value matches a zod schema.

Installation

NPM
npm install is-zod
Yarn
yarn add is-zod
PNPM
pnpm add is-zod
Bun
bun 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; }
}

Dependenciesdependencies

  • zod: TypeScript-first schema declaration and validation library with static type inference

License license

MIT - MIT License

Keywords