Skip to content

Commit

Permalink
refactor: next (#113)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: minimum supported `Node.js` version is `10.13.0`, the packages exports was changed, please use `const { validate } = require('schema-utils');`
  • Loading branch information
evilebottnawi authored Oct 5, 2020
1 parent 102d170 commit f6776aa
Show file tree
Hide file tree
Showing 13 changed files with 1,468 additions and 1,146 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [8.x, 10.x, 12.x, 13.x]
node-version: [10.x, 12.x, 13.x]

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

Expand Down
40 changes: 27 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ npm install schema-utils

```js
import schema from './path/to/schema.json';
import validate from 'schema-utils';
import { validate } from 'schema-utils';

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

```js
validate(
schema,
{
name: 123,
},
{ name: 'MyPlugin' }
);
import schema from './path/to/schema.json';
import { validate } from 'schema-utils';

const options = { foo: 'bar' };

validate(schema, { name: 123 }, { name: 'MyPlugin' });
```

### `configuration`
Expand Down Expand Up @@ -124,6 +123,11 @@ Default: `"Object"`
Allow to setup name in validation errors.

```js
import schema from './path/to/schema.json';
import { validate } from 'schema-utils';

const options = { foo: 'bar' };

validate(schema, options, { name: 'MyPlugin' });
```

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

```js
import schema from './path/to/schema.json';
import { validate } from 'schema-utils';

const options = { foo: 'bar' };

validate(schema, options, { name: 'MyPlugin', baseDataPath: 'options' });
```

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

```js
import schema from './path/to/schema.json';
import { validate } from 'schema-utils';

const options = { foo: 'bar' };

validate(schema, options, {
name: 'MyPlugin',
postFormatter: (formattedError, error) => {
Expand Down Expand Up @@ -207,14 +221,14 @@ Invalid options object. MyPlugin has been initialized using an options object th

```js
import { getOptions } from 'loader-utils';
import validateOptions from 'schema-utils';
import { validate } from 'schema-utils';

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

function loader(src, map) {
const options = getOptions(this) || {};
const options = getOptions(this);

validateOptions(schema, options, {
validate(schema, options, {
name: 'Loader Name',
baseDataPath: 'options',
});
Expand All @@ -228,13 +242,13 @@ export default loader;
### `Plugin`

```js
import validateOptions from 'schema-utils';
import { validate } from 'schema-utils';

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

class Plugin {
constructor(options) {
validateOptions(schema, options, {
validate(schema, options, {
name: 'Plugin Name',
baseDataPath: 'options',
});
Expand Down
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = (api) => {
'@babel/preset-env',
{
targets: {
node: '8.9.0',
node: '10.13.0',
},
},
],
Expand Down
4 changes: 2 additions & 2 deletions declarations/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
declare const _exports: typeof import('./validate').default;
export = _exports;
export const validate: typeof import('./validate').validate;
export const ValidationError: typeof import('./ValidationError').default;
8 changes: 2 additions & 6 deletions declarations/validate.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export default validate;
export type JSONSchema4 = import('json-schema').JSONSchema4;
export type JSONSchema6 = import('json-schema').JSONSchema6;
export type JSONSchema7 = import('json-schema').JSONSchema7;
Expand Down Expand Up @@ -31,13 +30,10 @@ export type ValidationErrorConfiguration = {
* @param {ValidationErrorConfiguration=} configuration
* @returns {void}
*/
declare function validate(
export function validate(
schema: Schema,
options: Array<object> | object,
configuration?: ValidationErrorConfiguration | undefined
): void;
declare namespace validate {
export { ValidationError };
export { ValidationError as ValidateError };
}
import ValidationError from './ValidationError';
export { ValidationError };
2 changes: 1 addition & 1 deletion lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
'*.js': ['prettier --write', 'eslint --fix'],
'*.js': ['eslint --fix', 'prettier --write'],
'*.{json,md,yml,css,ts}': ['prettier --write'],
};
Loading

0 comments on commit f6776aa

Please sign in to comment.