Skip to main content

any

$any

A constraint that checks whether any of the provided processors return a defined value. (Not to be confused with the unrelated "any" schema!)

Returns the first defined value from the processors, or throws if none returned a defined value. Be careful to not use this in a situation where the provided processors may require late-resolved values! This works best in finalizers, validators, or in opaque schema transformers.

See $or if you want to check for truthiness instead of a defined value.

Parameters

  • processors (Array<ProcessorSpec>, required): Array of processor specifications, at least one of which must return a defined value.

Example

// Accept a value that matches any of several pattern-based normalizations
new Schema('string').normalizer({
$any: [
{$match: /^\d+$/},
{$match: /^[a-f0-9]+$/i},
]
})

// Require a value that can be processed by at least one schema
new Schema('any').validator({$any: ['$numeric', '$boolean', '$date']})