Rttc.validate()

Validate a value against a type schema. If it's close enough, coerce it to fit.

Either returns a (potentially "lightly" coerced) version of the value that was accepted, or it triggers its `invalid` exit. The "light coercion" might turn "3" into 3, "true" into true, -4.5 into "-4.5", etc.

Usage

Hover over inputs/exits for more info.

var Rttc = require('machinepack-rttc');


// Validate a value against a type schema. If it's close enough, coerce it to fit.

Rttc.validate({

value: '===',

typeSchema: '*',

}).execSync();

Inputs

value required

The actual value to validate.

'==='
typeSchema required

The expected type schema.

'*'

Exits

error

An unexpected error occurred.

invalid

The value is invalid against the provided schema, and cannot be safely coerced to fit.

[ { code: 'E_INVALID_TYPE',
    keypath: 'foo.bar.0.baz',
    expected: '*',
    actual: '===' } ]
success

OK.

'==='