Socket
Socket
Sign inDemoInstall

clean-stack

Package Overview
Dependencies
1
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.1.0 to 5.2.0

23

index.d.ts

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

6

index.js

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

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc