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

Open
f0x wants to merge 2 commits from f0x-validatem/either:master into master

@ -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(Infinity);
}
function hasNestedPaths(error) {

@ -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"
}
}

Loading…
Cancel
Save