abolish
Version:
A javascript object validator.
23 lines (22 loc) • 814 B
JavaScript
;
const types_checker_1 = require("../../src/types-checker");
module.exports = {
name: "array",
error: ":param is not a valid array!",
validator(value, option, { error }) {
// If option is false then we don't validate this
if (option === false)
return true;
// Check if is an array
if (!Array.isArray(value))
return false;
// if option is string or array of strings then we check
// if it is an array and the values are of the given types.
if (typeof option === "string" || Array.isArray(option)) {
return (0, types_checker_1.arrayIsTypeOf)(value, option)
? true
: error(`:param array values must be of type: [${option}]`);
}
return true;
}
};