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