Skip to main content

or

$or

A constraint that checks whether any of the provided processors return a truthy value.

Returns the first truthy value from the processors, or throws if none are truthy. 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 $any if you want to check for success (defined value) instead of truthiness

Parameters

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

Example

// Accept either a valid hostname or a valid IPv4 address
new Schema('string').validator({$or: ['$hostname', '$ipv4']})

// Accept a port number OR the string 'auto'
new Schema('any').validator({
$or: [
{$range: {min: 1, max: 65535}},
{$eq: 'auto'},
]
})