clean-stack
Advanced tools
Comparing version 5.1.0 to 5.2.0
@@ -19,2 +19,25 @@ export type Options = { | ||
readonly basePath?: string; | ||
/** | ||
Remove the stack lines where the given function returns `false`. The function receives the path part of the stack line. | ||
@example | ||
``` | ||
import cleanStack from 'clean-stack'; | ||
const error = new Error('Missing unicorn'); | ||
console.log(cleanStack(error.stack)); | ||
// Error: Missing unicorn | ||
// at Object.<anonymous> (/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15) | ||
// at Object.<anonymous> (/Users/sindresorhus/dev/clean-stack/omit-me.js:1:16) | ||
const pathFilter = path => !/omit-me/.test(path); | ||
console.log(cleanStack(error.stack, {pathFilter})); | ||
// Error: Missing unicorn | ||
// at Object.<anonymous> (/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15) | ||
``` | ||
*/ | ||
readonly pathFilter?: (path: string) => boolean; | ||
}; | ||
@@ -21,0 +44,0 @@ |
@@ -7,3 +7,3 @@ import escapeStringRegexp from 'escape-string-regexp'; | ||
export default function cleanStack(stack, {pretty = false, basePath} = {}) { | ||
export default function cleanStack(stack, {pretty = false, basePath, pathFilter} = {}) { | ||
const basePathRegex = basePath && new RegExp(`(file://)?${escapeStringRegexp(basePath.replace(/\\/g, '/'))}/?`, 'g'); | ||
@@ -36,3 +36,5 @@ const homeDirectory = pretty ? getHomeDirectory() : ''; | ||
return !pathRegex.test(match); | ||
return pathFilter | ||
? !pathRegex.test(match) && pathFilter(match) | ||
: !pathRegex.test(match); | ||
}) | ||
@@ -39,0 +41,0 @@ .filter(line => line.trim() !== '') |
{ | ||
"name": "clean-stack", | ||
"version": "5.1.0", | ||
"version": "5.2.0", | ||
"description": "Clean up error stack traces", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -76,2 +76,25 @@ # clean-stack | ||
##### pathFilter | ||
Type: `(path: string) => boolean` | ||
Remove the stack lines where the given function returns `false`. The function receives the path part of the stack line. | ||
```js | ||
import cleanStack from 'clean-stack'; | ||
const error = new Error('Missing unicorn'); | ||
console.log(cleanStack(error.stack)); | ||
// Error: Missing unicorn | ||
// at Object.<anonymous> (/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15) | ||
// at Object.<anonymous> (/Users/sindresorhus/dev/clean-stack/omit-me.js:1:16) | ||
const pathFilter = path => !/omit-me/.test(path); | ||
console.log(cleanStack(error.stack, {pathFilter})); | ||
// Error: Missing unicorn | ||
// at Object.<anonymous> (/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15) | ||
``` | ||
## Related | ||
@@ -78,0 +101,0 @@ |
8747
102
103