normalize-exception
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -0,1 +1,15 @@ | ||
/** | ||
* `normalize-exception` options | ||
*/ | ||
export interface Options { | ||
/** | ||
* Unless `true`, | ||
* [`error.cause`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause) | ||
* and | ||
* [`error.errors`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError) | ||
* are normalized recursively, when present. | ||
*/ | ||
readonly shallow?: boolean | ||
} | ||
type DefinedString<Value, DefaultValue> = Value extends string | ||
@@ -54,7 +68,9 @@ ? Value extends '' | ||
error: ErrorArg, | ||
): ErrorArg extends Error | ||
? Error & { | ||
name: DefinedString<ErrorArg['name'], Error['constructor']['name']> | ||
message: DefinedString<ErrorArg['message'], ''> | ||
} | ||
: Error | ||
options?: Options, | ||
): Error & | ||
(ErrorArg extends Error | ||
? { | ||
name: DefinedString<ErrorArg['name'], Error['constructor']['name']> | ||
message: DefinedString<ErrorArg['message'], ''> | ||
} | ||
: unknown) |
@@ -8,7 +8,7 @@ import{normalizeAggregate}from"./aggregate.js"; | ||
export default function normalizeException(error){ | ||
return recurseException(error,[]); | ||
export default function normalizeException(error,{shallow=false}={}){ | ||
return recurseException(error,[],shallow); | ||
} | ||
const recurseException=function(error,parents){ | ||
const recurseException=function(error,parents,shallow){ | ||
if(parents.includes(error)){ | ||
@@ -18,4 +18,5 @@ return; | ||
const recurse=(innerError)=> | ||
recurseException(innerError,[...parents,error]); | ||
const recurse=shallow? | ||
identity: | ||
(innerError)=>recurseException(innerError,[...parents,error],shallow); | ||
@@ -27,2 +28,6 @@ const errorA=createError(error); | ||
const identity=function(error){ | ||
return error; | ||
}; | ||
const normalizeProps=function(error,recurse){ | ||
@@ -29,0 +34,0 @@ normalizeName(error); |
{ | ||
"name": "normalize-exception", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"type": "module", | ||
@@ -50,3 +50,3 @@ "exports": "./build/src/main.js", | ||
"@ehmicky/dev-tasks": "^1.0.84", | ||
"test-each": "^5.2.1" | ||
"test-each": "^5.3.0" | ||
}, | ||
@@ -53,0 +53,0 @@ "engines": { |
@@ -50,5 +50,6 @@ [![Codecov](https://img.shields.io/codecov/c/github/ehmicky/normalize-exception.svg?label=tested&logo=codecov)](https://codecov.io/gh/ehmicky/normalize-exception) | ||
## normalizeException(error) | ||
## normalizeException(error, options?) | ||
`error` `any`\ | ||
`options` [`Options`](#options)\ | ||
_Return value_: `Error` | ||
@@ -63,2 +64,17 @@ | ||
### Options | ||
Options are an optional object with the following properties. | ||
#### shallow | ||
_Type_: `boolean`\ | ||
_Default_: `false` | ||
Unless `true`, | ||
[`error.cause`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause) | ||
and | ||
[`error.errors`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError) | ||
are normalized [recursively](#recursion), when present. | ||
# Features | ||
@@ -65,0 +81,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34867
426
396