{"_id":"@develar/schema-utils","_rev":"4245042","name":"@develar/schema-utils","description":"webpack Validation Utils","dist-tags":{"latest":"2.6.5"},"maintainers":[{"name":"develar","email":""}],"time":{"modified":"2026-03-29T21:30:13.000Z","created":"2019-07-24T07:28:02.230Z","2.6.5":"2020-03-11T10:33:05.126Z","2.1.0":"2019-07-24T07:28:02.230Z"},"users":{},"author":{"name":"webpack Contrib","url":"https://github.com/webpack-contrib"},"repository":{"type":"git","url":"git+https://github.com/webpack/schema-utils.git"},"versions":{"2.6.5":{"name":"@develar/schema-utils","version":"2.6.5","description":"webpack Validation Utils","license":"MIT","repository":{"type":"git","url":"git+https://github.com/webpack/schema-utils.git"},"author":{"name":"webpack Contrib","url":"https://github.com/webpack-contrib"},"homepage":"https://github.com/webpack/schema-utils","bugs":{"url":"https://github.com/webpack/schema-utils/issues"},"funding":{"type":"opencollective","url":"https://opencollective.com/webpack"},"main":"dist/index.js","types":"declarations/index.d.ts","engines":{"node":">= 8.9.0"},"scripts":{"start":"npm run build -- -w","clean":"del-cli dist declarations","prebuild":"npm run clean","build:types":"tsc --declaration --emitDeclarationOnly --outDir declarations && prettier \"declarations/**/*.ts\" --write","build:code":"cross-env NODE_ENV=production babel src -d dist --copy-files","build":"npm-run-all -p \"build:**\"","commitlint":"commitlint --from=master","security":"npm audit","lint:prettier":"prettier \"{**/*,*}.{js,json,md,yml,css,ts}\" --list-different","lint:js":"eslint --cache .","lint:types":"tsc --pretty --noEmit","lint":"npm-run-all -l -p \"lint:**\"","test:only":"cross-env NODE_ENV=test jest","test:watch":"npm run test:only -- --watch","test:coverage":"npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage","pretest":"npm run lint","test":"npm run test:coverage","prepare":"npm run build","release":"standard-version","defaults":"webpack-defaults"},"dependencies":{"ajv":"^6.12.0","ajv-keywords":"^3.4.1"},"devDependencies":{"@babel/cli":"^7.8.3","@babel/core":"^7.8.3","@babel/preset-env":"^7.8.3","@commitlint/cli":"^8.3.5","@commitlint/config-conventional":"^8.3.4","@types/json-schema":"^7.0.4","@webpack-contrib/defaults":"^6.3.0","@webpack-contrib/eslint-config-webpack":"^3.0.0","babel-jest":"^24.9.0","commitlint-azure-pipelines-cli":"^1.0.3","cross-env":"^6.0.3","del":"^5.1.0","del-cli":"^3.0.0","eslint":"^6.8.0","eslint-config-prettier":"^6.9.0","eslint-plugin-import":"^2.20.0","husky":"^4.0.10","jest":"^24.9.0","jest-junit":"^10.0.0","lint-staged":"^9.5.0","npm-run-all":"^4.1.5","prettier":"^1.19.1","standard-version":"^7.0.1","typescript":"^3.7.5"},"keywords":["webpack"],"gitHead":"1654f1a3b5781aeb2ba2a2be83246d2a577dd16a","_id":"@develar/schema-utils@2.6.5","_nodeVersion":"12.16.1","_npmVersion":"6.13.4","dist":{"shasum":"3ece22c5838402419a6e0425f85742b961d9b6c6","size":15731,"noattachment":false,"key":"/@develar/schema-utils/-/@develar/schema-utils-2.6.5.tgz","tarball":"http://registry.cnpm.dingdandao.com/@develar/schema-utils/download/@develar/schema-utils-2.6.5.tgz"},"maintainers":[{"name":"develar","email":""}],"_npmUser":{"name":"develar","email":"develar@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/schema-utils_2.6.5_1583922784999_0.907898880112129"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2021-12-20T08:03:47.359Z","publish_time":1583922785126,"_cnpm_publish_time":1583922785126},"2.1.0":{"name":"@develar/schema-utils","version":"2.1.0","description":"webpack Validation Utils","license":"MIT","repository":{"type":"git","url":"git+https://github.com/webpack-contrib/schema-utils.git"},"author":{"name":"webpack Contrib","url":"https://github.com/webpack-contrib"},"homepage":"https://github.com/webpack-contrib/schema-utils","bugs":{"url":"https://github.com/webpack-contrib/schema-utils/issues"},"main":"dist/index.js","engines":{"node":">= 8.9.0"},"scripts":{"start":"npm run build -- -w","prebuild":"npm run clean","build":"cross-env NODE_ENV=production babel src -d dist --ignore \"src/**/*.test.js\" --copy-files","clean":"del-cli dist","commitlint":"commitlint --from=master","lint:prettier":"prettier \"{**/*,*}.{js,json,md,yml,css}\" --list-different","lint:js":"eslint --cache src test","lint":"npm-run-all -l -p \"lint:**\"","prepare":"npm run build","release":"standard-version","security":"npm audit","test:only":"cross-env NODE_ENV=test jest","test:watch":"cross-env NODE_ENV=test jest --watch","test:coverage":"cross-env NODE_ENV=test jest --collectCoverageFrom=\"src/**/*.js\" --coverage","pretest":"npm run lint","test":"cross-env NODE_ENV=test npm run test:coverage","defaults":"webpack-defaults"},"dependencies":{"ajv":"^6.1.0","ajv-keywords":"^3.1.0"},"devDependencies":{"@babel/cli":"^7.4.4","@babel/core":"^7.4.5","@babel/preset-env":"^7.4.5","@commitlint/cli":"^8.0.0","@commitlint/config-conventional":"^8.0.0","@webpack-contrib/defaults":"^5.0.0","@webpack-contrib/eslint-config-webpack":"^3.0.0","babel-jest":"^24.8.0","commitlint-azure-pipelines-cli":"^1.0.2","cross-env":"^5.2.0","del":"^5.0.0","del-cli":"^2.0.0","eslint":"^6.0.1","eslint-config-prettier":"^6.0.0","eslint-plugin-import":"^2.0.0","husky":"^3.0.0","jest":"^24.8.0","jest-junit":"^6.4.0","lint-staged":"^9.2.0","npm-run-all":"^4.1.5","prettier":"^1.0.0","standard-version":"^6.0.1"},"keywords":["webpack"],"gitHead":"ebbbe2c6ab023083e726c3ba7f1bc49a6d642d8b","_id":"@develar/schema-utils@2.1.0","_nodeVersion":"12.6.0","_npmVersion":"6.10.1","dist":{"shasum":"eceb1695bfbed6f6bb84666d5d3abe5e1fd54e17","size":9616,"noattachment":false,"key":"/@develar/schema-utils/-/@develar/schema-utils-2.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@develar/schema-utils/download/@develar/schema-utils-2.1.0.tgz"},"maintainers":[{"name":"develar","email":""}],"_npmUser":{"name":"develar","email":"develar@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/schema-utils_2.1.0_1563953281933_0.45522595342107386"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2021-12-20T08:03:46.474Z","publish_time":1563953282230,"_cnpm_publish_time":1563953282230}},"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/master/.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[![deps][deps]][deps-url]\n[![tests][tests]][tests-url]\n[![coverage][cover]][cover-url]\n[![chat][chat]][chat-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 schema from './path/to/schema.json';\nimport validate from 'schema-utils';\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\nvalidate(\n  schema,\n  {\n    name: 123,\n  },\n  { name: 'MyPlugin' }\n);\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\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\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\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 { getOptions } from 'loader-utils';\nimport validateOptions from 'schema-utils';\n\nimport schema from 'path/to/schema.json';\n\nfunction loader(src, map) {\n  const options = getOptions(this) || {};\n\n  validateOptions(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 validateOptions from 'schema-utils';\n\nimport schema from 'path/to/schema.json';\n\nclass Plugin {\n  constructor(options) {\n    validateOptions(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## Contributing\n\nPlease take a moment to read our contributing guidelines if you haven't yet done so.\n\n[CONTRIBUTING](./.github/CONTRIBUTING.md)\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[deps]: https://david-dm.org/webpack/schema-utils.svg\n[deps-url]: https://david-dm.org/webpack/schema-utils\n[tests]: https://dev.azure.com/webpack/schema-utils/_apis/build/status/webpack.schema-utils?branchName=master\n[tests-url]: https://dev.azure.com/webpack/schema-utils/_build/latest?definitionId=9&branchName=master\n[cover]: https://codecov.io/gh/webpack/schema-utils/branch/master/graph/badge.svg\n[cover-url]: https://codecov.io/gh/webpack/schema-utils\n[chat]: https://badges.gitter.im/webpack/webpack.svg\n[chat-url]: https://gitter.im/webpack/webpack\n[size]: https://packagephobia.now.sh/badge?p=schema-utils\n[size-url]: https://packagephobia.now.sh/result?p=schema-utils\n","_attachments":{},"homepage":"https://github.com/webpack/schema-utils","bugs":{"url":"https://github.com/webpack/schema-utils/issues"},"license":"MIT"}