@validatem/core
Version:
The last validation library you'll ever need.
18 lines (13 loc) • 392 B
JavaScript
;
const aggregrateErrors = require("../aggregrate-errors");
module.exports = function createValidationMethod(validationFunction) {
return function (... args) {
let { errors, newValue } = validationFunction(... args);
let aggregratedError = aggregrateErrors(errors);
if (aggregratedError != null) {
throw aggregratedError;
} else {
return newValue;
}
};
};