all
function all(predicate1, predicate2, ...): PredicateThis function takes as a parameters arbitrary number of Predicates, and returns a Predicate that matches only if all of the Predicates provided as arguments match.
If any of the Predicates provided as arguments doesn't match the value, the error(s) returned by that first (from left hand side) failing Predicate are returned from the combined Predicate.
Examples:
Failing example:
First, let's define an example value that we want to verify and wrap it with asVerificable():
const { asVerificable, all, isNumber, isString, isArray, getErrors } = require("verifica");
const value = 123;
const verificable = asVerificable(value);Next, let's use the all() function to combine multiple predicates into one:
const combinedPredicate = all(
isNumber,
isString,
isArray,
);Only the error(s) from the first failing Predicate (isString) are returned from the combinedPredicate. Errors from the next failing predicates (isArray) are not returned:
Matching example:
We can also create more useful combined predicate like:
And test the value against this combined Predicate:
Last updated
Was this helpful?