cli-color

Colors, styles, and formatting utilities for Node.js terminal output

Library
npm
v2.0.4
675stars
ISC

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
38/100Needs Attention
Development Activity0
Maintenance20
Community52
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
78/100Good
Architecture74
Code Quality78
Innovation70
Learning Curve88

cli-color is a Node.js library for adding ANSI colors, text styles, and formatting to console output. It exposes a chainable API (clc.red.bgWhite.underline('text')) that composes colors and styles into reusable formatting functions without ever mutating built-in prototypes.

Beyond colors, the package bundles a broad toolkit for terminal control: cursor movement, line and screen erasing, column layout, progress throbbers, xterm 256-color support, ANSI stripping, and honoring the NO_COLOR convention. It is a long-standing, widely depended-upon utility with millions of weekly downloads.

What You Get

  • A chainable color and style API covering all standard ANSI foreground/background colors and styles (bold, italic, underline, blink, inverse, strike)
  • xterm 256-color support with nearest-color matching for truecolor-style output
  • Terminal control helpers for cursor movement, screen/line erase, beep, and window size
  • Layout and text utilities including column formatting, ANSI stripping, and stripped-length measurement
  • Automatic NO_COLOR environment variable support to disable styling when requested

Common Use Cases

  • Colorizing log levels and status messages in command-line tools
  • Building formatted terminal UIs with columns, progress throbbers, and cursor control
  • Rendering 256-color output that degrades gracefully on limited terminals
  • Measuring and stripping ANSI codes when computing on-screen text width

Under The Hood

Architecture - cli-color is organized as a set of small CommonJS modules (index.js plus feature files like move.js, erase.js, columns.js, throbber.js) that each export a focused capability. The color API in index.js builds chainable formatter objects whose properties lazily compose SGR (Select Graphic Rendition) escape sequences; lib/sgr.js, lib/xterm-colors.js, and lib/xterm-match.js handle the ANSI/xterm encoding. Memoization (via memoizee) caches generated style functions.

Tech Stack - Pure JavaScript for Node.js with no compile step. It leans on the author’s ecosystem utilities — d, es5-ext, es6-iterator, memoizee, and timers-ext — for prototype-safe helpers, iteration, memoization, and timer control. Tooling uses tad as the test runner with nyc for coverage, plus ESLint and Prettier for style.

Code Quality - The repository carries a mature test suite under test/ mirroring the module layout, coverage tracking via nyc, and enforced linting/formatting. The code deliberately avoids monkey-patching built-ins, and honors the NO_COLOR standard. Being over a decade old, the codebase is stable and battle-tested, though recent development activity is low.

API Design - The chainable API is the library’s standout: clc.red.bgWhite.underline(text) reads naturally and encourages predefining named stylings for reuse. Colors, styles, and control helpers share a consistent surface, and the README documents each with runnable snippets. The learning curve is minimal for basic coloring, with more advanced terminal-control helpers available when needed.”

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search