{"name":"zod","version":"3.24.3","keywords":["typescript","schema","validation","type","inference"],"author":{"name":"Colin McDonnell","email":"colin@colinhacks.com"},"license":"MIT","_id":"zod@3.24.3","maintainers":[{"name":"colinhacks","email":"colinmcd94@gmail.com"}],"homepage":"https://zod.dev","bugs":{"url":"https://github.com/colinhacks/zod/issues"},"dist":{"shasum":"1f40f750a05e477396da64438e0e1c0995dafd87","tarball":"http://registry-npm.ywwl.com/zod/download/zod-3.24.3.tgz","fileCount":52,"integrity":"sha512-HhY1oqzWCQWuUqvBFnsyrtZRhyPeR7SUGv+C4+MsisMuVfSPx8HpwWqH8tRahSlt6M3PiFAcoeFhZAqIXTxoSg==","signatures":[{"sig":"MEQCIGrC7h5iA6xaVxMAO6Qjy1OiD2zXRs+aXWd1/P/BcRZPAiA1FqCW0oxD0k/0DaKWhJFcYwnag5NiMZdC3Egs34RkHQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/zod@3.24.3","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":697771,"size":122068,"noattachment":false,"key":"/zod/-/zod-3.24.3.tgz"},"main":"./lib/index.js","types":"./index.d.ts","module":"./lib/index.mjs","exports":{".":{"types":"./index.d.ts","import":"./lib/index.mjs","require":"./lib/index.js"},"./locales/*":"./lib/locales/*","./package.json":"./package.json"},"funding":"https://github.com/sponsors/colinhacks","gitHead":"a18d25b297d1a47dca8f1701afb18079c05e1e4c","scripts":{"fix":"yarn lint:fix && yarn prettier:fix","docs":"netlify dev","play":"nodemon -e ts -w . -x tsx playground.ts","test":"yarn test:ts-jest","build":"yarn run clean && npm run build:cjs && npm run build:esm && npm run build:deno","check":"yarn lint:check && yarn prettier:check","clean":"rm -rf lib/* deno/lib/*","prepare":"husky install","lint:fix":"eslint --cache --fix --ext .ts ./src","test:bun":"bun test src/","test:swc":"npx jest --config ./configs/swc-jest.config.json","benchmark":"tsx src/benchmarks/index.ts","build:cjs":"tsc -p ./configs/tsconfig.cjs.json","build:esm":"rollup --config ./configs/rollup.config.js","depcruise":"depcruise -c .dependency-cruiser.js src","test:deno":"cd deno && deno test","build:deno":"node ./deno-build.mjs && cp ./README.md ./deno/lib","build:test":"tsc -p ./configs/tsconfig.test.json","lint:check":"eslint --cache --ext .ts ./src","test:babel":"jest --coverage --config ./configs/babel-jest.config.json","test:watch":"yarn test:ts-jest --watch","build:types":"tsc -p ./configs/tsconfig.types.json","test:vitest":"npx vitest --config ./configs/vitest.config.ts","prettier:fix":"prettier --write src/**/*.ts deno/lib/**/*.ts *.md --ignore-unknown --no-error-on-unmatched-pattern","test:ts-jest":"npx jest --config ./configs/ts-jest.config.json","prepublishOnly":"npm run test && npm run build && npm run build:deno","prettier:check":"prettier --check src/**/*.ts deno/lib/**/*.ts *.md --no-error-on-unmatched-pattern"},"support":{"backing":{"npm-funding":true}},"_npmUser":{"name":"colinhacks","email":"colinmcd94@gmail.com"},"repository":{"url":"git+https://github.com/colinhacks/zod.git","type":"git"},"_npmVersion":"10.8.2","description":"TypeScript-first schema declaration and validation library with static type inference","directories":{},"lint-staged":{"*.md":["prettier --ignore-unknown --write"],"src/*.ts":["eslint --cache --fix","prettier --ignore-unknown --write"]},"sideEffects":false,"_nodeVersion":"20.19.0","_hasShrinkwrap":false,"devDependencies":{"tsx":"^3.8.0","jest":"^29.3.1","husky":"^7.0.4","tslib":"^2.3.1","eslint":"^8.11.0","rollup":"^2.70.1","vitest":"^0.32.2","nodemon":"^2.0.15","ts-jest":"^29.1.0","ts-node":"^10.9.1","prettier":"^2.6.0","ts-morph":"^14.0.0","@swc/core":"^1.3.66","@swc/jest":"^0.2.26","benchmark":"^2.1.4","babel-jest":"^29.5.0","typescript":"^5.0.0","@babel/core":"^7.22.5","@types/jest":"^29.2.2","@types/node":"14","lint-staged":"^12.3.7","netlify-cli":"^17.26.2","pretty-quick":"^3.1.3","@jest/globals":"^29.4.3","@types/benchmark":"^2.1.0","@babel/preset-env":"^7.22.5","eslint-plugin-ban":"^1.6.0","dependency-cruiser":"^9.19.0","eslint-plugin-import":"^2.25.4","@standard-schema/spec":"^1.0.0-beta.4","eslint-config-prettier":"^8.5.0","@babel/preset-typescript":"^7.22.5","@rollup/plugin-typescript":"^8.2.0","@typescript-eslint/parser":"^5.15.0","eslint-plugin-unused-imports":"^2.0.0","@typescript-eslint/eslint-plugin":"^5.15.0","eslint-plugin-simple-import-sort":"^7.0.0"},"_npmOperationalInternal":{"tmp":"tmp/zod_3.24.3_1744842710334_0.8823171019534881","host":"s3://npm-registry-packages-npm-production"},"readme":"<p align=\"center\">\n  <img src=\"logo.svg\" width=\"200px\" align=\"center\" alt=\"Zod logo\" />\n  <h1 align=\"center\">Zod</h1>\n  <p align=\"center\">\n    TypeScript-first schema validation with static type inference\n    <br/>\n    by <a href=\"https://x.com/colinhacks\">@colinhacks</a>\n  </p>\n</p>\n<br/>\n\n<p align=\"center\">\n<a href=\"https://github.com/colinhacks/zod/actions?query=branch%3Amain\"><img src=\"https://github.com/colinhacks/zod/actions/workflows/test.yml/badge.svg?event=push&branch=main\" alt=\"Zod CI status\" /></a>\n<a href=\"https://opensource.org/licenses/MIT\" rel=\"nofollow\"><img src=\"https://img.shields.io/github/license/colinhacks/zod\" alt=\"License\"></a>\n<a href=\"https://www.npmjs.com/package/zod\" rel=\"nofollow\"><img src=\"https://img.shields.io/npm/dw/zod.svg\" alt=\"npm\"></a>\n<a href=\"https://discord.gg/KaSRdyX2vc\" rel=\"nofollow\"><img src=\"https://img.shields.io/discord/893487829802418277?label=Discord&logo=discord&logoColor=white\" alt=\"discord server\"></a>\n<a href=\"https://github.com/colinhacks/zod\" rel=\"nofollow\"><img src=\"https://img.shields.io/github/stars/colinhacks/zod\" alt=\"stars\"></a>\n</p>\n\n<div align=\"center\">\n  <a href=\"https://zod.dev/api\">Docs</a>\n  <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>\n  <a href=\"https://discord.gg/RcG33DQJdf\">Discord</a>\n  <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>\n  <a href=\"https://twitter.com/colinhacks\">𝕏</a>\n  <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>\n  <a href=\"https://bsky.app/profile/zod.dev\">Bluesky</a>\n  <br />\n</div>\n\n<br/>\n<br/>\n\n### [Read the docs →](https://zod.dev/api)\n\n<br/>\n<br/>\n\n## What is Zod?\n\nZod is a TypeScript-first validation library. Define a schema and parse some data with it. You'll get back a strongly typed, validated result.\n\n```ts\nimport * as z from \"zod\";\n\nconst User = z.object({\n  name: z.string(),\n});\n\n// some untrusted data...\nconst input = {\n  /* stuff */\n};\n\n// the parsed result is validated and type safe!\nconst data = User.parse(input);\n\n// so you can use it with confidence :)\nconsole.log(data.name);\n```\n\n<br/>\n\n## Features\n\n- Zero external dependencies\n- Works in Node.js and all modern browsers\n- Tiny: `2kb` core bundle (gzipped)\n- Immutable API: methods return a new instance\n- Concise interface\n- Works with TypeScript and plain JS\n- Built-in JSON Schema conversion\n- Extensive ecosystem\n\n<br/>\n\n## Installation\n\n```sh\nnpm install zod\n```\n\n<br/>\n\n## Basic usage\n\nBefore you can do anything else, you need to define a schema. For the purposes of this guide, we'll use a simple object schema.\n\n```ts\nimport * as z from \"zod\";\n\nconst Player = z.object({\n  username: z.string(),\n  xp: z.number(),\n});\n```\n\n### Parsing data\n\nGiven any Zod schema, use `.parse` to validate an input. If it's valid, Zod returns a strongly-typed _deep clone_ of the input.\n\n```ts\nPlayer.parse({ username: \"billie\", xp: 100 });\n// => returns { username: \"billie\", xp: 100 }\n```\n\n**Note** — If your schema uses certain asynchronous APIs like `async` [refinements](https://zod.dev/api#refinements) or [transforms](https://zod.dev/api#transforms), you'll need to use the `.parseAsync()` method instead.\n\n```ts\nconst schema = z.string().refine(async (val) => val.length <= 8);\n\nawait schema.parseAsync(\"hello\");\n// => \"hello\"\n```\n\n### AOT compilation\n\nFor hot validation paths, `z.compile(schema)` returns a schema clone with an ahead-of-time compiled fast path. Valid inputs take the compiled path; invalid inputs fall back to the regular parser so error reporting stays identical.\n\nAcross a 55-schema benchmark the median speedup is **2.4x**, and it scales with how much work the schema does per parse: a large array of objects is ~9x, a 20-key object ~9x, a nested object ~4.5x, while a bare `z.string()` gains nothing — compilation removes per-node dispatch and allocation, and a single `typeof` has none to remove.\n\n```ts\nconst CompiledPlayer = z.compile(Player);\n\nCompiledPlayer.parse({ username: \"billie\", xp: 100 });\n```\n\nTo enable compilation globally for schemas constructed after import:\n\n```ts\nimport \"zod/compile\"; // place before modules that define schemas\n```\n\nThings to know:\n\n- Compilation uses `new Function`. Global mode is automatically disabled when `z.config({ jitless: true })` is set (e.g. CSP environments); calling `z.compile()` directly is an explicit opt-in.\n- Schemas with async refinements or transforms can't be compiled, and neither can a few other constructs. That is not an error: `z.compile()` hands the schema back unchanged and it keeps using the regular parser, exactly as global mode leaves it. Pass `{ strict: true }` to throw `ZodCompileAsyncError` / `ZodCompileUnsupportedError` instead.\n- On invalid input, refinements and transforms may run twice (fast path, then fallback).\n- Deriving a new schema from a compiled one (`.refine()`, `.extend()`, etc.) returns an uncompiled schema — compile the final schema.\n\nSee [`compile` docs](https://zod.dev/compile) for details.\n\n### Handling errors\n\nWhen validation fails, the `.parse()` method will throw a `ZodError` instance with granular information about the validation issues.\n\n```ts\ntry {\n  Player.parse({ username: 42, xp: \"100\" });\n} catch (err) {\n  if (err instanceof z.ZodError) {\n    err.issues;\n    /* [\n      {\n        expected: 'string',\n        code: 'invalid_type',\n        path: [ 'username' ],\n        message: 'Invalid input: expected string'\n      },\n      {\n        expected: 'number',\n        code: 'invalid_type',\n        path: [ 'xp' ],\n        message: 'Invalid input: expected number'\n      }\n    ] */\n  }\n}\n```\n\nTo avoid a `try/catch` block, you can use the `.safeParse()` method to get back a plain result object containing either the successfully parsed data or a `ZodError`. The result type is a [discriminated union](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions), so you can handle both cases conveniently.\n\n```ts\nconst result = Player.safeParse({ username: 42, xp: \"100\" });\nif (!result.success) {\n  result.error; // ZodError instance\n} else {\n  result.data; // { username: string; xp: number }\n}\n```\n\n**Note** — If your schema uses certain asynchronous APIs like `async` [refinements](https://zod.dev/api#refinements) or [transforms](https://zod.dev/api#transforms), you'll need to use the `.safeParseAsync()` method instead.\n\n```ts\nconst schema = z.string().refine(async (val) => val.length <= 8);\n\nawait schema.safeParseAsync(\"hello\");\n// => { success: true; data: \"hello\" }\n```\n\n### Inferring types\n\nZod infers a static type from your schema definitions. You can extract this type with the `z.infer<>` utility and use it however you like.\n\n```ts\nconst Player = z.object({\n  username: z.string(),\n  xp: z.number(),\n});\n\n// extract the inferred type\ntype Player = z.infer<typeof Player>;\n\n// use it in your code\nconst player: Player = { username: \"billie\", xp: 100 };\n```\n\nIn some cases, the input & output types of a schema can diverge. For instance, the `.transform()` API can convert the input from one type to another. In these cases, you can extract the input and output types independently:\n\n```ts\nconst mySchema = z.string().transform((val) => val.length);\n\ntype MySchemaIn = z.input<typeof mySchema>;\n// => string\n\ntype MySchemaOut = z.output<typeof mySchema>; // equivalent to z.infer<typeof mySchema>\n// number\n```\n","publish_time":1744842710697,"_cnpm_publish_time":1744842710697,"dist-tags":{"alpha":"3.25.68-alpha.11","beta":"4.1.13-beta.0","canary":"4.5.0-canary.20260828T171753","latest":"4.6.7","next":"3.25.0-beta.20250519T094321"}}