rttc
Runtime type-checking for JavaScript.
Installation
$ npm install rttc --save
Rules
General
null
is never allowed.NaN
is never allowed.Infinity
is never allowed.-Infinity
is never allowed.
Legacy Usage
The usage of this module is changing, but backwards compatibility will be maintained up until the first major version bump (v1.0.0).
See tests for more details.
rttc.rttc(expectations, inputValues, [options])
Validate and/or coerce a set of input values against a set of expectations (defined as input definitions.)
Two options may be provided:
coerce
- before failing, attempt to coerce not-quite-right input values to their expected type.base
- if an input value is missing, fill in its place in the result to the "base type" (falsy value)
require('rttc').rttc({
foo: {
type: 'string',
required: true
},
bar: {
type: { baz: {name: 'string'} },
required: false
}
}, {
foo: 'hi',
bar: {
baz: {
name: 'Rick'
}
}
});
rttc.infer(value)
Infer the type/schema of the provided value.
require('rttc').infer(false);
require('rttc').infer(0);
require('rttc').infer({
foo: 'bar'
});
require('rttc').infer({
foo: 'whatever',
bar: { baz: true }
});
require('rttc').infer([{
foo: ['bar']
}]);
require('rttc').infer({
user: {
friends: [{
name: 'Lenny',
age: 77
}]
});
rttc.types
require('rttc').types;