{"name":"schema-utils","version":"0.3.0","description":"Webpack Schema Validation Utilities","main":"dist/cjs.js","files":["dist"],"engines":{"node":">= 4.3 < 5.0.0 || >= 5.10"},"scripts":{"start":"yarn run build -- -w","prebuild":"yarn run clean","build":"cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js'","clean":"del-cli dist","lint":"eslint --cache src test","lint-staged":"lint-staged","security":"nsp check","test":"jest","test:watch":"jest --watch","test:coverage":"jest --collectCoverageFrom='src/**/*.js' --coverage","travis:coverage":"yarn run test:coverage","travis:lint":"yarn run lint && yarn run security","travis:test":"yarn run test","webpack-defaults":"webpack-defaults","prepublish":"yarn run build","release":"yarn run standard-version"},"dependencies":{"ajv":"^5.0.0"},"devDependencies":{"babel-cli":"^6.24.1","babel-jest":"^19.0.0","babel-plugin-transform-object-rest-spread":"^6.23.0","babel-polyfill":"^6.23.0","babel-preset-env":"^1.4.0","babel-preset-webpack":"^1.0.0","codecov":"^2.0.1","cross-env":"^4.0.0","del-cli":"^0.2.1","eslint":"^3.19.0","eslint-config-webpack":"^1.2.1","eslint-plugin-import":"^2.2.0","jest":"^19.0.2","lint-staged":"^3.4.0","nsp":"^2.6.3","pre-commit":"^1.2.2","standard-version":"^4.0.0","webpack-defaults":"^0.4.5"},"pre-commit":"lint-staged","lint-staged":{"*.js":["eslint --fix","git add"]},"eslintConfig":{"extends":"webpack","installedESLint":true},"keywords":["webpack","plugin","es2015"],"author":{"name":"Webpack Contrib","url":"https://github.com/webpack-contrib"},"contributors":[{"name":"Juho Vepsäläinen","email":"@bebraw"},{"name":"Joshua Wiens","email":"@d3viant0ne"},{"name":"Michael Ciniawsky","email":"@michael-ciniawsky"}],"repository":{"type":"git","url":"git+https://github.com/webpack-contrib/schema-utils.git"},"bugs":{"url":"https://github.com/webpack-contrib/schema-utils/issues"},"homepage":"https://github.com/webpack-contrib/schema-utils#readme","license":"MIT","gitHead":"96525dd9fd5c33056cbafe5680c5cdd10a994686","_id":"schema-utils@0.3.0","_shasum":"f5877222ce3e931edae039f17eb3716e7137f8cf","_from":".","_npmVersion":"4.2.0","_nodeVersion":"7.9.0","_npmUser":{"name":"d3viant0ne","email":"wiens.joshua@gmail.com"},"dist":{"shasum":"f5877222ce3e931edae039f17eb3716e7137f8cf","tarball":"http://registry-npm.ywwl.com/schema-utils/download/schema-utils-0.3.0.tgz","integrity":"sha512-QaVYBaD9U8scJw2EBWnCBY+LJ0AD+/2edTaigDs0XLDLBfJmSUK9KGqktg1rb32U3z4j/XwvFwHHH1YfbYFd7Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC8DgTMqh+qH7n0p2yUQd2yztWGVmkPFOiZSPuRPMGZUwIhAPZdfszJInwkIJpjrPUPhCumARm72geJb+4WwF+GZqTW"}],"size":4065,"noattachment":false,"key":"/schema-utils/-/schema-utils-0.3.0.tgz"},"maintainers":[{"name":"bebraw","email":"bebraw@gmail.com"},{"name":"d3viant0ne","email":"wiens.joshua@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/schema-utils-0.3.0.tgz_1493490045779_0.2797495676204562"},"directories":{},"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[![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 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\nimport schema from \"./path/to/schema.json\";\nimport { validate } from \"schema-utils\";\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 schema from \"./path/to/schema.json\";\nimport { validate } from \"schema-utils\";\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 schema from \"./path/to/schema.json\";\nimport { validate } from \"schema-utils\";\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 schema from \"./path/to/schema.json\";\nimport { validate } from \"schema-utils\";\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 { getOptions } from \"loader-utils\";\nimport { validate } from \"schema-utils\";\n\nimport schema from \"path/to/schema.json\";\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 { validate } from \"schema-utils\";\n\nimport schema from \"path/to/schema.json\";\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### 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\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[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/master/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":1493490047722,"_cnpm_publish_time":1493490047722,"dist-tags":{"latest":"4.8.5","version-3":"3.3.0"}}