From a8fc604f4f75a14fb891319e13c51f773815a3c2 Mon Sep 17 00:00:00 2001 From: f0x Date: Mon, 22 Aug 2022 20:41:06 +0200 Subject: [PATCH] change flatten to Array#flat (Node 10.x EOL) --- index.js | 6 ++---- package.json | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 3588cff..705dc1e 100644 --- a/index.js +++ b/index.js @@ -2,8 +2,6 @@ // TODO: Rename this to something more appropriate, like any/anyOf? How to make sure that doesn't cause confusion with `oneOf`? -const flatten = require("flatten"); - const ValidationError = require("@validatem/error"); const combinator = require("@validatem/combinator"); const validationResult = require("@validatem/validation-result"); @@ -14,13 +12,13 @@ const areErrorsFromSameOrigin = require("./src/are-errors-from-same-origin"); function unpackNestedEithers(errors) { // NOTE: We only unpack `either` errors that occurred *at the same level* as this error, ie. where there's directly a case of `either(either(...), ...)`, without any kind of data nesting (like `arrayOf` or `hasShape`) inbetween. Nested-data failures should still be shown separately, as their resolution strategy is actually different; unlike same-level nested `either` errors, where the nesting is purely an implementation detail that allows composing sets of alternatives together. - return flatten(errors.map((error) => { + return (errors.map((error) => { if (error.path.length === 0 && error.__isValidatemEitherError) { return error.subErrors; } else { return error; } - })); + })).flat(); } function hasNestedPaths(error) { diff --git a/package.json b/package.json index 5fa2d5e..7fa25d5 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,6 @@ "@validatem/combinator": "^0.1.1", "@validatem/error": "^1.0.0", "@validatem/match-validation-error": "^0.1.0", - "@validatem/validation-result": "^0.1.2", - "flatten": "^1.0.3" + "@validatem/validation-result": "^0.1.2" } }