Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

chalk vs. colorette

by Roy Revelt   ·   posted on Sunday, 28 February 2021   ·   js

  • the top
  • COLORIZING HE…

Tooling choices are a subjective matter. Lately, I’ve been observing coloretteopens in a new tab taking over eroding chalkopens in a new tab, and I have few thoughts on this subject.


My current consensus is, at first, to avoid any terminal colourizing helpers, then, only then, consider using one. For the record, at the time of writing, I have published a dozen of CLI’s, and while half of them use a colourization helper, the other half does not. Out of those that do, one uses colorette, and 5 are using chalk.

In my opinion, what matters when choosing one is fundamentals — particularly, do unused “colours” (or any other cruft) end up in your bundle. When you import blue, bold and underline from colorette:

import { blue, bold, underline } from "colorette";

only those end up in your bundle.

But whole chalk will end up in your bundle:

import chalk from "chalk";

On the other hand, a) I don’t transpile or bundle CLI’s at all; and b) chalk seems more developer-friendly. Chained methods get code suggestion hints, compare:

chalk.blue.underline.bold("hi");
// vs
underline(bold(blue("hi")));

For the record, there’s also ansi-redopens in a new tab and bunch, but it seems a bad idea to split colourization wrappers into standalone libraries. What if you change your mind, to use not red but green? Would you replace one dependency with another? In that light, ansi-* group, in my opinion, will never outcompete chalk or colorette.

Colorizing helpers are optional

It’s crucial to dispel any FUDopens in a new tab around the terminal colourization subject.

All it takes to colourize the text in the terminal is to wrap it with two special chunks of text.

No magic here.

The frontal part contains a colour code (31 for red, 32 for green and so on), ending part is always 39. Personally, I snippetized all six or seven of them and memorized the numbers. For example, I have set up a snippet q - q - <the first letter of the colour> on Dashopens in a new tab (yes I’m still using the notorious oneopens in a new tab), which produces something like:

`\u001b[${33}m${`text`}\u001b[${39}m`

where “text” is placeholder. I deliberately wrapped colour numbers as ES6 template literals because they get highlighted; it’s easier to visually-grep.

This is it.

No magic.

The only challenge is when you want to stack the styling: for example, bold and red and background fill. But it’s rare, and in those cases, I reach for chalk or, more recently colorette.

↑ back to top
older newer

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab