Socket
Socket
Sign inDemoInstall

schema-utils

Package Overview
Dependencies
7
Maintainers
4
Versions
39
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 2.0.0

dist/index.js

13

CHANGELOG.md

@@ -1,5 +0,16 @@

# Change Log
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
### [2.0.0](https://github.com/webpack-contrib/schema-utils/compare/v1.0.0...v2.0.0) (2019-07-17)
### BREAKING CHANGES
* drop support for Node.js < 8.9.0
* drop support `errorMessage`, please use `description` for links.
* api was changed, please look documentation.
* error messages was fully rewritten.
<a name="1.0.0"></a>

@@ -6,0 +17,0 @@ # [1.0.0](https://github.com/webpack-contrib/schema-utils/compare/v0.4.7...v1.0.0) (2018-08-07)

76

package.json
{
"name": "schema-utils",
"version": "1.0.0",
"version": "2.0.0",
"description": "webpack Validation Utils",
"main": "src/index.js",
"files": [
"src"
],
"license": "MIT",
"repository": "webpack-contrib/schema-utils",
"author": "webpack Contrib (https://github.com/webpack-contrib)",
"homepage": "https://github.com/webpack-contrib/schema-utils",
"bugs": "https://github.com/webpack-contrib/schema-utils/issues",
"main": "dist/index.js",
"engines": {
"node": ">= 4"
"node": ">= 8.9.0"
},
"scripts": {
"lint": "eslint --cache src test",
"test": "jest --env node --verbose --coverage",
"clean": "del-cli coverage",
"commits": "commitlint --from $(git rev-list --tags --max-count=1)",
"release": "npm run commits && standard-version"
"start": "npm run build -- -w",
"prebuild": "npm run clean",
"build": "cross-env NODE_ENV=production babel src -d dist --ignore \"src/**/*.test.js\" --copy-files",
"clean": "del-cli dist",
"commitlint": "commitlint --from=master",
"lint:prettier": "prettier \"{**/*,*}.{js,json,md,yml,css}\" --list-different",
"lint:js": "eslint --cache src test",
"lint": "npm-run-all -l -p \"lint:**\"",
"prepare": "npm run build",
"release": "standard-version",
"security": "npm audit",
"test:only": "cross-env NODE_ENV=test jest",
"test:watch": "cross-env NODE_ENV=test jest --watch",
"test:coverage": "cross-env NODE_ENV=test jest --collectCoverageFrom=\"src/**/*.js\" --coverage",
"pretest": "npm run lint",
"test": "cross-env NODE_ENV=test npm run test:coverage",
"defaults": "webpack-defaults"
},
"files": [
"dist"
],
"dependencies": {
"ajv": "^6.1.0",
"ajv-errors": "^1.0.0",
"ajv-keywords": "^3.1.0"
},
"devDependencies": {
"@commitlint/cli": "^7.0.0",
"@commitlint/config-conventional": "^7.0.0",
"@webpack-contrib/eslint-config-webpack": "^2.0.0",
"del-cli": "^1.0.0",
"eslint": "^5.0.0",
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.5",
"@babel/preset-env": "^7.4.5",
"@commitlint/cli": "^8.0.0",
"@commitlint/config-conventional": "^8.0.0",
"@webpack-contrib/defaults": "^5.0.0",
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
"babel-jest": "^24.8.0",
"commitlint-azure-pipelines-cli": "^1.0.2",
"cross-env": "^5.2.0",
"del": "^5.0.0",
"del-cli": "^2.0.0",
"eslint": "^6.0.1",
"eslint-config-prettier": "^6.0.0",
"eslint-plugin-import": "^2.0.0",
"eslint-plugin-prettier": "^2.0.0",
"jest": "^21.0.0",
"husky": "^3.0.0",
"jest": "^24.8.0",
"jest-junit": "^6.4.0",
"lint-staged": "^9.2.0",
"npm-run-all": "^4.1.5",
"prettier": "^1.0.0",
"standard-version": "^4.0.0"
"standard-version": "^6.0.1"
},
"author": "webpack Contrib (https://github.com/webpack-contrib)",
"bugs": "https://github.com/webpack-contrib/schema-utils/issues",
"homepage": "https://github.com/webpack-contrib/schema-utils",
"repository": "https://github.com/webpack-contrib/schema-utils",
"license": "MIT"
"keywords": [
"webpack"
]
}

@@ -1,12 +0,5 @@

[![npm][npm]][npm-url]
[![node][node]][node-url]
[![deps][deps]][deps-url]
[![test][test]][test-url]
[![coverage][cover]][cover-url]
[![chat][chat]][chat-url]
<div align="center">
<a href="http://json-schema.org">
<img width="160" height="160"
src="https://raw.githubusercontent.com/webpack-contrib/schema-utils/master/docs/logo.png">
src="https://raw.githubusercontent.com/webpack-contrib/schema-utils/master/.github/assets/logo.png">
</a>

@@ -17,21 +10,35 @@ <a href="https://github.com/webpack/webpack">

