Skip to content

Commit f6776aa

Browse files
refactor: next (#113)
BREAKING CHANGE: minimum supported `Node.js` version is `10.13.0`, the packages exports was changed, please use `const { validate } = require('schema-utils');`
1 parent 102d170 commit f6776aa

File tree

13 files changed

+1468
-1146
lines changed

13 files changed

+1468
-1146
lines changed

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
strategy:
6262
matrix:
6363
os: [ubuntu-latest, windows-latest, macos-latest]
64-
node-version: [8.x, 10.x, 12.x, 13.x]
64+
node-version: [10.x, 12.x, 13.x]
6565

6666
runs-on: ${{ matrix.os }}
6767

README.md

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ npm install schema-utils
4747

4848
```js
4949
import schema from './path/to/schema.json';
50-
import validate from 'schema-utils';
50+
import { validate } from 'schema-utils';
5151

5252
const options = { option: true };
5353
const configuration = { name: 'Loader Name/Plugin Name/Name' };
@@ -83,13 +83,12 @@ Type: `Object`
8383
Object with options.
8484

8585
```js
86-
validate(
87-
schema,
88-
{
89-
name: 123,
90-
},
91-
{ name: 'MyPlugin' }
92-
);
86+
import schema from './path/to/schema.json';
87+
import { validate } from 'schema-utils';
88+
89+
const options = { foo: 'bar' };
90+
91+
validate(schema, { name: 123 }, { name: 'MyPlugin' });
9392
```
9493

9594
### `configuration`
@@ -124,6 +123,11 @@ Default: `"Object"`
124123
Allow to setup name in validation errors.
125124

126125
```js
126+
import schema from './path/to/schema.json';
127+
import { validate } from 'schema-utils';
128+
129+
const options = { foo: 'bar' };
130+
127131
validate(schema, options, { name: 'MyPlugin' });
128132
```
129133

@@ -140,6 +144,11 @@ Default: `"configuration"`
140144
Allow to setup base data path in validation errors.
141145

142146
```js
147+
import schema from './path/to/schema.json';
148+
import { validate } from 'schema-utils';
149+
150+
const options = { foo: 'bar' };
151+
143152
validate(schema, options, { name: 'MyPlugin', baseDataPath: 'options' });
144153
```
145154

@@ -156,6 +165,11 @@ Default: `undefined`
156165
Allow to reformat errors.
157166

158167
```js
168+
import schema from './path/to/schema.json';
169+
import { validate } from 'schema-utils';
170+
171+
const options = { foo: 'bar' };
172+
159173
validate(schema, options, {
160174
name: 'MyPlugin',
161175
postFormatter: (formattedError, error) => {
@@ -207,14 +221,14 @@ Invalid options object. MyPlugin has been initialized using an options object th
207221

208222
```js
209223
import { getOptions } from 'loader-utils';
210-
import validateOptions from 'schema-utils';
224+
import { validate } from 'schema-utils';
211225

212226
import schema from 'path/to/schema.json';
213227

214228
function loader(src, map) {
215-
const options = getOptions(this) || {};
229+
const options = getOptions(this);
216230

217-
validateOptions(schema, options, {
231+
validate(schema, options, {
218232
name: 'Loader Name',
219233
baseDataPath: 'options',
220234
});
@@ -228,13 +242,13 @@ export default loader;
228242
### `Plugin`
229243

230244
```js
231-
import validateOptions from 'schema-utils';
245+
import { validate } from 'schema-utils';
232246

233247
import schema from 'path/to/schema.json';
234248

235249
class Plugin {
236250
constructor(options) {
237-
validateOptions(schema, options, {
251+
validate(schema, options, {
238252
name: 'Plugin Name',
239253
baseDataPath: 'options',
240254
});

babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = (api) => {
1010
'@babel/preset-env',
1111
{
1212
targets: {
13-
node: '8.9.0',
13+
node: '10.13.0',
1414
},
1515
},
1616
],

declarations/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
declare const _exports: typeof import('./validate').default;
2-
export = _exports;
1+
export const validate: typeof import('./validate').validate;
2+
export const ValidationError: typeof import('./ValidationError').default;

declarations/validate.d.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export default validate;
21
export type JSONSchema4 = import('json-schema').JSONSchema4;
32
export type JSONSchema6 = import('json-schema').JSONSchema6;
43
export type JSONSchema7 = import('json-schema').JSONSchema7;
@@ -31,13 +30,10 @@ export type ValidationErrorConfiguration = {
3130
* @param {ValidationErrorConfiguration=} configuration
3231
* @returns {void}
3332
*/
34-
declare function validate(
33+
export function validate(
3534
schema: Schema,
3635
options: Array<object> | object,
3736
configuration?: ValidationErrorConfiguration | undefined
3837
): void;
39-
declare namespace validate {
40-
export { ValidationError };
41-
export { ValidationError as ValidateError };
42-
}
4338
import ValidationError from './ValidationError';
39+
export { ValidationError };

lint-staged.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
2-
'*.js': ['prettier --write', 'eslint --fix'],
2+
'*.js': ['eslint --fix', 'prettier --write'],
33
'*.{json,md,yml,css,ts}': ['prettier --write'],
44
};

0 commit comments

Comments
 (0)