{"_id":"schema-utils@4.8.2","bin":{"schema-utils":"bin/schema-utils.js"},"bugs":{"url":"https://github.com/webpack/schema-utils/issues"},"dist":{"shasum":"c4504ea7492c58e1b8d1fcc7d3d202c078a6d700","tarball":"http://registry-npm.ywwl.com/schema-utils/download/schema-utils-4.8.2.tgz","fileCount":30,"integrity":"sha512-iKlak3OFHF0dgD1nZRvgWQzG+P1TiEcMnLSBtIVBg937z5Jd6WE1c3SyZkXIyCfPHowL35yMsVvIjotm1c1qiw==","signatures":[{"sig":"MEYCIQD8sskVPWVHIaQ3VQOchbkmFC8VYqqbZPm+0pLweRN3VgIhAPZ1d2P53ONpg198EADBdAmuL+bPT9OzR87x64JOFmEv","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIBD9e5XMd1X91ZeIKf0V0tXKjttnyvsXcyELanpouZItAiBgDN95jJfkAzhw5WjKRMjZT/7Rtrmby+QflaLJ5QESTg=="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/schema-utils@4.8.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":122915,"size":30903,"noattachment":false,"key":"/schema-utils/-/schema-utils-4.8.2.tgz"},"main":"dist/index.js","name":"schema-utils","types":"declarations/index.d.ts","author":{"url":"https://github.com/webpack-contrib","name":"webpack Contrib"},"engines":{"node":">= 10.13.0"},"funding":{"url":"https://opencollective.com/webpack","type":"opencollective"},"gitHead":"2d6aaec88fd885c835d5a07153b540bcfd2f325d","license":"MIT","scripts":{"fix":"npm-run-all fix:code fmt","fmt":"npm run fmt:check -- --write","lint":"npm-run-all lint:code lint:types fmt:check","test":"npm run test:coverage","build":"npm-run-all -p \"build:**\"","clean":"del-cli dist declarations","start":"npm run build -- -w","prepare":"husky && npm run build","pretest":"npm run lint","release":"npm run build && changeset publish","version":"changeset version","fix:code":"npm run lint:code -- --fix","prebuild":"npm run clean","security":"npm audit --production","fmt:check":"prettier \"{**/*,*}.{js,json,md,yml,css,ts}\" --list-different","lint:code":"eslint --cache .","test:only":"jest","build:code":"babel src -d dist --copy-files","lint:types":"tsc --pretty --noEmit","test:watch":"npm run test:only -- --watch","build:types":"tsc --declaration --emitDeclarationOnly --outDir declarations && prettier \"declarations/**/*.ts\" --write","test:coverage":"npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage"},"version":"4.8.2","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"707a03c9-e56a-4ea4-970d-3db2ec94e997"}},"homepage":"https://github.com/webpack/schema-utils","keywords":["webpack"],"repository":{"url":"git+https://github.com/webpack/schema-utils.git","type":"git"},"_npmVersion":"11.19.1","description":"webpack Validation Utils","directories":{},"maintainers":[{"name":"15000621931","email":"784487301@qq.com"},{"name":"ev1stensberg","email":"evenstensberg@gmail.com"},{"name":"__hai","email":"haijie0619@gmail.com"},{"name":"sokra","email":"tobias.koppers@googlemail.com"},{"name":"avivkeller","email":"me@aviv.sh"},{"name":"evilebottnawi","email":"sheo13666q@gmail.com"}],"_nodeVersion":"24.22.1","dependencies":{"ajv":"^8.20.0","ajv-formats":"^3.0.1","ajv-keywords":"^5.1.0","@types/json-schema":"^7.0.15"},"_hasShrinkwrap":false,"devDependencies":{"del":"^8.0.1","jest":"^30.3.0","husky":"^9.1.7","eslint":"^10.10.0","del-cli":"^7.0.0","webpack":"^5.112.0","prettier":"^3.9.6","@babel/cli":"^8.0.4","babel-jest":"^30.3.0","typescript":"^6.0.3","@babel/core":"^8.0.1","@types/node":"^26.5.0","lint-staged":"^17.5.0","npm-run-all":"^4.1.5","@changesets/cli":"^2.31.1","@babel/preset-env":"^8.0.1","eslint-config-webpack":"^4.9.6","@changesets/get-github-info":"^0.8.0"},"peerDependencies":{"webpack":"^5.112.0"},"peerDependenciesMeta":{"webpack":{"optional":true}},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/schema-utils_4.8.2_1793465564789_0.16305631494170314"},"readme":"<div align=\"center\">\n  <a href=\"http://json-schema.org\">\n    <img width=\"160\" height=\"160\"\n      src=\"https://raw.githubusercontent.com/webpack-contrib/schema-utils/main/.github/assets/logo.png\">\n  </a>\n  <a href=\"https://github.com/webpack/webpack\">\n    <img width=\"200\" height=\"200\"\n      src=\"https://webpack.js.org/assets/icon-square-big.svg\">\n  </a>\n</div>\n\n[![npm][npm]][npm-url]\n[![node][node]][node-url]\n[![tests][tests]][tests-url]\n[![coverage][cover]][cover-url]\n[![GitHub Discussions][discussion]][discussion-url]\n[![size][size]][size-url]\n\n# schema-utils\n\nPackage for validate options in loaders and plugins.\n\n## Getting Started\n\nTo begin, you'll need to install `schema-utils`:\n\n```console\nnpm install schema-utils\n```\n\n## API\n\n**schema.json**\n\n```json\n{\n  \"type\": \"object\",\n  \"properties\": {\n    \"option\": {\n      \"type\": \"boolean\"\n    }\n  },\n  \"additionalProperties\": false\n}\n```\n\n```js\nimport { validate } from \"schema-utils\";\nimport schema from \"./path/to/schema.json\";\n\nconst options = { option: true };\nconst configuration = { name: \"Loader Name/Plugin Name/Name\" };\n\nvalidate(schema, options, configuration);\n```\n\n### `schema`\n\nType: `String`\n\nJSON schema.\n\nSimple example of schema:\n\n```json\n{\n  \"type\": \"object\",\n  \"properties\": {\n    \"name\": {\n      \"description\": \"This is description of option.\",\n      \"type\": \"string\"\n    }\n  },\n  \"additionalProperties\": false\n}\n```\n\n### `options`\n\nType: `Object`\n\nObject with options.\n\n```js\nimport { validate } from \"schema-utils\";\nimport schema from \"./path/to/schema.json\";\n\nconst options = { foo: \"bar\" };\n\nvalidate(schema, { name: 123 }, { name: \"MyPlugin\" });\n```\n\n### `configuration`\n\nAllow to configure validator.\n\nThere is an alternative method to configure the `name` and`baseDataPath` options via the `title` property in the schema.\nFor example:\n\n```json\n{\n  \"title\": \"My Loader options\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"name\": {\n      \"description\": \"This is description of option.\",\n      \"type\": \"string\"\n    }\n  },\n  \"additionalProperties\": false\n}\n```\n\nThe last word used for the `baseDataPath` option, other words used for the `name` option.\nBased on the example above the `name` option equals `My Loader`, the `baseDataPath` option equals `options`.\n\n#### `name`\n\nType: `Object`\nDefault: `\"Object\"`\n\nAllow to setup name in validation errors.\n\n```js\nimport { validate } from \"schema-utils\";\nimport schema from \"./path/to/schema.json\";\n\nconst options = { foo: \"bar\" };\n\nvalidate(schema, options, { name: \"MyPlugin\" });\n```\n\n```shell\nInvalid configuration object. MyPlugin has been initialised using a configuration object that does not match the API schema.\n - configuration.optionName should be a integer.\n```\n\n#### `baseDataPath`\n\nType: `String`\nDefault: `\"configuration\"`\n\nAllow to setup base data path in validation errors.\n\n```js\nimport { validate } from \"schema-utils\";\nimport schema from \"./path/to/schema.json\";\n\nconst options = { foo: \"bar\" };\n\nvalidate(schema, options, { name: \"MyPlugin\", baseDataPath: \"options\" });\n```\n\n```shell\nInvalid options object. MyPlugin has been initialised using an options object that does not match the API schema.\n - options.optionName should be a integer.\n```\n\n#### `postFormatter`\n\nType: `Function`\nDefault: `undefined`\n\nAllow to reformat errors.\n\n```js\nimport { validate } from \"schema-utils\";\nimport schema from \"./path/to/schema.json\";\n\nconst options = { foo: \"bar\" };\n\nvalidate(schema, options, {\n  name: \"MyPlugin\",\n  postFormatter: (formattedError, error) => {\n    if (error.keyword === \"type\") {\n      return `${formattedError}\\nAdditional Information.`;\n    }\n\n    return formattedError;\n  },\n});\n```\n\n```shell\nInvalid options object. MyPlugin has been initialized using an options object that does not match the API schema.\n - options.optionName should be a integer.\n   Additional Information.\n```\n\n## Examples\n\n**schema.json**\n\n```json\n{\n  \"type\": \"object\",\n  \"properties\": {\n    \"name\": {\n      \"type\": \"string\"\n    },\n    \"test\": {\n      \"anyOf\": [\n        { \"type\": \"array\" },\n        { \"type\": \"string\" },\n        { \"instanceof\": \"RegExp\" }\n      ]\n    },\n    \"transform\": {\n      \"instanceof\": \"Function\"\n    },\n    \"sourceMap\": {\n      \"type\": \"boolean\"\n    }\n  },\n  \"additionalProperties\": false\n}\n```\n\n### `Loader`\n\n```js\nimport schema from \"path/to/schema.json\";\nimport { getOptions } from \"loader-utils\";\nimport { validate } from \"schema-utils\";\n\nfunction loader(src, map) {\n  const options = getOptions(this);\n\n  validate(schema, options, {\n    name: \"Loader Name\",\n    baseDataPath: \"options\",\n  });\n\n  // Code...\n}\n\nexport default loader;\n```\n\n### `Plugin`\n\n```js\nimport schema from \"path/to/schema.json\";\nimport { validate } from \"schema-utils\";\n\nclass Plugin {\n  constructor(options) {\n    validate(schema, options, {\n      name: \"Plugin Name\",\n      baseDataPath: \"options\",\n    });\n\n    this.options = options;\n  }\n\n  apply(compiler) {\n    // Code...\n  }\n}\n\nexport default Plugin;\n```\n\n### Precompiled schemas\n\nCompiling a schema at runtime loads `ajv`, which costs about 150ms for the first schema of a\nprocess and a few to tens of milliseconds for every other one. A loader or a plugin can compile its\nschema ahead of time instead, into a check that `validate` takes as its fourth argument:\n\n```console\nnpx schema-utils precompile src/options.json\n```\n\nThis writes `src/options.check.js` next to the schema. Commit it, and publish it with the package:\n\n```js\nimport { validate } from \"schema-utils\";\nimport check from \"./options.check.js\";\nimport schema from \"./options.json\";\n\nvalidate(schema, options, { name: \"Loader Name\" }, check);\n```\n\nWhen the options are valid, the check is all that runs and `ajv` is never loaded. When they are\nnot, `validate` runs the full validation to report what is wrong, so the errors are the same as\nwithout a check.\n\nRun `schema-utils precompile --check src/options.json` in CI to fail when the check is missing or\nout of date with its schema. The generated module may need `schema-utils` as a dependency of the\npackage. It is an ES module when the nearest `package.json` has `\"type\": \"module\"`, the way Node.js\nreads a `.js` file there, and CommonJS otherwise.\n\nWith `--minify`, the check drops the error objects it never reports, has its helpers written into\nit instead of loaded from `schema-utils`, and is minified with webpack's own minifier, which needs\nwebpack 5.112.0 or later. For webpack's own options that is less than half the size and loads in\n13ms instead of 21ms. `--check` has to be given the same `--minify` to compare against the right code.\n\nA relative `$ref` to another file resolves against the schema. To compile a schema from code, use\n`precompile(schema, { loadSchema, esm, minify })`, it returns the source of the module.\n\n### Allow to disable and enable validation (the `validate` function do nothing)\n\nThis can be useful when you don't want to do validation for `production` builds.\n\n```js\nimport { disableValidation, enableValidation, validate } from \"schema-utils\";\n\n// Disable validation\ndisableValidation();\n// Do nothing\nvalidate(schema, options);\n\n// Enable validation\nenableValidation();\n// Will throw an error if schema is not valid\nvalidate(schema, options);\n\n// Allow to undestand do you need validation or not\nconst need = needValidate();\n\nconsole.log(need);\n```\n\nAlso you can enable/disable validation using the `process.env.SKIP_VALIDATION` env variable.\n\nSupported values (case insensitive):\n\n- `yes`/`y`/`true`/`1`/`on`\n- `no`/`n`/`false`/`0`/`off`\n\nThe variable is read when `schema-utils` is loaded, so set it before starting the process:\n\n```console\nSKIP_VALIDATION=y webpack\n```\n\nUse `enableValidation()`/`disableValidation()` to change it while the process is running - they\ntake effect immediately and apply to every copy of `schema-utils` in the process.\n\n## Contributing\n\nPlease take a moment to read our contributing guidelines if you haven't yet done so.\n\n[CONTRIBUTING](https://github.com/webpack/schema-utils?tab=contributing-ov-file#contributing)\n\nThe package itself runs on Node.js 10.13.0 and above, but the dev dependencies require an active\nLTS release, so use one to work on it. CI installs older ones to run the tests on the older\nversions of Node.js the package supports.\n\n## License\n\n[MIT](./LICENSE)\n\n[npm]: https://img.shields.io/npm/v/schema-utils.svg\n[npm-url]: https://npmjs.com/package/schema-utils\n[node]: https://img.shields.io/node/v/schema-utils.svg\n[node-url]: https://nodejs.org\n[tests]: https://github.com/webpack/schema-utils/workflows/schema-utils/badge.svg\n[tests-url]: https://github.com/webpack/schema-utils/actions\n[cover]: https://codecov.io/gh/webpack/schema-utils/branch/main/graph/badge.svg\n[cover-url]: https://codecov.io/gh/webpack/schema-utils\n[discussion]: https://img.shields.io/github/discussions/webpack/webpack\n[discussion-url]: https://github.com/webpack/webpack/discussions\n[size]: https://packagephobia.com/badge?p=schema-utils\n[size-url]: https://packagephobia.com/result?p=schema-utils\n","publish_time":1793465564881,"_cnpm_publish_time":1793465564881,"dist-tags":{"latest":"4.8.5","version-3":"3.3.0"}}