schema-utils
Package for validate options in loaders and plugins.
Getting Started
To begin, you'll need to install schema-utils
:
npm install schema-utils
API
schema.json
;; const options = option: true ;const configuration = name: 'Loader Name/Plugin Name/Name' ; //增加Ajv实例化配置项const ajvOptions = useDefaults: true; ;
schema
Type: String
JSON schema.
Simple example of schema:
options
Type: Object
Object with options.
;
configuration
Allow to configure validator.
There is an alternative method to configure the name
andbaseDataPath
options via the title
property in the schema.
For example:
The last word used for the baseDataPath
option, other words used for the name
option.
Based on the example above the name
option equals My Loader
, the baseDataPath
option equals options
.
name
Type: Object
Default: "Object"
Allow to setup name in validation errors.
;
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.
;
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.
;
Invalid options object. MyPlugin has been initialized using an options object that does not match the API schema. - options.optionName should be a integer. Additional Information.
Examples
schema.json
Loader
;; ; { const options = || {}; ; // Code...} ;
Plugin
; ; { ; thisoptions = options; } { // Code... } ;
Contributing
Please take a moment to read our contributing guidelines if you haven't yet done so.