thrownewValidationError("Must be a Buffer object");
}
},
either:function(...alternatives){
either:function(...alternatives){
if(alternatives.length===0){
if(alternatives.length===0){
thrownewError("Must specify at least one alternative");
thrownewError("Must specify at least one alternative");
@ -189,24 +209,28 @@ module.exports = {
}
}
},
},
when:function(predicate,rules){
when:function(predicate,rules){
letrules_=assureArray(rules).map((rule)=>{
if(rules==null){
if(typeofrule==="object"){
thrownewError("No rules specified for a `when` validation clause; did you misplace a parenthese?");
/* We automatically allow extraneous properties in a `when` clause, because it'll generally be used as a partial addition to an otherwise-fully-specified object structure. */
}else{
returnallowExtraProperties(rule);
letrules_=assureArray(rules).map((rule)=>{
}else{
if(typeofrule==="object"){
returnrule;
/* We automatically allow extraneous properties in a `when` clause, because it'll generally be used as a partial addition to an otherwise-fully-specified object structure. */
}
returnallowExtraProperties(rule);
});
}else{
returnrule;
}
});
returnfunction(value){
returnfunction(value){
letmatches=predicate(value);
letmatches=predicate(value);
if(matches){
if(matches){
returnvalidateValue(value,rules_);
returnvalidateValue(value,rules_);
}else{
}else{
return[];
return[];
}
}
};
};
}
},
},
matchesFormat:function(regex){
matchesFormat:function(regex){
returnfunction(value){
returnfunction(value){
@ -215,6 +239,19 @@ module.exports = {
}
}
};
};
},
},
oneOf:function(validValues){
if(Array.isArray(validValues)){
letvalidValueSet=newSet(validValues);
returnfunction(value){
if(!validValueSet.has(value)){
thrownewValidationError(`Must be one of: ${validValues.map((item)=>util.inspect(item)).join(", ")}`);
}
}
}else{
thrownewError("Argument to `oneOf` must be an array of values");
}
},
arrayOf:function(rules){
arrayOf:function(rules){
letrules_=assureArray(rules);
letrules_=assureArray(rules);
@ -256,9 +293,10 @@ module.exports = {
}
}
};
};
},
},
allowExtraProperties:function(rules){
allowExtraProperties:allowExtraProperties,
returnfunction(value){
forbidden:function(value){
returnvalidateObject(value,rules,true);
if(value!=null){
};
thrownewValidationError("Value exists in a place that should be empty");