set-error-class
Advanced tools
| 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 ... | ||
| * ``` | ||
| */ | ||
| export default function setErrorClass<ErrorArg>( | ||
| error: ErrorArg, | ||
| ErrorClass: new () => unknown, | ||
| ): NormalizeError<ErrorArg> |
@@ -8,5 +8,5 @@ | ||
| writable:true, | ||
| configurable:true}); | ||
| configurable:true | ||
| }); | ||
| }; | ||
| //# sourceMappingURL=enum.js.map |
@@ -31,5 +31,5 @@ import{setNonEnumProp}from"./enum.js"; | ||
| writable:true, | ||
| configurable:true}; | ||
| configurable:true | ||
| }; | ||
| Object.defineProperty(StackError,"name",descriptor); | ||
@@ -36,0 +36,0 @@ |
+7
-6
| { | ||
| "name": "set-error-class", | ||
| "version": "1.5.0", | ||
| "version": "1.6.0", | ||
| "type": "module", | ||
| "exports": { | ||
| "types": "./build/types/main.d.ts", | ||
| "types": "./build/src/main.d.ts", | ||
| "default": "./build/src/main.js" | ||
| }, | ||
| "main": "./build/src/main.js", | ||
| "types": "./build/types/main.d.ts", | ||
| "types": "./build/src/main.d.ts", | ||
| "files": [ | ||
| "build/src/**/*.{js,json}", | ||
| "build/types/**/*.d.ts" | ||
| "build/src/**/*.{js,json,d.ts}", | ||
| "!build/src/**/*.test.js", | ||
| "!build/src/{helpers,fixtures}" | ||
| ], | ||
@@ -36,3 +37,3 @@ "sideEffects": false, | ||
| "devDependencies": { | ||
| "@ehmicky/dev-tasks": "^1.0.102", | ||
| "@ehmicky/dev-tasks": "^2.0.52", | ||
| "test-each": "^5.6.0" | ||
@@ -39,0 +40,0 @@ }, |
+10
-4
| [](https://www.npmjs.com/package/set-error-class) | ||
| [](https://unpkg.com/set-error-class?module) | ||
| [](/types/main.d.ts) | ||
| [](/src/main.d.ts) | ||
| [](https://codecov.io/gh/ehmicky/set-error-class) | ||
@@ -44,3 +44,3 @@ [](https://bundlephobia.com/package/set-error-class) | ||
| This package works in both Node.js >=14.18.0 and | ||
| [browsers](https://raw.githubusercontent.com/ehmicky/dev-tasks/main/src/tasks/build/browserslist). | ||
| [browsers](https://raw.githubusercontent.com/ehmicky/dev-tasks/main/src/browserslist). | ||
| It is an ES module and must be loaded using | ||
@@ -87,4 +87,4 @@ [an `import` or `import()` statement](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c), | ||
| - [`modern-errors`](https://github.com/ehmicky/modern-errors): Handle errors | ||
| like it's 2022 🔮 | ||
| - [`modern-errors`](https://github.com/ehmicky/modern-errors): Handle errors in | ||
| a simple, stable, consistent way | ||
| - [`error-custom-class`](https://github.com/ehmicky/error-custom-class): Create | ||
@@ -102,2 +102,4 @@ one error class | ||
| update an error's message | ||
| - [`wrap-error-message`](https://github.com/ehmicky/wrap-error-message): | ||
| Properly wrap an error's message | ||
| - [`set-error-props`](https://github.com/ehmicky/set-error-props): Properly | ||
@@ -115,2 +117,6 @@ update an error's properties | ||
| some ❤ to Node.js process errors | ||
| - [`error-http-response`](https://github.com/ehmicky/error-http-response): | ||
| Create HTTP error responses | ||
| - [`winston-error-format`](https://github.com/ehmicky/winston-error-format): Log | ||
| errors with Winston | ||
@@ -117,0 +123,0 @@ # Support |
| 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 ... | ||
| * ``` | ||
| */ | ||
| export default function setErrorClass<ErrorArg>( | ||
| error: ErrorArg, | ||
| ErrorClass: Function, | ||
| ): NormalizeError<ErrorArg> |
14218
2.64%174
1.16%146
4.29%