You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
757 B
JavaScript

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