Created
February 14, 2024 17:57
-
-
Save ewized/4685e49983c866a5e2288a9c0ea61dcb 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 red = (text) => ({ color: '31', text }) | |
| const green = (text) => ({ color: '32', text }) | |
| const white = (text) => ({ color: '0', text }) | |
| const color = (strings, ...args) => { | |
| const colorize = args.map(({ color, text }) => `\x1b[${color}m${text}`) | |
| return strings.reduce((acc, item) => `${acc}${item}${colorize.shift() ?? ''}`, '') | |
| } | |
| console.log(color`${red`FAIL`} ${white`foobar`} ${green`pass`}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment