some
Strickland provides a some validator. The some validator operates over an array of validators and it will exit as soon as it encounters a valid result. If any of the validators in the array are valid, then the overall result will be valid.
Parameters
The first parameter to the some validator factory is the array of validators. Validator props can also be supplied either as an object or as a function that accepts context and returns a validator props object.
Result Properties
some: The array of validation results produced during validation
The some validator adds a some property to the validation result that provides the detailed validation results of every validator that was validated in the array of validators. The validation result property is named some to match the name of the validator (this is a common pattern in Strickland).
Usage
import validate, {
some, required, minLength, maxLength
} from 'strickland';
const max5orMin10orValue7 = some([
max(5),
min(10),
compare(7)
]);
const result = validate(max5orMin10orValue7, 12);
/*
result = {
isValid: true,
value: 12,
max: 5,
min: 10,
some: [
{
isValid: false,
value: 12,
max: 5
},
{
isValid: true,
value: 12,
min: 10
}
]
}
*/There are a few notable characteristics of this result:
The properties from each executed validator are added to the top-level result
The
maxvalidator added themax: 5property to the resultThe
minvalidator added themin: 10property to the result
Property collisions are resolved using last-in-wins
Once validation succeeds for a validator, no further validation is performed
The
comparevalidator was not executedThe props from the
comparevalidator are not included on the resultThe
somearray in the result does not include an item for thecomparevalidator
The top-level
isValidprop on the result reflects the overall validation result
Last updated
Was this helpful?