clean-stack
Advanced tools
+12
-1
| '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'); | ||
| }; |
+1
-1
| { | ||
| "name": "clean-stack", | ||
| "version": "1.2.0", | ||
| "version": "1.3.0", | ||
| "description": "Clean up error stack traces", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
+24
-0
@@ -43,2 +43,26 @@ # clean-stack [](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 @@ |
4222
16.53%31
40.91%76
46.15%