Home

Awesome

Colorize Template

Tagged template literal for ANSI colors.

You need to provides an object which includes a variety of text coloring and formatting functions. You can use ready-made projects: Picocolors, Colorette, Kleur, Colors.js, Chalk

import { createColorize } from 'colorize-template'
import * as picocolors from 'picocolors'
import * as colorette from 'colorette'

let colorize = createColorize({
  ...picocolors,
  success: picocolors.green,
  error: colorette.red
})

console.log(
  colorize`Is red {red color} text`,
  colorize`Run {yellow.bgRed ${'yellow'} test}`,
  colorize`Is red {error error and success {success green text}}`,
)

Blocks are delimited by an opening curly brace {, a style, some content, and a closing curly brace }.