colorific
v0.2.0
Published
Text coloring (with ANSI) for nodejs
Maintainers
Readme
node-colorific
Text coloring (with ANSI) for Node.js.
This package was heavily inspiried by Muslim Idris' node-curly-colors and several other ANSI/Color - specific packages available on the npm repository.
The reason - for me - to write yet another coloring package was that I personally don't like having any properties and/or functions attached to the String object and find it preferably to encode the colorinformation within the String itself. That leaves the possibility to save my messages in some JSON file and retrieve them later - making it easy to write internationalization functions. In addition I noticed that there are quite a couple of different format tags out there and people seem to like various different styles. So instead of inventing yet another fixed format library I tried to enable all kinds of custom format supporting - almost - every format that is currently already available.
Documentation
GitHub/npm only render this file by default, so here's everything else:
- Quickstart - install it and color your first string in under a minute.
- Tutorial - how tag formats, nesting, custom formats and
printf/template-literal usage actually work. - Cheatsheet - every predefined tag format and every supported ANSI code, in table form.
- Examples - copy-pasteable snippets, including the bundled color-table demo.
- Contribution guide - local setup, project layout, and how to submit a change.
- Changelog - notable changes per version.
- License - MIT.
Requirements
Node.js >= 18.18 (tested on the active 18.x, 20.x, 22.x and 24.x release lines,
see .github/workflows/ci.yml). The package ships
both an ES Module (src/colorific.js) and a CommonJS build
(src/colorific.cjs) and has zero runtime dependencies.
Installation
$ npm install --save colorific
$ yarn add colorificSee the Quickstart for how to use it right after installing.
Known quirks
- Unknown/unrecognized
@KEYvalues (anything not in the supported ANSI codes list in the Cheatsheet) are left completely untouched in the output, tag and all. - Compression removes redundant SGR codes. If the same code is opened twice
with no other code in between (e.g. two adjacent
@red:sections, or aresetthat is immediately followed by anotherreset), the second, redundant escape sequence is dropped rather than emitted twice. - Closing tags that don't match the key of the currently open tag (e.g.
<red>text</blue>when using theSGMLformat) are not recognized as a closing tag and are left in the output as literal text; the originally opened tag is still closed automatically at the end of the string.
See the Tutorial for the full explanation of why these happen.
Testing
npm testRuns the Mocha/Chai suite
in spec/, covering every predefined tag format, every supported ANSI code,
custom tag formats, nesting/compression behaviour and the CommonJS/ESM entry
points. See the Contribution guide for more.
Contributing
Issues and pull requests are welcome - see the Contribution guide for how to get set up, or jump straight to github.com/joetjen/node-colorific/issues.
License
MIT © 2013-2026 Jan Oetjen
