Skip to main content

exclusive

$exclusive

A constraint that checks whether exactly one of the provided processors returns a truthy value.

Returns the single truthy value, or throws if zero or more than one 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 $one if you want to check for success (defined value) instead of truthiness.

Parameters

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

Example

// A form field must have either an email or a phone number, but not both
new Schema('object').validator({
$exclusive: [
{$property: 'email'},
{$property: 'phone'},
]
})