Created
February 19, 2021 18:33
-
-
Save jonathantneal/9b26c630b51b8130d28d0a9661e8e526 to your computer and use it in GitHub Desktop.
color.js - a color utility useful in a NodeJS terminal, console, command prompt
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
export default new Proxy( | |
Object.entries({ | |
reset: 0, | |
bold: 1, | |
dim: 2, | |
underline: 4, | |
blink: 5, | |
invert: 7, | |
hidden: 8, | |
black: 30, | |
red: 31, | |
green: 32, | |
yellow: 33, | |
blue: 34, | |
magenta: 35, | |
cyan: 36, | |
white: 37, | |
bgBlack: 40, | |
bgRed: 41, | |
bgGreen: 42, | |
bgYellow: 43, | |
bgBlue: 44, | |
bgMagenta: 45, | |
bgCyan: 46, | |
bgWhite: 47, | |
}).reduce((color, [name, id]) => ({ ...color, [name]: `\x1b[${id}m` }), {}), | |
{ | |
get: (colors, name) => (string) => colors[name] + string.replace(colors.reset, colors.reset + colors[name]) + colors.reset, | |
}, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment