schema-utils (1.0.0)
Published 2026-02-24 14:04:47 +00:00 by atheaadmin
Installation
registry=npm install schema-utils@1.0.0"schema-utils": "1.0.0"About this package
Install
npm i schema-utils
Usage
validateOptions
schema.json
{
"type": "object",
"properties": {
// Options...
},
"additionalProperties": false
}
Error Messages (Custom)
schema.json
{
"type": "object",
"properties": {
"option": {
"type": [ "boolean" ]
}
},
// Overrides the default err.message for option
"errorMessage": {
"option": "should be {Boolean} (https:/github.com/org/repo#anchor)"
}
"additionalProperties": false
}
import schema from 'path/to/schema.json'
import validateOptions from 'schema-utils'
validateOptions(schema, options, 'Loader/Plugin Name')
Examples
schema.json
{
"type": "object",
"properties": {
"name": {
"type": "string"
},
"test": {
"anyOf": [
{ "type": "array" },
{ "type": "string" },
{ "instanceof": "RegExp" }
]
},
"transform": {
"instanceof": "Function"
},
"sourceMap": {
"type": "boolean"
}
},
"additionalProperties": false
}
Loader
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
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...
}
}
Dependencies
Dependencies
| ID | Version |
|---|---|
| ajv | ^6.1.0 |
| ajv-errors | ^1.0.0 |
| ajv-keywords | ^3.1.0 |
Development Dependencies
| ID | Version |
|---|---|
| @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 |
| eslint-plugin-import | ^2.0.0 |
| eslint-plugin-prettier | ^2.0.0 |
| jest | ^21.0.0 |
| prettier | ^1.0.0 |
| standard-version | ^4.0.0 |
Details
Assets (1)
Versions (5)
View all
schema-utils-1.0.0.tgz
3.8 KiB