Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

normalize-exception

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

normalize-exception - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

28

build/src/main.d.ts

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc