From 26105034da4fcce7ac883c899d781f016559310d Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 8 Nov 2018 00:38:48 +0800 Subject: switch to vuepress --- node_modules/schema-utils/README.md | 130 ++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 node_modules/schema-utils/README.md (limited to 'node_modules/schema-utils/README.md') diff --git a/node_modules/schema-utils/README.md b/node_modules/schema-utils/README.md new file mode 100644 index 00000000..2c4d9967 --- /dev/null +++ b/node_modules/schema-utils/README.md @@ -0,0 +1,130 @@ +[![npm][npm]][npm-url] +[![node][node]][node-url] +[![deps][deps]][deps-url] +[![test][test]][test-url] +[![coverage][cover]][cover-url] +[![chat][chat]][chat-url] + +
+ + + + + + +

Schema Utils

+
+ +

Install

+ +```bash +npm i schema-utils +``` + +

Usage

+ +### `validateOptions` + +**schema.json** +```js +{ + "type": "object", + "properties": { + // Options... + }, + "additionalProperties": false +} +``` + +```js +import schema from 'path/to/schema.json' +import validateOptions from 'schema-utils' + +validateOptions(schema, options, 'Loader/Plugin Name') +``` + +

Examples

+ +**schema.json** +```json +{ + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "test": { + "anyOf": [ + { "type": "array" }, + { "type": "string" }, + { "instanceof": "RegExp" } + ] + }, + "transform": { + "instanceof": "Function" + }, + "sourceMap": { + "type": "boolean" + } + }, + "additionalProperties": false +} +``` + +### `Loader` + +```js +import { getOptions } from 'loader-utils' +import validateOptions from 'schema-utils' + +import schema from 'path/to/schema.json' + +function loader (src, map) { + const options = getOptions(this) || {} + + validateOptions(schema, options, 'Loader Name') + + // Code... +} +``` + +### `Plugin` + +```js +import validateOptions from 'schema-utils' + +import schema from 'path/to/schema.json' + +class Plugin { + constructor (options) { + validateOptions(schema, options, 'Plugin Name') + + this.options = options + } + + apply (compiler) { + // Code... + } +} +``` + + +[npm]: https://img.shields.io/npm/v/schema-utils.svg +[npm-url]: https://npmjs.com/package/schema-utils + +[node]: https://img.shields.io/node/v/schema-utils.svg +[node-url]: https://nodejs.org + +[deps]: https://david-dm.org/webpack-contrib/schema-utils.svg +[deps-url]: https://david-dm.org/webpack-contrib/schema-utils + +[test]: http://img.shields.io/travis/webpack-contrib/schema-utils.svg +[test-url]: https://travis-ci.org/webpack-contrib/schema-utils + +[cover]: https://codecov.io/gh/webpack-contrib/schema-utils/branch/master/graph/badge.svg +[cover-url]: https://codecov.io/gh/webpack-contrib/schema-utils + +[chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg +[chat-url]: https://gitter.im/webpack/webpack -- cgit v1.2.3