forked from validatem/either
Add callIfNull support
This commit is contained in:
parent
a1a85e4f29
commit
2170e3a2ab
6
index.js
6
index.js
|
@ -14,7 +14,7 @@ module.exports = function (alternatives) {
|
|||
} else if (arguments.length > 1) {
|
||||
throw new Error(`Only one argument is accepted; maybe you forgot to wrap the different alternatives into an array?`);
|
||||
} else {
|
||||
return combinator((value, applyValidators) => {
|
||||
let validator = combinator((value, applyValidators) => {
|
||||
let allErrors = [];
|
||||
|
||||
for (let alternative of alternatives) {
|
||||
|
@ -35,5 +35,9 @@ module.exports = function (alternatives) {
|
|||
|
||||
throw new ValidationError(`Must satisfy at least one of: ${errorList}`, { errors: allErrors });
|
||||
});
|
||||
|
||||
validator.callIfNull = true;
|
||||
|
||||
return validator;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue