ansi-colors

Fast, zero-dependency ANSI color and style helpers for terminal text

Library
npm
v4.1.3
454stars
MIT License

Repository Health

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

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
80/100Excellent
Architecture76
Code Quality80
Innovation74
Learning Curve90

ansi-colors is a fast Node.js library for adding ANSI colors and text styles to terminal output. It is a drop-in replacement for chalk with no dependencies, positioning itself as one of the fastest terminal styling libraries in the ecosystem and the official ANSI styling library for gulp.

The API exposes chainable style methods (colors.red.bold('text')), a bundled set of cross-platform terminal symbols, and helpers to enable, disable, strip, or unstyle ANSI codes. It is depended upon by hundreds of projects including enquirer, mocha, aws-cdk, and RedwoodJS, with tens of millions of weekly downloads.

What You Get

  • Chainable color and style methods covering standard ANSI colors, backgrounds, and styles
  • A cross-platform terminal symbols set (check, cross, pointer, etc.) with Windows fallbacks
  • Global enable/disable of coloring plus per-call unstyle and strip helpers
  • Zero runtime dependencies for fast install and minimal footprint
  • TypeScript type definitions bundled in the package

Common Use Cases

  • Colorizing CLI output, prompts, and log messages in Node.js tools
  • Replacing chalk to cut dependencies and speed up terminal styling
  • Rendering status symbols that display consistently across Windows and Unix terminals
  • Stripping ANSI codes from styled strings before writing to files or logs

Under The Hood

Architecture - ansi-colors is built around a single index.js that defines a styles table of ANSI open/close code pairs and lazily creates chainable wrapper functions for each color and style. Each style function wraps text with the appropriate escape sequences and supports nesting by re-opening codes after a nested close. A separate symbols.js module maps semantic symbol names (check, cross, pointer) to platform-appropriate glyphs, choosing ASCII fallbacks on Windows.

Tech Stack - Pure JavaScript for Node.js with zero runtime dependencies, which is central to its speed and small footprint. It bundles TypeScript declarations in a types/ directory and includes a bench/ suite for performance comparisons against chalk, kleur, and turbocolor. Tests run under mocha.

Code Quality - The repository ships a test.js suite run with mocha, benchmarks demonstrating its performance claims, and bundled type definitions. The implementation is compact and focused; while active development has stopped, its stability is evidenced by adoption across major tools (mocha, aws-cdk, enquirer) and tens of millions of weekly downloads.

API Design - The API mirrors chalk closely, easing migration: chainable properties like colors.red.bold read naturally and every style composes with every other. Global enable/disable, unstyle, and strip helpers cover common needs. With no configuration required and familiar naming, the learning curve is minimal, especially for anyone who has used chalk.”

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