yellback
Version:
A Colorful Logger package
24 lines (23 loc) • 987 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Yellback = Yellback;
function Yellback(depth = 1) {
const stack = new Error().stack?.split("\n");
if (!stack || stack.length < depth + 2) {
return "\x1b[41m📍 Unable to determine caller\x1b[0m"; // Red background
}
const callerLine = stack[depth + 1];
const match = callerLine.match(/at\s+(.*?)\s+\((.*?):(\d+):(\d+)\)/) ||
callerLine.match(/at\s+(.*?):(\d+):(\d+)/);
if (match) {
if (match.length === 5) {
const [, fnName, file, line, col] = match;
console.log(`\x1b[45m📍 Called from:\x1b[0m \x1b[30;43m ${fnName} \x1b[0m \x1b[42m (${file}:${line}:${col}) \x1b[0m`);
}
else {
const [, file, line, col] = match;
console.log(`\x1b[45m📍 Called from:\x1b[0m \x1b[42m (${file}:${line}:${col}) \x1b[0m`);
}
}
// console.log(`\x1b[41m📍 Called from: Unknown\x1b[0m`);
}