clean-stack
Advanced tools
Comparing version 1.2.0 to 1.3.0
13
index.js
'use strict'; | ||
const os = require('os'); | ||
const extractPathRegex = /\s+at.*(?:\(|\s)(.*)\)?/; | ||
const pathRegex = /^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/babel-polyfill\/.*)?\w+)\.js:\d+:\d+)|native)/; | ||
const homeDir = os.homedir(); | ||
module.exports = stack => { | ||
module.exports = (stack, options) => { | ||
options = Object.assign({pretty: false}, options); | ||
return stack.replace(/\\/g, '/') | ||
@@ -26,3 +30,10 @@ .split('\n') | ||
.filter(x => x.trim() !== '') | ||
.map(x => { | ||
if (options.pretty) { | ||
return x.replace(extractPathRegex, (m, p1) => m.replace(p1, p1.replace(homeDir, '~'))); | ||
} | ||
return x; | ||
}) | ||
.join('\n'); | ||
}; |
{ | ||
"name": "clean-stack", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Clean up error stack traces", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -43,2 +43,26 @@ # clean-stack [![Build Status](https://travis-ci.org/sindresorhus/clean-stack.svg?branch=master)](https://travis-ci.org/sindresorhus/clean-stack) | ||
## API | ||
### cleanStack(stack, [options]) | ||
#### stack | ||
Type: `string` | ||
The `stack` property of an `Error`. | ||
#### options | ||
Type: `Object` | ||
##### pretty | ||
Type: `boolean`<br> | ||
Default: `false` | ||
Prettify the file paths in the stack: | ||
`/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15` → `~/dev/clean-stack/unicorn.js:2:15` | ||
## Related | ||
@@ -45,0 +69,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4222
31
76