diff --git a/index.js b/index.js index ad95f56..59fe777 100644 --- a/index.js +++ b/index.js @@ -3,8 +3,7 @@ const assureArray = require("assure-array"); const isPlainObj = require("is-plain-obj"); const defaultValue = require("default-value"); -const flat = require("array.prototype.flat"); -const flatMap = require("array.prototype.flatmap"); +const flatten = require("flatten"); const matchSpecial = require("@validatem/match-special"); const isPlainObjectValidator = require("@validatem/is-plain-object"); @@ -15,12 +14,13 @@ const hasShape = require("@validatem/has-shape"); module.exports = function normalizeRules(rules, options) { let normalizeObjects = defaultValue(options.normalizeObjects, false); - // TODO: Switch to `Array#flat` once it is available - let flattened = flat(assureArray(rules)); + // 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); if (normalizeObjects) { - return flatMap(actualRules, (rule) => { + // TODO: Switch to `Array#flatmap` once Node 10.x goes EOL (April 2021) + let mapped = actualRules.map((rule) => { if (isPlainObj(rule) && !matchSpecial(rule)) { return [ isPlainObjectValidator, @@ -30,6 +30,8 @@ module.exports = function normalizeRules(rules, options) { return rule; } }); + + return flatten(mapped); } else { return actualRules; } diff --git a/package.json b/package.json index 32bec39..e8e2c52 100644 --- a/package.json +++ b/package.json @@ -10,10 +10,9 @@ "@validatem/has-shape": "^0.1.0", "@validatem/is-plain-object": "^0.1.0", "@validatem/match-special": "^0.1.0", - "array.prototype.flat": "^1.2.3", - "array.prototype.flatmap": "^1.2.3", "assure-array": "^1.0.0", "default-value": "^1.0.0", + "flatten": "^1.0.3", "is-plain-obj": "^2.1.0" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 0840259..fde5c11 100644 --- a/yarn.lock +++ b/yarn.lock @@ -164,15 +164,6 @@ array.prototype.flat@^1.2.3: define-properties "^1.1.3" es-abstract "^1.17.0-next.1" -array.prototype.flatmap@^1.2.3: - version "1.2.3" - resolved "https://registry.yarnpkg.com/array.prototype.flatmap/-/array.prototype.flatmap-1.2.3.tgz#1c13f84a178566042dd63de4414440db9222e443" - integrity sha512-OOEk+lkePcg+ODXIpvuU9PAryCikCJyo7GlDG1upleEpQRx6mzL9puEBkozQ5iAx20KV0l3DbyQwqciJtqe5Pg== - dependencies: - define-properties "^1.1.3" - es-abstract "^1.17.0-next.1" - function-bind "^1.1.1" - as-expression@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/as-expression/-/as-expression-1.0.0.tgz#7bc620ca4cb2fe0ee90d86729bd6add33b8fd831" @@ -522,6 +513,11 @@ flatted@^2.0.0: resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.2.tgz#4575b21e2bcee7434aa9be662f4b7b5f9c2b5138" integrity sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA== +flatten@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.3.tgz#c1283ac9f27b368abc1e36d1ff7b04501a30356b" + integrity sha512-dVsPA/UwQ8+2uoFe5GHtiBMu48dWLTdsuEd7CKGlZlD78r1TTWBvDuFaFGKCo/ZfEr95Uk56vZoX86OsHkUeIg== + fs.realpath@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"