Package Exports
- option-resolver.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (option-resolver.js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
option-resolver.js
Simple Javascript Option Resolver
Install:
npm install option-resolver.js
Import
HTML:
<script src="option-resolver.js"></script>
ES6:
import OptionResolver from 'option-resolver.js';
Node:
const OptionResolver = require('option-resolver.js');
Usage:
Define the format of your configuration:
const definition = new OptionResolver()
.setTypes({
animation: 'boolean',
color: 'string',
length: 'number',
debug: 'boolean',
})
.setRequired(['color'])
.setOptional(['debug', 'length'])
.setDefaults({
animation: true,
debug: false,
});
Resolve a config object:
const options = definition.resolve({
animation: false,
color: 'red',
});
This return the following object:
{
animation: false,
color: 'red',
debug: false,
}
Validation:
Resolving a set of options will throw an error when:
- A
required
option is missing - An option valud doesn't match the expected
type
. - A unknown option is given. Note: You can disable this behaviour and allow extra key by specifying the
allowExtra
option as follow:new OptionsResolver(true)
.