|
|
@ -3,6 +3,7 @@
|
|
|
|
const createError = require("create-error");
|
|
|
|
const createError = require("create-error");
|
|
|
|
const assureArray = require("assure-array");
|
|
|
|
const assureArray = require("assure-array");
|
|
|
|
const defaultValue = require("default-value");
|
|
|
|
const defaultValue = require("default-value");
|
|
|
|
|
|
|
|
const isPlainObj = require("is-plain-obj");
|
|
|
|
const util = require("util");
|
|
|
|
const util = require("util");
|
|
|
|
|
|
|
|
|
|
|
|
let ValidationError = createError("ValidationError", { path: [] });
|
|
|
|
let ValidationError = createError("ValidationError", { path: [] });
|
|
|
@ -139,6 +140,12 @@ function validateArguments(args, rules) {
|
|
|
|
aggregrateErrors(errors);
|
|
|
|
aggregrateErrors(errors);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function isPlainObject(value) {
|
|
|
|
|
|
|
|
if (!isPlainObj(value)) {
|
|
|
|
|
|
|
|
throw new ValidationError("Must be a plain object (eg. object literal)");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
module.exports = {
|
|
|
|
validateArguments: validateArguments,
|
|
|
|
validateArguments: validateArguments,
|
|
|
|
validateValue: function (value, rules) {
|
|
|
|
validateValue: function (value, rules) {
|
|
|
@ -148,7 +155,7 @@ module.exports = {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateOptions: function (args, optionsRules) {
|
|
|
|
validateOptions: function (args, optionsRules) {
|
|
|
|
return validateArguments(args, [
|
|
|
|
return validateArguments(args, [
|
|
|
|
["options", optionsRules]
|
|
|
|
["options", isPlainObject].concat(assureArray(optionsRules))
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ValidationError: ValidationError,
|
|
|
|
ValidationError: ValidationError,
|
|
|
@ -183,6 +190,7 @@ module.exports = {
|
|
|
|
throw new ValidationError("Must be a Buffer object");
|
|
|
|
throw new ValidationError("Must be a Buffer object");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
isPlainObject: isPlainObject,
|
|
|
|
either: function (...alternatives) {
|
|
|
|
either: function (...alternatives) {
|
|
|
|
if (alternatives.length === 0) {
|
|
|
|
if (alternatives.length === 0) {
|
|
|
|
throw new Error("Must specify at least one alternative");
|
|
|
|
throw new Error("Must specify at least one alternative");
|
|
|
|