clean-stack
Advanced tools
Comparing version 2.2.0 to 3.0.0
@@ -11,2 +11,11 @@ declare namespace cleanStack { | ||
readonly pretty?: boolean; | ||
/** | ||
Remove the given base path from stack trace file paths, effectively turning absolute paths into relative ones. | ||
Example with `'/Users/sindresorhus/dev/clean-stack/'` as `basePath`: | ||
`/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15` → `unicorn.js:2:15` | ||
*/ | ||
readonly basePath?: string; | ||
} | ||
@@ -13,0 +22,0 @@ } |
15
index.js
'use strict'; | ||
const os = require('os'); | ||
const escapeStringRegexp = require('escape-string-regexp'); | ||
const extractPathRegex = /\s+at.*(?:\(|\s)(.*)\)?/; | ||
const extractPathRegex = /\s+at.*[(\s](.*)\)?/; | ||
const pathRegex = /^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/(?:babel-polyfill|pirates)\/.*)?\w+)\.js:\d+:\d+)|native)/; | ||
const homeDir = typeof os.homedir === 'undefined' ? '' : os.homedir(); | ||
module.exports = (stack, options) => { | ||
options = Object.assign({pretty: false}, options); | ||
module.exports = (stack, {pretty = false, basePath} = {}) => { | ||
const basePathRegex = basePath && new RegExp(`(at | \\()${escapeStringRegexp(basePath)}`, 'g'); | ||
@@ -33,6 +34,10 @@ return stack.replace(/\\/g, '/') | ||
.map(line => { | ||
if (options.pretty) { | ||
return line.replace(extractPathRegex, (m, p1) => m.replace(p1, p1.replace(homeDir, '~'))); | ||
if (basePathRegex) { | ||
line = line.replace(basePathRegex, '$1'); | ||
} | ||
if (pretty) { | ||
line = line.replace(extractPathRegex, (m, p1) => m.replace(p1, p1.replace(homeDir, '~'))); | ||
} | ||
return line; | ||
@@ -39,0 +44,0 @@ }) |
{ | ||
"name": "clean-stack", | ||
"version": "2.2.0", | ||
"version": "3.0.0", | ||
"description": "Clean up error stack traces", | ||
"license": "MIT", | ||
"repository": "sindresorhus/clean-stack", | ||
"funding": "https://github.com/sponsors/sindresorhus", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
"node": ">=10" | ||
}, | ||
@@ -28,9 +29,11 @@ "scripts": { | ||
"error", | ||
"err", | ||
"electron" | ||
], | ||
"dependencies": { | ||
"escape-string-regexp": "4.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
"ava": "^2.4.0", | ||
"tsd": "^0.11.0", | ||
"xo": "^0.32.0" | ||
}, | ||
@@ -37,0 +40,0 @@ "browser": { |
@@ -1,2 +0,2 @@ | ||
# clean-stack [![Build Status](https://travis-ci.org/sindresorhus/clean-stack.svg?branch=master)](https://travis-ci.org/sindresorhus/clean-stack) | ||
# clean-stack [![Build Status](https://travis-ci.com/sindresorhus/clean-stack.svg?branch=master)](https://travis-ci.com/github/sindresorhus/clean-stack) | ||
@@ -9,3 +9,2 @@ > Clean up error stack traces | ||
## Install | ||
@@ -17,3 +16,2 @@ | ||
## Usage | ||
@@ -45,6 +43,5 @@ | ||
## API | ||
### cleanStack(stack, [options]) | ||
### cleanStack(stack, options?) | ||
@@ -59,7 +56,7 @@ #### stack | ||
Type: `Object` | ||
Type: `object` | ||
##### pretty | ||
Type: `boolean`<br> | ||
Type: `boolean`\ | ||
Default: `false` | ||
@@ -71,11 +68,15 @@ | ||
##### basePath | ||
## Related | ||
Type: `string?` | ||
- [extrack-stack](https://github.com/sindresorhus/extract-stack) - Extract the actual stack of an error | ||
- [stack-utils](https://github.com/tapjs/stack-utils) - Captures and cleans stack traces | ||
Remove the given base path from stack trace file paths, effectively turning absolute paths into relative ones. | ||
Example with `'/Users/sindresorhus/dev/clean-stack/'` as `basePath`: | ||
## License | ||
`/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15` → `unicorn.js:2:15` | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) | ||
## Related | ||
- [extract-stack](https://github.com/sindresorhus/extract-stack) - Extract the actual stack of an error | ||
- [stack-utils](https://github.com/tapjs/stack-utils) - Captures and cleans stack traces |
Sorry, the diff of this file is not supported yet
6357
79
78
1
+ Addedescape-string-regexp@4.0.0
+ Addedescape-string-regexp@4.0.0(transitive)