A library that extends the chalk.js library by allowing you to apply color and style to HTML-like templates.
npm install chalk-mate
import chalkMate from 'chalk-mate'
const styled = chalkMate(`<red>Hello</red> <green>World</green>`)
console.log(styled)
The foreground color can be applied:
- By using the color name as the tag name.
- By using the
color
attribute.
CSS color names are supported. See CSS Color Names for a list of supported color names.
<red>Hello World</red>
<text color="red">Hello World</text>
<text color="#ff0000">Hello World</text>
<text color="255, 0, 0">Hello World</text>
The background color can be applied:
- By using the
bg-
prefix before the color name as the tag name. - By using the
bg
attribute.
CSS color names are supported. See CSS Color Names for a list of supported color names.
<bg-red>Hello World</bg-red>
<text bg="red">Hello World</text>
<white bg="#ff0000">Hello World</white>
<white bg="255, 0, 0">Hello World</white>
The following text styles are supported:
- Bold
- Dim
- Italic
- Underline
- Inverse
- Hidden
- Strikethrough
- Visible
See modifiers in chalk.js for more information.
They can be applied:
- By using the style name as the tag name.
- By using the name of the style as the attribute.
<bold>Hello World</bold>
or
<text bold>Hello World</text>
<italic>Hello World</italic>
or
<text italic>Hello World</text>
You can nest tags within tags.
<red>Hello <bold>World</bold></red>
You can combine styles and colors.
<bg-red color="white" underline>Hello <bold italic color="blue" bg="white">World</bold></bg-red>
You can print the text without styles and colors by using the stripColors
function.
import { stripColors } from 'chalk-mate'
console.log(stripColors(`<red>Hello</red> <green>World</green>`))
Copyright © Moses Gitau All rights reserved.
Find a copy of the License here