Skip to content

Instantly share code, notes, and snippets.

@ewized
Created February 14, 2024 17:57
Show Gist options
  • Select an option

  • Save ewized/4685e49983c866a5e2288a9c0ea61dcb to your computer and use it in GitHub Desktop.

Select an option

Save ewized/4685e49983c866a5e2288a9c0ea61dcb to your computer and use it in GitHub Desktop.
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