Last active
August 4, 2022 17:35
-
-
Save pi0/ea6ec75e4a77bd583831401c3fd953bc to your computer and use it in GitHub Desktop.
Super Simple Node.js String Colors Support
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
This snippets add super Simple Node.js String Colors Support. | |
See here: | |
http://stackoverflow.com/questions/32474241/node-js-terminal-color | |
http://stackoverflow.com/questions/9781218/how-to-change-node-jss-console-font-color |
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
// Node String Colors Support. (global version) (https://git.io/colors) | |
// Usage console.log(green("Hello world!") | |
const _c = require('util').inspect.colors; | |
Object.keys(_c).forEach(c =>global[c] = s =>`\x1b[${_c[c][0]}m${s}\x1b[${_c[c][1]}m`); |
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
// Node String Colors Support (https://git.io/colors) | |
// Usage console.log("Hello!".green()) | |
const _c = require('util').inspect.colors; | |
Object.keys(_c).forEach(c =>String.prototype[c] = s =>`\x1b[${_c[c][0]}m${s}\x1b[${_c[c][1]}m`); |
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
// Node String Colors Support. (no util version) (https://git.io/colors) | |
// Usage console.log("Hello!".green()) | |
const _c = {bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]}; | |
Object.keys(_c).forEach(c =>String.prototype[c] = s =>`\x1b[${_c[c][0]}m${s}\x1b[${_c[c][1]}m`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment