Skip to content

Meant to be used with `clean-stacktrace` as mapper function. Makes absolute paths inside stack traces to relative paths.

License

Notifications You must be signed in to change notification settings

tunnckoCore/clean-stacktrace-relative-paths

Repository files navigation

relative-paths NPM version mit license NPM monthly downloads npm total downloads

Meant to be used with clean-stacktrace as mapper function. Makes absolute paths inside stack traces to relative paths.

code climate code style linux build windows build code coverage dependency status paypal donate

You might also be interested in always-done.

Table of Contents

(TOC generated by verb using markdown-toc)

Install

Install with npm

$ npm install clean-stacktrace-relative-paths --save

or install using yarn

$ yarn add clean-stacktrace-relative-paths

Usage

For more use-cases see the tests

const cleanStacktraceRelativePaths = require('clean-stacktrace-relative-paths')

API

Cleans stack traces to use relative paths, instead of absolute paths. Pass a cwd if you want to customize, otherwise process.cwd() is used by default.

Meant to be used as mapper argument in clean-stacktrace

Params

  • [cwd] {String}: custom current working directory
  • returns {Function}: a function that can be passed as mapper to clean-stacktrace

Example

const cleanStack = require('clean-stacktrace')
const relativePaths = require('clean-stacktrace-relative-paths')

const error = new Error('Missing unicorn')
console.log(error.stack)
// =>
// Error: Missing unicorn
//     at Object.<anonymous> (/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15)
//     at Module._compile (module.js:409:26)
//     at Object.Module._extensions..js (module.js:416:10)
//     at Module.load (module.js:343:32)
//     at Function.Module._load (module.js:300:12)
//     at Function.Module.runMain (module.js:441:10)
//     at startup (node.js:139:18)

const mapper = relativePaths()
const stack =