thrownewValidationError("Must be a Buffer object");
}
},
either:function(...alternatives){
if(alternatives.length===0){
thrownewError("Must specify at least one alternative");
@ -189,6 +209,9 @@ module.exports = {
}
},
when:function(predicate,rules){
if(rules==null){
thrownewError("No rules specified for a `when` validation clause; did you misplace a parenthese?");
}else{
letrules_=assureArray(rules).map((rule)=>{
if(typeofrule==="object"){
/* 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. */
@ -207,6 +230,7 @@ module.exports = {
return[];
}
};
}
},
matchesFormat:function(regex){
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){
letrules_=assureArray(rules);
@ -256,9 +293,10 @@ module.exports = {
}
};
},
allowExtraProperties:function(rules){
returnfunction(value){
returnvalidateObject(value,rules,true);
};
allowExtraProperties:allowExtraProperties,
forbidden:function(value){
if(value!=null){
thrownewValidationError("Value exists in a place that should be empty");