Extension of aproba - argument validator for key-value object validation
const validate = require( "oproba" );
// 'validate' is instance of aproba
// Check that `options` object properties comply specified aproba constraints
validate.obj({ foo: "N", bar: "S|N" }, options );
// Validate a nested object
validate.obj({
foo: {
baz: {
quiz: "S"
}
},
bar: "S|N" }, options );
validate.obj({ foo: "N?", bar: "S|N?" }, options );
validate.obj({
foo: { bar: "S|Z" }
}, {
foo: { bar: 1 }
});
// throws `Error: Invalid type in property #foo.bar: Expected string or null but got number`
type | description |
---|---|
* | matches any type |
A | Array.isArray OR an arguments object |
S | typeof == string |
N | typeof == number |
F | typeof == function |
O | typeof == object and not type A and not type E |
B | typeof == boolean |
E | instanceof Error OR null |
Z | == null |