Skip to content

Instantly share code, notes, and snippets.

@nickreese
Created May 12, 2022 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickreese/bde2322cd29aebd5e3619b0835bdb0b9 to your computer and use it in GitHub Desktop.
Save nickreese/bde2322cd29aebd5e3619b0835bdb0b9 to your computer and use it in GitHub Desktop.
Clean Stacktraces In JS
function cleanStack(stack) {
const parts = path.resolve('./').split('/');
let str = stack.toString();
for (const part of parts) {
const r = new RegExp(`/${part}/`, `gim`);
str = str.replace(r, '/');
}
return str;
}
const e = new Error('test');
const clean = cleanStack(e);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment