set-error-class
Advanced tools
| export const normalizeArgs=function( | ||
@@ -3,0 +4,0 @@ error, |
| type NormalizeError<ErrorArg> = ErrorArg extends Error ? ErrorArg : Error | ||
| /** | ||
| * Sets the `error`'s | ||
| * [prototype](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf), | ||
| * [`name`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name) | ||
| * and | ||
| * [`constructor`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor). | ||
| * | ||
| * @example | ||
| * ```js | ||
| * const typeError = new TypeError('test') | ||
| * console.log(typeError instanceof TypeError) // true | ||
| * console.log(typeError.name) // 'TypeError' | ||
| * console.log(typeError.constructor) // TypeError | ||
| * console.log(typeError.stack) // TypeError: test ... | ||
| * | ||
| * const rangeError = setErrorClass(typeError, RangeError) | ||
| * console.log(rangeError === typeError) // true | ||
| * console.log(rangeError instanceof RangeError) // true | ||
| * console.log(rangeError.name) // 'RangeError' | ||
| * console.log(rangeError.constructor) // RangeError | ||
| * console.log(rangeError.stack) // RangeError: test ... | ||
| * ``` | ||
@@ -12,3 +29,2 @@ */ | ||
| ErrorClass: Function, | ||
| currentName?: string, | ||
| ): NormalizeError<ErrorArg> |
+2
-2
| { | ||
| "name": "set-error-class", | ||
| "version": "1.4.0", | ||
| "version": "1.5.0", | ||
| "type": "module", | ||
@@ -37,3 +37,3 @@ "exports": { | ||
| "@ehmicky/dev-tasks": "^1.0.102", | ||
| "test-each": "^5.5.0" | ||
| "test-each": "^5.6.0" | ||
| }, | ||
@@ -40,0 +40,0 @@ "engines": { |
+7
-7
@@ -6,3 +6,3 @@ [](https://www.npmjs.com/package/set-error-class) | ||
| [](https://bundlephobia.com/package/set-error-class) | ||
| [](https://twitter.com/intent/follow?screen_name=ehmicky) | ||
| [](https://fosstodon.org/@ehmicky) | ||
| [](https://medium.com/@ehmicky) | ||
@@ -15,3 +15,3 @@ | ||
| - Sets an error's | ||
| [prototype, name and constructor](#seterrorclasserror-errorclass-currentname) | ||
| [prototype, name and constructor](#seterrorclasserror-errorclass) | ||
| - Update the [error's `stack`](#errorstack) with its new `name` | ||
@@ -53,7 +53,6 @@ - Handles [invalid errors](#invalid-errors) | ||
| ## setErrorClass(error, ErrorClass, currentName?) | ||
| ## setErrorClass(error, ErrorClass) | ||
| `error` `Error | unknown`\ | ||
| `ErrorClass` `typeof Error`\ | ||
| `currentName` `string?`\ | ||
| _Return value_: `Error` | ||
@@ -80,4 +79,3 @@ | ||
| [`error.name`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message). | ||
| If `error.stack` contains `currentName` (which defaults to the current | ||
| `error.name`), it is replaced with the new `error.name`. | ||
| It is updated accordingly. | ||
@@ -108,2 +106,4 @@ ## Error constructors | ||
| update an error's properties | ||
| - [`set-error-stack`](https://github.com/ehmicky/set-error-stack): Properly | ||
| update an error's stack | ||
| - [`merge-error-cause`](https://github.com/ehmicky/merge-error-cause): Merge an | ||
@@ -142,4 +142,4 @@ error with its `cause` | ||
| <!-- | ||
| <table><tr><td align="center"><a href="https://twitter.com/ehmicky"><img src="https://avatars2.githubusercontent.com/u/8136211?v=4" width="100px;" alt="ehmicky"/><br /><sub><b>ehmicky</b></sub></a><br /><a href="https://github.com/ehmicky/set-error-class/commits?author=ehmicky" title="Code">💻</a> <a href="#design-ehmicky" title="Design">🎨</a> <a href="#ideas-ehmicky" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/ehmicky/set-error-class/commits?author=ehmicky" title="Documentation">📖</a></td></tr></table> | ||
| <table><tr><td align="center"><a href="https://fosstodon.org/@ehmicky"><img src="https://avatars2.githubusercontent.com/u/8136211?v=4" width="100px;" alt="ehmicky"/><br /><sub><b>ehmicky</b></sub></a><br /><a href="https://github.com/ehmicky/set-error-class/commits?author=ehmicky" title="Code">💻</a> <a href="#design-ehmicky" title="Design">🎨</a> <a href="#ideas-ehmicky" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/ehmicky/set-error-class/commits?author=ehmicky" title="Documentation">📖</a></td></tr></table> | ||
| --> | ||
| <!-- ALL-CONTRIBUTORS-LIST:END --> |
13852
6.77%172
10.26%