Set ansi colors in strings using <> markers and chalk or ansi-colors.
import chalker from "chalker";
console.log(chalker("<red.bgGreen>Red on Green Text</>"));
// with template string tagging
console.log(chalker`<green>hello world</green>`);
A typical use case is to easily manage colors for logs that could go to console or log servers.
const msg = `<red>some error occurred...</red>`;
// log to console for visual with colors
if (!production) console.log(chalker(msg));
// log to log server with colors removed
logger.log(chalker.remove(msg));
npm i --save chalker chalk
or:
npm i --save chalker ansi-colors
chalker expects either chalk >= 4 or ansi-colors >= 4 as a peer dependency.

Color markers has the <red>red text</red> format. You can use any valid methods chalk supports.
<blue.bold>blue bold text</blue.bold> will colorize blue bold text with chalk.blue.bold.</>The following HTML entities escapes are supported:
| Entity | Character | Entity | Character |
|---|---|---|---|
< |
< | > |
> |
& |
& | |
non-breaking space |
' |
' | © |
© |
" |
" | ® |
® |
HTML escape using code points also works:
&#xhhhh; where hhhh is the Hex code point.&#nnnn; where nnnn is the Decimal code point.�� makes 👩Some advanced color markers use chalker compatibility wrappers when Chalk does not provide
the corresponding API directly.
Chalk advanced colors can be applied with:
| chalk API | chalker marker | chalk API | chalker marker |
|---|---|---|---|
chalk.rgb |
<(255, 10, 20)>, <rgb(255,10,20)> |
chalk.bgRgb |
<bg(255, 10, 20)>, <bgRgb(255,10,20)> |
chalk.hex |
<#FF0000>, <hex(#FF0000)> |
chalk.bgHex |
<bg#0000FF>, <bgHex(#0000FF)> |
chalk.keyword |
<orange>, <(orange)>, <keyword(orange)> |
chalk.bgKeyword |
<bg-orange>, <bg(orange)>, <bgKeyword(orange)> |
chalk.hsl |
<hsl(32,100,50)> |
chalk.bgHsl |
<bgHsl(32,100,50)> |
chalk.hsv |
<hsv(32,100,100)> |
chalk.bgHsv |
<bgHsv(32,100,100)> |
chalk.hwb |
<hwb(32,0,50)> |
chalk.bgHwb |
<bgHwb(32,0,50)> |
a marker is tried with chalk.keyword if:
it's not detected as hex value
it doesn't contain params enclosed in ()
it's not found as a basic color that chalk supports
for example, this is a chalk color keyword: <orange>
If it's prefixed with "bg-" then it's tried using chalk.bgKeyword
<bg-orange>All markers can be comined with . in any order as long as they work with chalk
<#FF0000.bg#0000FF.bg-orange.keyword(red)>See the full API reference for every function, option, and type.
chalkerchalker(str, [chalkInstance]);
str - String with chalker color markerschalkInstance - Optional custom instance of chalk.
new chalk.Instance({level: 2})Returns: A string with terminal/ansi color codes
If
chalk.supportsColorisfalse, then markers are parsed the same way but no colors are applied. The output is the colored output minus the color codes, with HTML entities decoded. Chalk 5+ instances have nosupportsColor. Atlevel0, chalk itself emits no color codes.
chalker.CHALKimport ansiColors from "ansi-colors";
chalker.CHALK = ansiColors;
Set the default colors library. By default, chalker loads chalk first and falls back to
ansi-colors.
With ansi-colors,
chalkerchanges the module object it uses. ansi-colors has no true-color support, sochalkeraddsrgb,bgRgb,hexandbgHexmethods to it. This happens on load:chalker/ansi-colorsalways does it, andchalkerdoes it when it falls back to ansi-colors. Each true-color marker, such as<#FF0000>or<orange>, also registers a style named likechalker_rgb_255_0_0throughcolors.alias().The default ansi-colors export is shared, so other code that imports ansi-colors sees these changes. Setting
chalker.CHALKto an instance fromcolors.create()keeps the new styles on that instance. The methods added on load stay on the shared module.
chalkeris published as an ESM-only package ("type": "module"). It can still be loaded from CommonJS withrequire("chalker")on Node >=22.18, but sincerequire()of an ESM module returns the module's namespace object, you need to access.default:const chalker = require("chalker").default;
chalker.removechalker.remove(str, keepHtml);
str - String with chalker color markerskeepHtml - If true, then don't decode HTML entity escapes.Remove all chalker markers, then decode HTML escapes and return the plain text string. Whitespace is kept as is. Before 2.3.0, leading and trailing whitespace was trimmed.
Returns: A plain text string without chalker color markers
chalker.decodeHtmlchalker.decodeHtml(str);
str - String to decode HTML entitiesReturns: String with HTML entities escapes decoded
Copyright (c) 2022-2026 Joel Chen
Licensed under the Apache License, Version 2.0.