change flatten to Array#flat (Node 10.x EOL)

pull/1/head
f0x 2 years ago
parent 5bf5895224
commit a8fc604f4f

@ -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`? // 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 ValidationError = require("@validatem/error");
const combinator = require("@validatem/combinator"); const combinator = require("@validatem/combinator");
const validationResult = require("@validatem/validation-result"); const validationResult = require("@validatem/validation-result");
@ -14,13 +12,13 @@ const areErrorsFromSameOrigin = require("./src/are-errors-from-same-origin");
function unpackNestedEithers(errors) { 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. // 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) { if (error.path.length === 0 && error.__isValidatemEitherError) {
return error.subErrors; return error.subErrors;
} else { } else {
return error; return error;
} }
})); })).flat();
} }
function hasNestedPaths(error) { function hasNestedPaths(error) {

@ -20,7 +20,6 @@
"@validatem/combinator": "^0.1.1", "@validatem/combinator": "^0.1.1",
"@validatem/error": "^1.0.0", "@validatem/error": "^1.0.0",
"@validatem/match-validation-error": "^0.1.0", "@validatem/match-validation-error": "^0.1.0",
"@validatem/validation-result": "^0.1.2", "@validatem/validation-result": "^0.1.2"
"flatten": "^1.0.3"
} }
} }

Loading…
Cancel
Save