Created
February 25, 2025 16:19
-
-
Save jherskow/35cfee5e60f67e7572110bce12a9c01a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const colorize = (color: string, message: string) => { | |
const ansiColors: Record<string, string> = { | |
green: '\x1b[32m', | |
orange: '\x1b[33m', // Yellow (closest to orange in ANSI) | |
red: '\x1b[31m', | |
redBG: '\x1b[41m', // Red background | |
blue: '\x1b[34m', | |
blueBG: '\x1b[44m', // Blue background | |
pink: '\x1b[35m', // Magenta (closest to pink) | |
pinkBG: '\x1b[45m', // Magenta background | |
reset: '\x1b[0m', | |
}; | |
if (color.endsWith('BG')) { | |
return [`${ansiColors[color]} ${message} ${ansiColors.reset}`]; | |
} | |
return [`${ansiColors[color] ?? ''}${message}${ansiColors.reset}`]; | |
}; | |
export const jconsole = { | |
log: (...args: any[]) => { | |
console.log(...colorize('blueBG', '[JLOG]'), ...args); | |
}, | |
warn: (...args: any[]) => { | |
console.warn(...colorize('pinkBG', '[JWARN]'), ...args); | |
}, | |
error: (...args: any[]) => { | |
console.error(...colorize('redBG', '[JERROR]'), ...args); | |
}, | |
info: (...args: any[]) => { | |
console.info(...colorize('green', '[JINFO]'), ...args); | |
}, | |
debug: (...args: any[]) => { | |
console.debug(...colorize('blue', '[JDEBUG]'), ...args); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment