simple-common-utils
Advanced tools
Comparing version 2.5.0 to 2.5.1
@@ -180,18 +180,26 @@ export default class StaticUtils { | ||
static formatError(error) { | ||
let result = "Start of error output:\n"; | ||
let result; | ||
Object.entries(error).forEach(entry => { | ||
const value = entry[1]; | ||
const errorEntries = Object.entries(error); | ||
if (!errorEntries.length) { | ||
result = error; | ||
} else { | ||
result = "Start of error output:\n"; | ||
const stringifier = [ | ||
Array, | ||
Object, | ||
undefined | ||
].includes(value?.constructor) ? JSON.stringify : obj => obj.toString(); | ||
errorEntries.forEach(entry => { | ||
const value = entry[1]; | ||
const stringifier = [ | ||
Array, | ||
Object, | ||
undefined | ||
].includes(value?.constructor) ? JSON.stringify : obj => obj.toString(); | ||
result += `${entry[0]}: ${stringifier(value)}\n`; | ||
}); | ||
result += `${entry[0]}: ${stringifier(value)}\n`; | ||
}); | ||
result += "End of error output"; | ||
} | ||
result += "End of error output"; | ||
return result; | ||
@@ -198,0 +206,0 @@ } |
@@ -21,3 +21,3 @@ { | ||
}, | ||
"version": "2.5.0" | ||
"version": "2.5.1" | ||
} |
@@ -185,3 +185,3 @@ This is a collection of utility classes used for JS development. | ||
Enumerates the fields of the given argument with `Object.entries()` and returns a string based on the result. | ||
Enumerates the fields of the given argument with `Object.entries()` and returns a string based on the result. Returns the given argument if it has no enumerable entries. | ||
@@ -258,2 +258,3 @@ - objectToArray() | ||
-|- | ||
v2.5.1|`StaticUtils.formatError()`: fallback added. | ||
v2.5.0|`StaticUtils.formatError()` added. | ||
@@ -260,0 +261,0 @@ v2.4.0|1. `StaticUtils.today()`: `returnNow` added.<br>2. `package.json`: fields alphabetized. |
36088
713
276