Skip to content

Instantly share code, notes, and snippets.

@Restuta
Last active Mar 12, 2020
Embed
What would you like to do?
neat-stack.js
import cleanStack from 'clean-stack';
// dims non-useful log lines in stack traces
const neatStack = (colorize, stack) => {
// add parts of stack trace lines here that should be ignored
const regexParts = [
'(node_modules)',
'(WEBPACK_IMPORTED)',
'(next_tick.js)',
'(domain.js)',
'(timers.js)',
'(overloadSequlizeFind)',
'(Array.)',
'(at new Promise)',
'(_next)',
'(_callee)',
'(__webpack_require__)',
].join('|');
const internalStackRegex = new RegExp(`at.*${regexParts}`);
const cleanedStack = cleanStack(String(stack));
const stackLines = cleanedStack.split('\n');
const title = R.head(stackLines);
const colorizedStackLines = R.pipe(
R.tail,
R.map(line =>
line.match(internalStackRegex) || line.match('From previous event')
? chalk.dim(line)
: colorize(line),
),
R.join('\n'),
)(stackLines);
return colorize(`${title}\n${colorizedStackLines}`);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment