Zod

Zod

github.com

1

About this website

Zod is a TypeScript-first schema declaration and validation library that enables developers to define data schemas with full static type inference, runtime validation, and automatic TypeScript type generation from a single source of truth. Created by Colin McDonnell (colinhacks) and first released in March 2020, Zod has rapidly become the most popular runtime validation library in the TypeScript ecosystem, with over 35,000 GitHub stars and tens of millions of weekly npm downloads. The library's core philosophy is that schemas should double as TypeScript types, eliminating the need to maintain separate type definitions and validation logic that can drift out of sync. Zod provides a fluent, chainable API for defining primitive types (z.string, z.number, z.boolean, z.bigint, z.date, z.symbol), complex types (z.object, z.array, z.tuple, z.record, z.map, z.set, z.enum, z.literal, z.union, z.intersection, z.discriminatedUnion), and specialized validators including z.string().email(), .url(), .uuid(), .ip(), .regex(), .min(), .max(), z.number().int(), .positive(), .negative(), .multipleOf(), and refinements via .refine() and .superRefine() for custom validation logic. Zod supports advanced patterns like optional and nullable fields with .optional() and .nullable(), default values with .default(), transformations with .transform() and .pipe(), branded types with z.brand(), recursive schemas using z.lazy(), conditional validation, and schema composition. The library integrates seamlessly with popular frameworks including React Hook Form (via @hookform/resolvers/zod), TanStack Form, tRPC (for end-to-end type-safe APIs), Next.js, Hono, Express (via middleware), Remix, Astro, and Drizzle ORM (for database schema validation). Zod also supports JSON Schema generation via zod-to-json-schema, OpenAPI spec generation, and form auto-generation. Zero dependencies, tree-shakeable, and isomorphic (works in Node.js, browsers, Deno, and Bun).

Tags & Categories

Categories

Tags

Statistics

1
Views
0
Clicks
0
Like
0
Dislike

Comments

Log In to post a comment

No comments yet. Be the first!