|
|
@ -3,6 +3,7 @@
|
|
|
|
const assureArray = require("assure-array");
|
|
|
|
const assureArray = require("assure-array");
|
|
|
|
const isPlainObj = require("is-plain-obj");
|
|
|
|
const isPlainObj = require("is-plain-obj");
|
|
|
|
const defaultValue = require("default-value");
|
|
|
|
const defaultValue = require("default-value");
|
|
|
|
|
|
|
|
const flatten = require("flatten");
|
|
|
|
|
|
|
|
|
|
|
|
const matchSpecial = require("@validatem/match-special");
|
|
|
|
const matchSpecial = require("@validatem/match-special");
|
|
|
|
const isPlainObjectValidator = require("@validatem/is-plain-object");
|
|
|
|
const isPlainObjectValidator = require("@validatem/is-plain-object");
|
|
|
@ -13,7 +14,8 @@ const hasShape = require("@validatem/has-shape");
|
|
|
|
module.exports = function normalizeRules(rules, options) {
|
|
|
|
module.exports = function normalizeRules(rules, options) {
|
|
|
|
let normalizeObjects = defaultValue(options.normalizeObjects, false);
|
|
|
|
let normalizeObjects = defaultValue(options.normalizeObjects, false);
|
|
|
|
|
|
|
|
|
|
|
|
let flattened = assureArray(rules).flat();
|
|
|
|
// TODO: Switch to `Array#flat` once Node 10.x goes EOL (April 2021)
|
|
|
|
|
|
|
|
let flattened = flatten(assureArray(rules));
|
|
|
|
let actualRules = flattened.filter((rule) => rule != null);
|
|
|
|
let actualRules = flattened.filter((rule) => rule != null);
|
|
|
|
|
|
|
|
|
|
|
|
if (normalizeObjects) {
|
|
|
|
if (normalizeObjects) {
|
|
|
@ -32,7 +34,7 @@ module.exports = function normalizeRules(rules, options) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return mapped.flat();
|
|
|
|
return flatten(mapped);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return actualRules;
|
|
|
|
return actualRules;
|
|
|
|
}
|
|
|
|
}
|
|
|
|