Update for new combinator API

master
Sven Slootweg 4 years ago
parent 3517bf5266
commit 940e4265c9

@ -6,28 +6,32 @@ const annotateErrors = require("@validatem/annotate-errors");
const isArray = require("@validatem/is-array"); const isArray = require("@validatem/is-array");
module.exports = function (rules) { module.exports = function (rules) {
return [ let validator = combinator((value, applyValidators) => {
isArray, let newArray = [];
combinator((value, applyValidators) => { let allErrors = [];
let newArray = [];
let allErrors = [];
value.forEach((item, i) => {
let { errors, newValue } = applyValidators(item, rules);
let annotatedErrors = annotateErrors({ value.forEach((item, i) => {
pathSegments: [ i ], let { errors, newValue } = applyValidators(item, rules);
errors: errors
});
newArray.push(newValue); let annotatedErrors = annotateErrors({
allErrors.push(...annotatedErrors); pathSegments: [ i ],
errors: errors
}); });
return validationResult({ newArray.push(newValue);
errors: allErrors, allErrors.push(...annotatedErrors);
newValue: newArray });
});
}) return validationResult({
errors: allErrors,
newValue: newArray
});
});
validator.callIfNull = false;
return [
isArray,
validator
]; ];
}; };

Loading…
Cancel
Save