For example there’s a
foregroundColor util that does “nothing” by itself, but
it’s used to create other utils like
is the result of an
optionalFormat util that will format only under the right
One particular thing this library has that I think is pretty neat, is that it can be used as a tag functions for template literals, like this:
I made this library when I started coding my own CLI tools for Node.js, and I wanted to have my own library with only some basic utils that I needed for color, position, and so on. Alternatives such as chalk and kleur didn’t fit my needs, and as usual I wanted to use the opportunity to build something myself, to learn from it.
I built this library using TypeScript, with configurations from my shared configs. I made it ESM only as soon as Node started supporting ESM modules, and I made it tree-shakeable by using named exports.
I relied heavily on the the ANSI escape codes wiki to learn about the different things I could do with ANSI escape codes, and I used the chalk and kleur source code to learn about stuff like detecting if the CLI has color support.
One particular challenge was to have test aligned with the other libraries,
@lou.codes/test is based on
@lou.codes/ansi itself, so using
it would mean having circular dependencies. The solution was to rely on
node:test with a wrapper that makes test similar to the ones in the other