Optimal v0.3.0
Options object builder and validator.
Usage
Pass a plain object and a factory function to Options
. The factory defines a
blueprint for every property and value within the options object.
The plain object is then validated, built, and returned.
const baseOptions = {
bool: false,
number: 10,
object: {
foo: 'b',
},
};
const options = new Options(baseOptions, (o) => ({
bool: o.bool(true),
string: o.string('foo'),
number: o.number(5).between(0, 10),
func: o.func(),
object: {
foo: o.string('a').oneOf(['a', 'b', 'c']),
},
}));
const {
string,
number,
} = options;