cli-color-lite
v1.0.0
Published
Ultra-tiny (<1 KB), zero-dependency ANSI terminal colors and text styles with chained formatting and NO_COLOR support.
Maintainers
Readme
🎨 cli-color-lite
Ultra-lightweight (< 1 KB), zero-dependency ANSI terminal text colorizer and formatter with chained syntax and
NO_COLORcompliance.
💡 Why cli-color-lite?
Most CLI tools and backend services pull in packages like chalk or colorette. While great, they often include nested sub-dependencies, complex color level detection, or modern ESM compatibility issues in hybrid environments.
cli-color-lite provides:
- ⚡ Zero Dependencies — Less than 1 KB minified, pure native TypeScript.
- 🔗 Fluent Chaining — Combine colors and modifiers effortlessly:
colors.bold.red.bgYellow('ALERT'). - 🧼 ANSI Code Stripping — Strip codes with
colors.strip()when writing to raw log files. - 🎛️ NO_COLOR Standard Compliant — Automatically honors
NO_COLOR,FORCE_COLOR, and non-TTY stdout streams. - 📦 Dual ESM & CommonJS — Works everywhere: Node.js, Bun, Deno, and CI/CD pipelines.
📥 Installation
# npm
npm install cli-color-lite
# pnpm
pnpm add cli-color-lite
# yarn
yarn add cli-color-lite
# bun
bun add cli-color-lite🚀 Usage & Real-World Examples
1. Basic Colors & Formatting
import colors from 'cli-color-lite';
console.log(colors.green('✔ Build completed successfully!'));
console.log(colors.red('✖ Failed to connect to database.'));
console.log(colors.yellow('⚠ High memory usage detected.'));
console.log(colors.cyan('ℹ Server listening on port 3000.'));2. Chained Styles & Backgrounds
import colors from 'cli-color-lite';
// Bold and Bright Colors:
console.log(colors.bold.greenBright('DONE'));
// Background Colors with Text Formatting:
console.log(colors.bold.white.bgRed(' CRITICAL ERROR '));
// Underline and Dim styles:
console.log(colors.dim.italic('Config loaded from /etc/app.json'));
console.log(colors.underline.blue('https://github.com/Piratha97'));3. CLI Logger with ANSI Stripping
When outputting to terminal and saving to a log file simultaneously:
import fs from 'node:fs';
import colors from 'cli-color-lite';
function log(level: 'INFO' | 'WARN' | 'ERROR', message: string) {
const badgeMap = {
INFO: colors.bgBlue.bold.white(' INFO '),
WARN: colors.bgYellow.bold.black(' WARN '),
ERROR: colors.bgRed.bold.white(' ERROR '),
};
const terminalOutput = `${badgeMap[level]} ${message}`;
console.log(terminalOutput);
// Write plain text without ANSI escape sequences to file:
fs.appendFileSync('server.log', colors.strip(terminalOutput) + '\n');
}
log('INFO', 'Database migration applied.');
log('ERROR', 'Connection timed out after 5000ms.');📖 API Reference & Supported Styles
Foreground Colors
black, red, green, yellow, blue, magenta, cyan, white, gray
Bright Foreground Colors
redBright, greenBright, yellowBright, blueBright, magentaBright, cyanBright, whiteBright
Background Colors
bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite
Modifiers
bold, dim, italic, underline, inverse, hidden, strikethrough, reset
Methods & Properties:
colors.strip(str): Removes all ANSI escape codes from a string.colors.enabled: Boolean flag to enable or disable color output.
💖 Support the Project
If cli-color-lite keeps your CLI output colorful and lightweight, please support continued development:
👉 Sponsor @Piratha97 on GitHub Sponsors
📄 License
MIT © 2026 Pirapaakaran Pirathapan
