import {conform, explain, explainData, spec} from 'js.spec'
const str_or_int = spec.or("str or int", {
  str: spec.string,
  int: spec.integer

conform(spec, value)

Returns the conformed value to this spec. In case of or it will be an array with the matched branches.

conform(str_or_int, 5) // => ['int', 5]
conform(str_or_int, 'five') // => ['str', 'five']

explain(spec, value)

Prints reasons why the value did not conform to this spec.

explain(str_or_int, false)
// Or(isString, isInteger)->isString: isString failed for false at []
// Or(isString, isInteger)->isInteger: isInteger failed for false at []

explainData(spec/id, value)

Like explain, but returns problems as data structure.

explainData(str_or_int, false)
/* =>
[ { path: [],
    via: [ 'str or int', 'isString'],
    value: false,
    predicate: [Function: isString],
    predicateName: 'isString' },
  { path: [],
    via: [ 'str or int', 'isInteger'],
    value: false,
    predicate: [Function: isInteger],
    predicateName: 'isInteger' } ]

results matching ""

    No results matching ""