source: trip-planner-front/node_modules/webpack-dev-server/node_modules/schema-utils/README.md@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.9 KB
Line 
1[![npm][npm]][npm-url]
2[![node][node]][node-url]
3[![deps][deps]][deps-url]
4[![test][test]][test-url]
5[![coverage][cover]][cover-url]
6[![chat][chat]][chat-url]
7
8<div align="center">
9 <a href="http://json-schema.org">
10 <img width="160" height="160"
11 src="https://raw.githubusercontent.com/webpack-contrib/schema-utils/master/docs/logo.png">
12 </a>
13 <a href="https://github.com/webpack/webpack">
14 <img width="200" height="200"
15 src="https://webpack.js.org/assets/icon-square-big.svg">
16 </a>
17 <h1>Schema Utils</h1>
18</div>
19
20<h2 align="center">Install</h2>
21
22```bash
23npm i schema-utils
24```
25
26<h2 align="center">Usage</h2>
27
28### `validateOptions`
29
30**`schema.json`**
31```js
32{
33 "type": "object",
34 "properties": {
35 // Options...
36 },
37 "additionalProperties": false
38}
39```
40
41#### Error Messages (Custom)
42
43**`schema.json`**
44```js
45{
46 "type": "object",
47 "properties": {
48 "option": {
49 "type": [ "boolean" ]
50 }
51 },
52 // Overrides the default err.message for option
53 "errorMessage": {
54 "option": "should be {Boolean} (https:/github.com/org/repo#anchor)"
55 }
56 "additionalProperties": false
57}
58```
59
60```js
61import schema from 'path/to/schema.json'
62import validateOptions from 'schema-utils'
63
64validateOptions(schema, options, 'Loader/Plugin Name')
65```
66
67<h2 align="center">Examples</h2>
68
69**schema.json**
70```json
71{
72 "type": "object",
73 "properties": {
74 "name": {
75 "type": "string"
76 },
77 "test": {
78 "anyOf": [
79 { "type": "array" },
80 { "type": "string" },
81 { "instanceof": "RegExp" }
82 ]
83 },
84 "transform": {
85 "instanceof": "Function"
86 },
87 "sourceMap": {
88 "type": "boolean"
89 }
90 },
91 "additionalProperties": false
92}
93```
94
95### `Loader`
96
97```js
98import { getOptions } from 'loader-utils'
99import validateOptions from 'schema-utils'
100
101import schema from 'path/to/schema.json'
102
103function loader (src, map) {
104 const options = getOptions(this) || {}
105
106 validateOptions(schema, options, 'Loader Name')
107
108 // Code...
109}
110```
111
112### `Plugin`
113
114```js
115import validateOptions from 'schema-utils'
116
117import schema from 'path/to/schema.json'
118
119class Plugin {
120 constructor (options) {
121 validateOptions(schema, options, 'Plugin Name')
122
123 this.options = options
124 }
125
126 apply (compiler) {
127 // Code...
128 }
129}
130```
131
132
133[npm]: https://img.shields.io/npm/v/schema-utils.svg
134[npm-url]: https://npmjs.com/package/schema-utils
135
136[node]: https://img.shields.io/node/v/schema-utils.svg
137[node-url]: https://nodejs.org
138
139[deps]: https://david-dm.org/webpack-contrib/schema-utils.svg
140[deps-url]: https://david-dm.org/webpack-contrib/schema-utils
141
142[test]: http://img.shields.io/travis/webpack-contrib/schema-utils.svg
143[test-url]: https://travis-ci.org/webpack-contrib/schema-utils
144
145[cover]: https://codecov.io/gh/webpack-contrib/schema-utils/branch/master/graph/badge.svg
146[cover-url]: https://codecov.io/gh/webpack-contrib/schema-utils
147
148[chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
149[chat-url]: https://gitter.im/webpack/webpack
Note: See TracBrowser for help on using the repository browser.