picocolors
The tiniest, fastest zero-dependency library for ANSI terminal color formatting in Node.js.
Repository Health
Technical Analysis
picocolors is a zero-dependency JavaScript library for adding ANSI color and style formatting to terminal output. At roughly 7 KB installed and benchmarked up to 2x faster than Chalk, it exposes a flat set of formatter functions — colors, background colors, and text styles like bold, italic, and underline — built around a single lightweight closure that correctly handles nested color codes without corrupting output.
Because of its tiny footprint and lack of dependencies, picocolors has become a quiet standard in the Node.js tooling ecosystem: it ships inside PostCSS, Stylelint, SVGO, Browserslist, Vite, and many other widely-used build tools and CLIs, where minimizing node_modules bloat and startup time matters. It supports both CommonJS and ESM consumers, includes TypeScript declarations, respects the NO_COLOR convention, and ships a browser-safe build for bundlers that need one.
What You Get
- Full ANSI color palette - Standard and bright foreground/background color functions (red, green, blue, gray, and their
Bright/bgvariants) covering all 16 base terminal colors. - Text style formatters - bold, dim, italic, underline, inverse, hidden, strikethrough, and reset functions for styling terminal text beyond color.
- Nested-formatting safety - A
replaceClosemechanism that correctly re-opens an outer color code when a nested formatter’s close sequence appears mid-string, avoiding the broken output some competing libraries produce. - Environment-aware color detection - An
isColorSupportedflag computed fromNO_COLOR,FORCE_COLOR,--color/--no-colorflags, TTY status, and CI environment, plus acreateColors(enabled)factory to override it manually. - Dual CJS/ESM and browser builds - A Node-targeted CommonJS module plus a separate
picocolors.browser.jsbuild wired through package.json’sbrowserfield, with bundled TypeScript type declarations.
Common Use Cases
- CLI tool output - Formatting success/error/warning messages, prompts, and diffs in command-line tools without pulling in a heavier dependency tree.
- Build tool and bundler logging - Coloring compiler/bundler console output (as used inside PostCSS, Vite, SVGO, Stylelint, and Browserslist) where install size and cold-start time affect every consumer’s build.
- Drop-in Chalk replacement - Swapping out Chalk in existing codebases to shrink node_modules and speed up script startup, using the documented migration path for chained-call syntax.
- Test runners and dev servers - Highlighting pass/fail output, stack traces, and status messages in local development tooling.
Under The Hood
Architecture picocolors is a single-file, dependency-free module built around one core primitive: a formatter closure that wraps text in ANSI open/close escape codes and handles nested closes via replaceClose (so nesting one color inside another doesn’t prematurely terminate the outer code). All roughly 40 color/style functions are generated by partially applying formatter with different escape sequences, avoiding per-function duplication. The createColors(enabled) factory produces either the real formatters or no-op passthroughs (() => String) based on a boolean, cleanly separating “does the terminal support color” from “format the string” — that separation is essentially the whole architecture. A parallel picocolors.browser.js variant ships for bundlers that need a browser build.
Tech Stack The stack is deliberately plain: dependency-free CommonJS JavaScript targeting Node 6+ and browsers, with a hand-written .d.ts for TypeScript consumers and a browser field in package.json to swap in a browser-safe build for bundlers. There is no build step, transpiler, or runtime dependency — the entire “stack” is authoring conventions (a Prettier config using tabs and no semicolons) and a tests/test.js file run directly by node, reflecting the project’s goal of minimizing everything downstream consumers have to install.
Code Quality The source is under 80 lines with tight, readable logic; naming is clear (isColorSupported, createColors, formatter), and the nested-color-code handling in replaceClose shows real attention to a subtle correctness edge case — nested ANSI codes resetting the wrong style — that several competing libraries get wrong. There’s no linter configuration beyond Prettier, and tests live in a small hand-rolled tests/test.js/tests/environments.js rather than a full test-runner framework, but the terse, single-file source is easy to read end-to-end in one sitting.
API Design The API is a flat object of self-explanatory formatter functions (pc.red(), pc.bold()) plus one power-user escape hatch (createColors(enabled)) for manually controlling color support — there’s no method chaining like Chalk’s, which keeps the mental model simple but requires nesting calls for combined styles (pc.red(pc.bold(text))). The isColorSupported boolean gives consumers an explicit flag to branch on, and because picocolors is a near drop-in replacement for Chalk, migration friction is low and documented directly in the README with a step-by-step “Replacing chalk” guide.
Used by 24 apps in this directory
Papra
Bookmarks Archiving
Self-hosted document archiving with email ingestion, OCR full-text search, and pluggable storage — store once, find anything.
Skrun
AI Agents
An open, self-hostable, multi-model agent runtime that deploys any agent skill as an API via POST /run — an open-source alternative to Claude Managed Agents and Google's Gemini Enterprise Agent Platform.
Spree Commerce
CRM · Ecommerce · Marketing
Open-source headless eCommerce platform with a REST API, TypeScript SDK, and Next.js storefront for B2B, cross-border, and marketplace commerce — no vendor lock-in, no platform fees.
Suna
AI Agents
Turn your company into a git repo — one config, one command center, a workforce of AI agents that runs the real work around the clock.
Teable
Databases · No Code Platforms
A no-code PostgreSQL database with spreadsheet UX, real-time collaboration, and native AI agents — built for teams that outgrow Airtable.
Webstudio
Design Tools · No Code Platforms
Open source visual development platform with complete CSS control, headless CMS integration, and full infrastructure ownership