Last active
November 13, 2017 17:48
-
-
Save aaronbeall/13ea0082db5874343cbfaec31ff3242b to your computer and use it in GitHub Desktop.
TypeScript NodeJS colorized console output
This file contains 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
// Colors: https://coderwall.com/p/yphywg/printing-colorful-text-in-terminal-when-run-node-js-script | |
const {log, error, warn, info, debug} = console; | |
console.error = (...args: any[]) => _console.error("\x1b[31m", ...args, "\x1b[0m") // red | |
console.warn = (...args: any[]) => _console.warn("\x1b[33m", ...args, "\x1b[0m") // yellow | |
console.info = (...args: any[]) => _console.info("\x1b[34m", ...args, "\x1b[0m") // blue | |
console.debug = (...args: any[]) => _console.debug("\x1b[2m", ...args, "\x1b[0m") // dim | |
// extras | |
declare global { | |
interface Console { | |
fatal: typeof console.error; | |
positive: typeof console.log; | |
success: typeof console.log; | |
fail: typeof console.log; | |
note: typeof console.log; | |
explode: typeof console.log; | |
} | |
} | |
console.fatal = (...args: any[]) => _console.error("\x1b[1m\x1b[31m", ...args, "\x1b[0m"); // bright red | |
console.positive = (...args: any[]) => _console.log("\x1b[1m\x1b[32m", ...args, "\x1b[0m"); // bright green | |
console.success = (...args: any[]) => _console.log("\x1b[42m", ...args, "\x1b[0m"); // green bg | |
console.fail = (...args: any[]) => _console.log("\x1b[41m", ...args, "\x1b[0m"); // red bg | |
console.note = (...args: any[]) => _console.log("\x1b[45m", ...args, "\x1b[0m"); // magenta bg | |
console.explode = (...args: any[]) => _console.log("\x1b[5m\x1b[1m\x1b[41m", ...args, "\x1b[0m"); // blinking bright red bg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment