Add callIfNull support

master
Sven Slootweg 4 years ago
parent 437b798064
commit 5dd62e2836

@ -3,9 +3,13 @@
const combinator = require("@validatem/combinator"); const combinator = require("@validatem/combinator");
module.exports = function withContext(rules, context) { module.exports = function withContext(rules, context) {
return combinator((item, applyValidators, parentContext) => { let validator = combinator((item, applyValidators, parentContext) => {
let mergedContext = Object.assign({}, parentContext, context); let mergedContext = Object.assign({}, parentContext, context);
return applyValidators(item, rules, mergedContext); return applyValidators(item, rules, mergedContext);
}); });
validator.callIfNull = true;
return validator;
}; };

Loading…
Cancel
Save