{"name":"z-schema","version":"7.0.9","keywords":["JSON","Schema","Validator"],"license":"MIT","_id":"z-schema@7.0.9","maintainers":[{"name":"zaggino","email":"zaggino@gmail.com"}],"homepage":"https://github.com/zaggino/z-schema","bugs":{"url":"https://github.com/zaggino/z-schema/issues"},"bin":{"z-schema":"bin/z-schema"},"dist":{"shasum":"3e73d8337143495b863f83cc3dfe64df517f3570","tarball":"http://registry-npm.ywwl.com/z-schema/download/z-schema-7.0.9.tgz","fileCount":66,"integrity":"sha512-tQDaVx999EEpG4y4mw8tv/hujq4XbADrTtGLOEy2bbyRX92dMAAQ0HOXptoJXDic2DCXlPLwyTW+BGDoL1vrVQ==","signatures":[{"sig":"MEQCICeLOF4ifICjn0eQl/KdZ/Yuy9oEFJ+3izCnOGwSs3clAiA6ihicRp3gGENM8/zoMl6/3QkTIPPZHztNyqtm71FvWg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/z-schema@7.0.9","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":1442846,"size":315879,"noattachment":false,"key":"/z-schema/-/z-schema-7.0.9.tgz"},"authors":["Martin Zagora <zaggino@gmail.com>"],"engines":{"node":">=22.0.0"},"exports":{".":{"import":{"types":"./dist/types/index.d.ts","default":"./dist/index.js"},"default":"./dist/index.js","require":{"types":"./cjs/index.d.ts","default":"./cjs/index.js"}}},"gitHead":"c13ee7755ee91c93cf5c3616c9cf38834cc80a32","scripts":{"lint":"eslint --fix","test":"vitest run","build":"npm run copy:schemas && tsc && npm run copy:module-json && rollup -c","clean":"rimraf ./cjs && rimraf ./dist && rimraf ./umd && rimraf --glob \"./src/schemas/*.json\"","format":"prettier --write .","prepare":"husky","pre-push":"","test:node":"vitest run --project node --silent=true","lint:check":"eslint","pre-commit":"npx lint-staged","test:quick":"npm run build && npm run test:node","build:watch":"rollup -c -w","copy:schema":"node -e \"fs.copyFileSync('./json-schema/draft-04/schema', './src/schemas/draft-04-schema.json')\"","test:sample":"npx vitest run --silent=false --hideSkippedTests --project node -t \"invalid definition\"","copy:schemas":"npm run copy:schema && npm run copy:hyper-schema","format:check":"prettier --check .","build:browser":"rollup -c --environment BROWSER","test:browsers":"vitest run --project browsers --silent=true","prepublishOnly":"npm run clean && npm run build && npm test","release:commit":"node -e \"const v=process.argv[1]; if(!v) throw new Error('Usage: npm run release:empty-commit -- <version>'); require('child_process').execSync(`git commit --allow-empty -m \\\"chore: release ${v}\\\" -m \\\"Release-As: ${v}\\\"`, {stdio:'inherit'});\" --","copy:module-json":"node -e \"fs.copyFileSync('./src/package.json', './dist/package.json')\"","copy:hyper-schema":"node -e \"fs.copyFileSync('./json-schema/draft-04/hyper-schema', './src/schemas/draft-04-hyper-schema.json')\""},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:54bd527f-2592-4da9-9eee-9cc054a1c552"}},"repository":{"url":"git+https://github.com/zaggino/z-schema.git","type":"git"},"_npmVersion":"11.8.0","description":"JSON schema validator","directories":{},"_nodeVersion":"24.13.0","dependencies":{"validator":"^13.7.0","lodash.isequal":"^4.5.0"},"_hasShrinkwrap":false,"devDependencies":{"husky":"^9.1.7","jsdom":"^27.4.0","tslib":"^2.8.1","eslint":"^9.39.2","rimraf":"^6.1.2","rollup":"^4.57.0","vitest":"^4.0.18","globals":"^17.2.0","prettier":"^3.8.1","remapify":"^2.2.0","coveralls":"^3.1.1","grunt-cli":"^1.4.3","@eslint/js":"^9.39.2","browserify":"^17.0.0","grunt-jscs":"^3.0.1","typescript":"^5.9.3","@types/node":"^25.1.0","lint-staged":"^16.2.7","@eslint/json":"^1.0.0","@eslint/markdown":"^7.5.1","@types/validator":"^13.15.10","grunt-browserify":"^6.0.0","grunt-lineending":"^1.0.0","rollup-plugin-dts":"^6.3.0","typescript-eslint":"^8.54.0","grunt-contrib-copy":"^1.0.0","@rollup/plugin-json":"^6.1.0","grunt-contrib-jshint":"^3.2.0","grunt-contrib-uglify":"^5.2.2","@rollup/plugin-terser":"^0.4.4","@types/lodash.isequal":"^4.5.8","@vitest/eslint-plugin":"^1.6.6","@rollup/plugin-commonjs":"^29.0.0","@rollup/plugin-typescript":"^12.3.0","@vitest/browser-playwright":"^4.0.18","@rollup/plugin-node-resolve":"^16.0.3"},"optionalDependencies":{"commander":"^14.0.2"},"_npmOperationalInternal":{"tmp":"tmp/z-schema_7.0.9_1770119791422_0.9706553026310207","host":"s3://npm-registry-packages-npm-production"},"readme":"# z-schema\n\nFast, lightweight JSON Schema validator for Node.js and browsers with **full support for the latest JSON Schema draft (2020-12)**, plus draft-2019-09, draft-07, draft-06, and draft-04.\n\n[![NPM](https://nodei.co/npm/z-schema.png?downloads=true&downloadRank=true)](https://www.npmjs.com/package/z-schema)\n\n[![Coverage 91%](https://img.shields.io/badge/coverage-91%25-brightgreen)](docs/test-coverage.md)\n\n## Install\n\n```bash\nnpm install z-schema\n```\n\nRequires **Node.js 22** or later.\n\n## Quick Start\n\n### ESM / TypeScript\n\n```typescript\nimport ZSchema from 'z-schema';\n\nconst validator = ZSchema.create();\n\ntry {\n  validator.validate({ name: 'Alice' }, { type: 'object', properties: { name: { type: 'string' } } });\n  console.log('Valid');\n} catch (error) {\n  console.log('Invalid:', error.details);\n}\n```\n\n### CommonJS\n\n```javascript\nconst ZSchema = require('z-schema');\nconst validator = ZSchema.create();\n```\n\n### Browser (UMD)\n\n```html\n<script src=\"z-schema/umd/ZSchema.min.js\"></script>\n<script>\n  const validator = ZSchema.create();\n  try {\n    validator.validate('hello', { type: 'string' });\n  } catch (error) {\n    console.log(error.details);\n  }\n</script>\n```\n\n### CLI\n\n```bash\nnpm install --global z-schema\nz-schema mySchema.json\nz-schema mySchema.json myData.json\nz-schema --strictMode mySchema.json myData.json\n```\n\n## Usage\n\n`ZSchema.create()` returns one of four validator variants based on the `async` and `safe` options:\n\n| Options                       | Class              | `validate()` returns       |\n| ----------------------------- | ------------------ | -------------------------- |\n| `{}`                          | `ZSchema`          | `true` (throws on error)   |\n| `{ safe: true }`              | `ZSchemaSafe`      | `{ valid, err? }`          |\n| `{ async: true }`             | `ZSchemaAsync`     | `Promise<true>` (rejects)  |\n| `{ async: true, safe: true }` | `ZSchemaAsyncSafe` | `Promise<{ valid, err? }>` |\n\n### Sync Validation (Throw Mode)\n\nBy default, `validate` throws a `ValidateError` on failure. The error has a `details` array with structured error info.\n\n```typescript\nconst validator = ZSchema.create(); // returns ZSchema\n\ntry {\n  validator.validate(json, schema); // returns true\n} catch (error) {\n  console.log(error.name); // 'ValidateError'\n  console.log(error.message); // summary message\n  console.log(error.details); // array of { code, message, path, ... }\n}\n```\n\n### Sync Validation (Safe Mode)\n\nUse `{ safe: true }` to get a `ZSchemaSafe` instance whose `validate()` returns a result object instead of throwing.\n\n```typescript\nconst validator = ZSchema.create({ safe: true }); // returns ZSchemaSafe\n\nconst result = validator.validate(json, schema); // { valid: boolean, err?: ValidateError }\nif (!result.valid) {\n  console.log(result.err!.details);\n}\n```\n\n### Async Validation (Throw Mode)\n\nPass `{ async: true }` to support async format validators. Returns a `ZSchemaAsync` instance whose `validate()` returns a `Promise`.\n\n```typescript\nconst validator = ZSchema.create({ async: true }); // returns ZSchemaAsync\n\ntry {\n  await validator.validate(json, schema); // Promise<true>\n} catch (error) {\n  console.log(error.details);\n}\n```\n\n### Async Validation (Safe Mode)\n\nCombine both options to get a `ZSchemaAsyncSafe` instance — the promise always resolves (never rejects) with a result object.\n\n```typescript\nconst validator = ZSchema.create({ async: true, safe: true }); // returns ZSchemaAsyncSafe\n\nconst result = await validator.validate(json, schema); // Promise<{ valid, err? }>\nif (!result.valid) {\n  console.log(result.err!.details);\n}\n```\n\n### Schema Compilation\n\nPre-compile schemas at startup to validate `$ref` references and cache compiled schemas.\n\n```typescript\nconst validator = ZSchema.create();\n\nconst schemas = [\n  { id: 'person', type: 'object', properties: { name: { type: 'string' } }, required: ['name'] },\n  { id: 'team', type: 'object', properties: { lead: { $ref: 'person' } } },\n];\n\ntry {\n  validator.validateSchema(schemas);\n} catch (error) {\n  console.log('Schema errors:', error.details);\n}\n```\n\n### Compile to a Function\n\n```typescript\nconst validator = ZSchema.create();\nconst validateUser = validator.compile({ type: 'object', required: ['name'] });\n\nvalidateUser({ name: 'Alice' }); // true, or throws ValidateError\n```\n\nSee [features](docs/features.md#compile-a-schema-to-a-reusable-function) for details.\n\n### Custom Format Validators\n\nRegister custom format validators for sync or async checks.\n\n```typescript\nconst validator = ZSchema.create();\n\n// Sync format\nvalidator.registerFormat('uppercase', (value: unknown): boolean => {\n  return typeof value === 'string' && value === value.toUpperCase();\n});\n\n// Async format\nvalidator.registerFormat('user-exists', async (value: unknown): Promise<boolean> => {\n  if (typeof value !== 'number') return false;\n  const user = await db.getUserById(value);\n  return user != null;\n});\n```\n\n### Remote References\n\nIf your schemas reference remote URIs, register them before validation.\n\n```typescript\nconst validator = ZSchema.create();\n\n// Register a remote schema manually\nvalidator.setRemoteReference('http://example.com/person.json', personSchema);\n\n// Or set a schema reader to load them automatically\nZSchema.setSchemaReader((uri: string) => {\n  const filePath = path.resolve(__dirname, 'schemas', uri + '.json');\n  return JSON.parse(fs.readFileSync(filePath, 'utf8'));\n});\n```\n\n## Version History\n\n| Version | Changes                                                                                           |\n| ------- | ------------------------------------------------------------------------------------------------- |\n| **v12** | Default version is **draft2020-12**. Full support for **draft-2020-12** and **draft-2019-09**.    |\n| **v11** | Default version is **draft-07**. Implemented draft-07 tests from JSON Schema Test Suite.          |\n| **v10** | Default version is **draft-06**. Implemented draft-06 tests from JSON Schema Test Suite.          |\n| **v9**  | New factory API: `ZSchema.create()` replaces `new ZSchema()`. New cache algorithms.               |\n| **v8**  | Schemas without `$schema` default to draft-04. Use `{ version: 'none' }` for the old v7 behavior. |\n| **v7**  | Rewritten in TypeScript/ESM. Passes all JSON Schema Test Suite tests for draft-04.                |\n| **v6**  | Legacy version. Draft-04 support.                                                                 |\n\n## Features\n\nSee [docs/features.md](docs/features.md) for the full feature list.\n\n## Options\n\nSee [docs/options.md](docs/options.md) for all constructor and per-call options.\n\n## Documentation\n\n| Document                                     | Description                                                                           |\n| -------------------------------------------- | ------------------------------------------------------------------------------------- |\n| [docs/usage.md](docs/usage.md)               | Detailed usage guide with all validation modes, error handling, and advanced features |\n| [docs/options.md](docs/options.md)           | Constructor options and per-call validation options                                   |\n| [docs/features.md](docs/features.md)         | Feature catalog with examples                                                         |\n| [docs/MIGRATION.md](docs/MIGRATION.md)       | Migration guide for upgrading between major versions                                  |\n| [docs/architecture.md](docs/architecture.md) | Internal architecture, module structure, and public API reference                     |\n| [docs/conventions.md](docs/conventions.md)   | Code style, naming, and formatting conventions                                        |\n| [docs/testing.md](docs/testing.md)           | Test framework, running tests, and writing new tests                                  |\n| [docs/contributing.md](docs/contributing.md) | PR workflow and contribution guidelines                                               |\n\n## Contributing\n\nThis repository uses submodules. Clone with:\n\n```bash\ngit clone --recursive https://github.com/zaggino/z-schema.git\n```\n\nSee [docs/contributing.md](docs/contributing.md) for the full contribution guide.\n\n## Contributors\n\nBig thanks to:\n\n<!-- readme: contributors,zaggino/- -start -->\n<table>\n\t<tbody>\n\t\t<tr>\n            <td align=\"center\">\n                <a href=\"https://github.com/sergey-shandar\">\n                    <img src=\"https://avatars.githubusercontent.com/u/902339?v=4\" width=\"100;\" alt=\"sergey-shandar\"/>\n                    <br />\n                    <sub><b>Sergey Shandar</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/IvanGoncharov\">\n                    <img src=\"https://avatars.githubusercontent.com/u/8336157?v=4\" width=\"100;\" alt=\"IvanGoncharov\"/>\n                    <br />\n                    <sub><b>Ivan Goncharov</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/pgonzal\">\n                    <img src=\"https://avatars.githubusercontent.com/u/47177787?v=4\" width=\"100;\" alt=\"pgonzal\"/>\n                    <br />\n                    <sub><b>Pete Gonzalez (OLD ALIAS)</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/simon-p-r\">\n                    <img src=\"https://avatars.githubusercontent.com/u/4668724?v=4\" width=\"100;\" alt=\"simon-p-r\"/>\n                    <br />\n                    <sub><b>Simon R</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/TheToolbox\">\n                    <img src=\"https://avatars.githubusercontent.com/u/2837017?v=4\" width=\"100;\" alt=\"TheToolbox\"/>\n                    <br />\n                    <sub><b>Jason Oettinger</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/whitlockjc\">\n                    <img src=\"https://avatars.githubusercontent.com/u/98899?v=4\" width=\"100;\" alt=\"whitlockjc\"/>\n                    <br />\n                    <sub><b>Jeremy Whitlock</b></sub>\n                </a>\n            </td>\n\t\t</tr>\n\t\t<tr>\n            <td align=\"center\">\n                <a href=\"https://github.com/toofishes\">\n                    <img src=\"https://avatars.githubusercontent.com/u/265817?v=4\" width=\"100;\" alt=\"toofishes\"/>\n                    <br />\n                    <sub><b>Dan McGee</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/epoberezkin\">\n                    <img src=\"https://avatars.githubusercontent.com/u/2769109?v=4\" width=\"100;\" alt=\"epoberezkin\"/>\n                    <br />\n                    <sub><b>Evgeny</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/antialias\">\n                    <img src=\"https://avatars.githubusercontent.com/u/447517?v=4\" width=\"100;\" alt=\"antialias\"/>\n                    <br />\n                    <sub><b>Thomas Hallock</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/kallaspriit\">\n                    <img src=\"https://avatars.githubusercontent.com/u/277993?v=4\" width=\"100;\" alt=\"kallaspriit\"/>\n                    <br />\n                    <sub><b>Priit Kallas</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/santam85\">\n                    <img src=\"https://avatars.githubusercontent.com/u/2706307?v=4\" width=\"100;\" alt=\"santam85\"/>\n                    <br />\n                    <sub><b>Marco Santarelli</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/Hirse\">\n                    <img src=\"https://avatars.githubusercontent.com/u/2564094?v=4\" width=\"100;\" alt=\"Hirse\"/>\n                    <br />\n                    <sub><b>Jan Pilzer</b></sub>\n                </a>\n            </td>\n\t\t</tr>\n\t\t<tr>\n            <td align=\"center\">\n                <a href=\"https://github.com/geraintluff\">\n                    <img src=\"https://avatars.githubusercontent.com/u/1957191?v=4\" width=\"100;\" alt=\"geraintluff\"/>\n                    <br />\n                    <sub><b>Geraint</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/lirenhe\">\n                    <img src=\"https://avatars.githubusercontent.com/u/9100546?v=4\" width=\"100;\" alt=\"lirenhe\"/>\n                    <br />\n                    <sub><b>Renhe Li</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/dgerber\">\n                    <img src=\"https://avatars.githubusercontent.com/u/393344?v=4\" width=\"100;\" alt=\"dgerber\"/>\n                    <br />\n                    <sub><b>Daniel Gerber</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/addaleax\">\n                    <img src=\"https://avatars.githubusercontent.com/u/899444?v=4\" width=\"100;\" alt=\"addaleax\"/>\n                    <br />\n                    <sub><b>Anna Henningsen</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/mctep\">\n                    <img src=\"https://avatars.githubusercontent.com/u/1949681?v=4\" width=\"100;\" alt=\"mctep\"/>\n                    <br />\n                    <sub><b>Konstantin Vasilev</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/barrtender\">\n                    <img src=\"https://avatars.githubusercontent.com/u/3101221?v=4\" width=\"100;\" alt=\"barrtender\"/>\n                    <br />\n                    <sub><b>barrtender</b></sub>\n                </a>\n            </td>\n\t\t</tr>\n\t\t<tr>\n            <td align=\"center\">\n                <a href=\"https://github.com/RomanHotsiy\">\n                    <img src=\"https://avatars.githubusercontent.com/u/3975738?v=4\" width=\"100;\" alt=\"RomanHotsiy\"/>\n                    <br />\n                    <sub><b>Roman Hotsiy</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/sauvainr\">\n                    <img src=\"https://avatars.githubusercontent.com/u/1715747?v=4\" width=\"100;\" alt=\"sauvainr\"/>\n                    <br />\n                    <sub><b>RenaudS</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/figadore\">\n                    <img src=\"https://avatars.githubusercontent.com/u/3253971?v=4\" width=\"100;\" alt=\"figadore\"/>\n                    <br />\n                    <sub><b>Reese</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/MattiSG\">\n                    <img src=\"https://avatars.githubusercontent.com/u/222463?v=4\" width=\"100;\" alt=\"MattiSG\"/>\n                    <br />\n                    <sub><b>Matti Schneider</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/sandersky\">\n                    <img src=\"https://avatars.githubusercontent.com/u/422902?v=4\" width=\"100;\" alt=\"sandersky\"/>\n                    <br />\n                    <sub><b>Matthew Dahl</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/jfromaniello\">\n                    <img src=\"https://avatars.githubusercontent.com/u/178512?v=4\" width=\"100;\" alt=\"jfromaniello\"/>\n                    <br />\n                    <sub><b>José F. Romaniello</b></sub>\n                </a>\n            </td>\n\t\t</tr>\n\t\t<tr>\n            <td align=\"center\">\n                <a href=\"https://github.com/KEIII\">\n                    <img src=\"https://avatars.githubusercontent.com/u/1167833?v=4\" width=\"100;\" alt=\"KEIII\"/>\n                    <br />\n                    <sub><b>Ivan Kasenkov</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/HanOterLin\">\n                    <img src=\"https://avatars.githubusercontent.com/u/21137108?v=4\" width=\"100;\" alt=\"HanOterLin\"/>\n                    <br />\n                    <sub><b>Tony Lin</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/domoritz\">\n                    <img src=\"https://avatars.githubusercontent.com/u/589034?v=4\" width=\"100;\" alt=\"domoritz\"/>\n                    <br />\n                    <sub><b>Dominik Moritz</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/Semigradsky\">\n                    <img src=\"https://avatars.githubusercontent.com/u/1198848?v=4\" width=\"100;\" alt=\"Semigradsky\"/>\n                    <br />\n                    <sub><b>Dmitry Semigradsky</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/countcain\">\n                    <img src=\"https://avatars.githubusercontent.com/u/1751150?v=4\" width=\"100;\" alt=\"countcain\"/>\n                    <br />\n                    <sub><b>Tao Huang</b></sub>\n                </a>\n            </td>\n            <td align=\"center\">\n                <a href=\"https://github.com/BuBuaBu\">\n                    <img src=\"https://avatars.githubusercontent.com/u/3825745?v=4\" width=\"100;\" alt=\"BuBuaBu\"/>\n                    <br />\n                    <sub><b>BuBuaBu</b></sub>\n                </a>\n            </td>\n\t\t</tr>\n\t<tbody>\n</table>\n<!-- readme: contributors,zaggino/- -end -->\n\nand to everyone submitting [issues](https://github.com/zaggino/z-schema/issues) on GitHub\n","publish_time":1770119791600,"_cnpm_publish_time":1770119791600,"dist-tags":{"beta":"7.0.0-beta.5","latest":"12.5.0"}}