set-error-stack
Advanced tools
Comparing version 1.0.0 to 2.0.0
import normalizeException from"normalize-exception"; | ||
export default function setErrorStack(error,newStack){ | ||
const setErrorStack=(error,newStack)=>{ | ||
if(typeof newStack!=="string"){ | ||
throw new TypeError(`Stack trace must be a string: ${newStack}`); | ||
throw new TypeError(`Stack trace must be a string: ${newStack}`) | ||
} | ||
@@ -13,3 +13,3 @@ | ||
if(newStack===currentStack){ | ||
return errorA; | ||
return errorA | ||
} | ||
@@ -19,5 +19,6 @@ | ||
updateMessage({error:errorA,newStack,currentStack,name}); | ||
return errorA; | ||
} | ||
return errorA | ||
}; | ||
export default setErrorStack; | ||
@@ -27,5 +28,6 @@ | ||
const updateMessage=function({error,newStack,currentStack,name}){ | ||
const updateMessage=({error,newStack,currentStack,name})=>{ | ||
if(getStackMessage(currentStack,name)===undefined){ | ||
return; | ||
return | ||
} | ||
@@ -36,11 +38,11 @@ | ||
if(message!==undefined){ | ||
setNonEnumProp(error,"message",message); | ||
setNonEnumProp(error,"message",message) | ||
} | ||
}; | ||
const getStackMessage=function(stack,name){ | ||
const getStackMessage=(stack,name)=>{ | ||
const startIndex=getStartIndex(stack,name); | ||
if(startIndex===-1){ | ||
return; | ||
return | ||
} | ||
@@ -52,20 +54,20 @@ | ||
if(endIndex===-1){ | ||
return; | ||
return | ||
} | ||
return stackA.slice(0,endIndex); | ||
return stackA.slice(0,endIndex) | ||
}; | ||
const getStartIndex=function(stack,name){ | ||
const getStartIndex=(stack,name)=>{ | ||
const namePrefix=`${name}: `; | ||
if(stack.startsWith(namePrefix)){ | ||
return namePrefix.length; | ||
return namePrefix.length | ||
} | ||
const startIndex=stack.indexOf(`\n${namePrefix}`); | ||
return startIndex===-1?startIndex:startIndex+namePrefix.length+1; | ||
return startIndex===-1?startIndex:startIndex+namePrefix.length+1 | ||
}; | ||
const setNonEnumProp=function(error,propName,value){ | ||
const setNonEnumProp=(error,propName,value)=>{ | ||
@@ -76,5 +78,4 @@ Object.defineProperty(error,propName,{ | ||
writable:true, | ||
configurable:true}); | ||
}; | ||
//# sourceMappingURL=main.js.map | ||
configurable:true | ||
}) | ||
}; |
{ | ||
"name": "set-error-stack", | ||
"version": "1.0.0", | ||
"version": "2.0.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}" | ||
], | ||
@@ -50,15 +51,14 @@ "sideEffects": false, | ||
"directories": { | ||
"lib": "src", | ||
"test": "test" | ||
"lib": "src" | ||
}, | ||
"dependencies": { | ||
"normalize-exception": "^2.11.0" | ||
"normalize-exception": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"@ehmicky/dev-tasks": "^1.0.102", | ||
"test-each": "^5.6.0" | ||
"@ehmicky/dev-tasks": "^2.0.80", | ||
"test-each": "^6.0.1" | ||
}, | ||
"engines": { | ||
"node": ">=14.18.0" | ||
"node": ">=16.17.0" | ||
} | ||
} |
[![Node](https://img.shields.io/badge/-Node.js-808080?logo=node.js&colorA=404040&logoColor=66cc33)](https://www.npmjs.com/package/set-error-stack) | ||
[![Browsers](https://img.shields.io/badge/-Browsers-808080?logo=firefox&colorA=404040)](https://unpkg.com/set-error-stack?module) | ||
[![TypeScript](https://img.shields.io/badge/-Typed-808080?logo=typescript&colorA=404040&logoColor=0096ff)](/types/main.d.ts) | ||
[![TypeScript](https://img.shields.io/badge/-Typed-808080?logo=typescript&colorA=404040&logoColor=0096ff)](/src/main.d.ts) | ||
[![Codecov](https://img.shields.io/badge/-Tested%20100%25-808080?logo=codecov&colorA=404040)](https://codecov.io/gh/ehmicky/set-error-stack) | ||
[![Minified size](https://img.shields.io/bundlephobia/minzip/set-error-stack?label&colorA=404040&colorB=808080&logo=webpack)](https://bundlephobia.com/package/set-error-stack) | ||
[![Twitter](https://img.shields.io/badge/-Twitter-808080.svg?logo=twitter&colorA=404040)](https://twitter.com/intent/follow?screen_name=ehmicky) | ||
[![Mastodon](https://img.shields.io/badge/-Mastodon-808080.svg?logo=mastodon&colorA=404040&logoColor=9590F9)](https://fosstodon.org/@ehmicky) | ||
[![Medium](https://img.shields.io/badge/-Medium-808080.svg?logo=medium&colorA=404040)](https://medium.com/@ehmicky) | ||
@@ -54,7 +54,10 @@ | ||
This package works in both Node.js >=14.18.0 and | ||
[browsers](https://raw.githubusercontent.com/ehmicky/dev-tasks/main/src/tasks/build/browserslist). | ||
It is an ES module and must be loaded using | ||
This package works in both Node.js >=16.17.0 and | ||
[browsers](https://raw.githubusercontent.com/ehmicky/dev-tasks/main/src/browserslist). | ||
This is an ES module. It must be loaded using | ||
[an `import` or `import()` statement](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c), | ||
not `require()`. | ||
not `require()`. If TypeScript is used, it must be configured to | ||
[output ES modules](https://www.typescriptlang.org/docs/handbook/esm-node.html), | ||
not CommonJS. | ||
@@ -76,4 +79,4 @@ # API | ||
- [`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 | ||
@@ -95,2 +98,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 | ||
@@ -104,2 +109,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 | ||
@@ -130,4 +139,4 @@ # Support | ||
<!-- | ||
<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-stack/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-stack/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-stack/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-stack/commits?author=ehmicky" title="Documentation">📖</a></td></tr></table> | ||
--> | ||
<!-- ALL-CONTRIBUTORS-LIST:END --> |
10431
74
138
+ Addedis-error-instance@2.0.0(transitive)
+ Addednormalize-exception@3.0.0(transitive)
- Removedis-error-instance@1.6.0(transitive)
- Removednormalize-exception@2.11.0(transitive)
Updatednormalize-exception@^3.0.0