</a>
<h1>Schema Utils</h1>
</div>
<h2 align="center">Install</h2>
[![npm][npm]][npm-url]
[![node][node]][node-url]
[![deps][deps]][deps-url]
[![tests][tests]][tests-url]
[![coverage][cover]][cover-url]
[![chat][chat]][chat-url]
[![size][size]][size-url]
```bash
npm i schema-utils
# schema-utils
Package for validate options in loaders and plugins.
## Getting Started
To begin, you'll need to install `schema-utils`:
```console
npm install schema-utils
```
<h2 align="center">Usage</h2>
## API
### `validateOptions`
**schema.json**
**`schema.json`**
```js
```json
{
"type": "object",
"properties": {
// Options...
"option": {
"type": ["boolean"]
}
},

@@ -42,17 +49,29 @@ "additionalProperties": false

#### Error Messages (Custom)
```js
import schema from './path/to/schema.json';
import validate from 'schema-utils';
**`schema.json`**
```js
const options = { option: true };
const configuration = { name: 'Loader Name/Plugin Name/Name' };
validate(schema, options, configuration);
```
### `schema`
Type: `String`
JSON schema.
Simple example of schema:
```json
{
"type": "object",
"properties": {
"option": {
"type": [ "boolean" ]
"name": {
"description": "This is description of option.",
"type": "string"
}
},
// Overrides the default err.message for option
"errorMessage": {
"option": "should be {Boolean} (https:/github.com/org/repo#anchor)"
}
"additionalProperties": false

@@ -62,12 +81,84 @@ }

### `options`
Type: `Object`
Object with options.
```js
import schema from 'path/to/schema.json'
import validateOptions from 'schema-utils'
validate(
schema,
{
name: 123,
},
{ name: 'MyPlugin' }
);
```
validateOptions(schema, options, 'Loader/Plugin Name')
### `configuration`
Allow to configure validator.
#### `name`
Type: `Object`
Default: `"Object"`
Allow to setup name in validation errors.
```js
validate(schema, options, { name: 'MyPlugin' });
```
<h2 align="center">Examples</h2>
```shell
Invalid configuration object. MyPlugin has been initialised using a configuration object that does not match the API schema.
- configuration.optionName should be a integer.
```
#### `baseDataPath`
Type: `String`
Default: `"configuration"`
Allow to setup base data path in validation errors.
```js
validate(schema, options, { name: 'MyPlugin', baseDataPath: 'options' });
```
```shell
Invalid options object. MyPlugin has been initialised using an options object that does not match the API schema.
- options.optionName should be a integer.
```
#### `postFormatter`
Type: `Function`
Default: `undefined`
Allow to reformat errors.
```js
validate(schema, options, {
name: 'MyPlugin',
postFormatter: (formattedError, error) => {
if (error.keyword === 'type') {
return `${formattedError}\nAdditional Information.`;
}
return formattedError;
},
});
```
```shell
Invalid options object. MyPlugin has been initialised using an options object that does not match the API schema.
- options.optionName should be a integer.
Additional Information.
```
## Examples
**schema.json**
```json

@@ -101,14 +192,19 @@ {

```js
import { getOptions } from 'loader-utils'
import validateOptions from 'schema-utils'
import { getOptions } from 'loader-utils';
import validateOptions from 'schema-utils';
import schema from 'path/to/schema.json'
import schema from 'path/to/schema.json';
function loader (src, map) {
const options = getOptions(this) || {}
function loader(src, map) {
const options = getOptions(this) || {};
validateOptions(schema, options, 'Loader Name')
validateOptions(schema, options, {
name: 'Loader Name',
baseDataPath: 'options',
});
// Code...
}
export default loader;
```

@@ -119,36 +215,47 @@

```js
import validateOptions from 'schema-utils'
import validateOptions from 'schema-utils';
import schema from 'path/to/schema.json'
import schema from 'path/to/schema.json';
class Plugin {
constructor (options) {
validateOptions(schema, options, 'Plugin Name')
constructor(options) {
validateOptions(schema, options, {
name: 'Plugin Name',
baseDataPath: 'options',
});
this.options = options
this.options = options;
}
apply (compiler) {
apply(compiler) {
// Code...
}
}
export default Plugin;
```
## Contributing
Please take a moment to read our contributing guidelines if you haven't yet done so.
[CONTRIBUTING](./.github/CONTRIBUTING.md)
## License
[MIT](./LICENSE)
[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
[deps]: https://david-dm.org/webpack/schema-utils.svg
[deps-url]: https://david-dm.org/webpack/schema-utils
[tests]: https://dev.azure.com/webpack/schema-utils/_apis/build/status/webpack.schema-utils?branchName=master
[tests-url]: https://dev.azure.com/webpack/schema-utils/_build/latest?definitionId=9&branchName=master
[cover]: https://codecov.io/gh/webpack/schema-utils/branch/master/graph/badge.svg
[cover-url]: https://codecov.io/gh/webpack/schema-utils
[chat]: https://badges.gitter.im/webpack/webpack.svg
[chat-url]: https://gitter.im/webpack/webpack
[size]: https://packagephobia.now.sh/badge?p=schema-utils
[size-url]: https://packagephobia.now.sh/result?p=schema-utils
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc