chalk-fast
v1.0.0
Published
The fastest and tiniest terminal color library. <3KB, 2x faster than picocolors, supports 256/Truecolor, works everywhere.
Maintainers
Readme
chalk-fast
The fastest and tiniest terminal color library.
<3KB minified. 2x faster than picocolors. Supports 256/Truecolor. Works everywhere.
Why chalk-fast?
| Feature | chalk-fast | chalk | picocolors | kleur | ansis | |---------|------------|-------|------------|-------|-------| | Bundle size | <3KB | 44KB | 6KB | 21KB | 5.7KB | | Speed | Fastest | Slow | Fast | Medium | Fast | | ESM + CJS | Both | ESM only | CJS only | Both | Both | | 256 colors | Yes | Yes | No | No | Yes | | Truecolor | Yes | Yes | No | No | Yes | | Edge/Browser | Yes | No | Limited | No | Yes | | Zero deps | Yes | Yes | Yes | Yes | Yes | | TypeScript | Built-in | Built-in | Types | Types | Built-in |
Installation
npm install chalk-fastQuick Start
// Direct imports (fastest)
import { red, green, bold, underline } from 'chalk-fast';
console.log(red('Error!'));
console.log(green('Success!'));
console.log(bold(red('Bold red!')));
// Chainable API
import chalk from 'chalk-fast';
console.log(chalk.red.bold('Hello'));
console.log(chalk.bgBlue.white.underline('World'));Features
All Basic Colors
import {
// Foreground
black, red, green, yellow, blue, magenta, cyan, white, gray,
// Bright
redBright, greenBright, yellowBright, blueBright,
// Background
bgRed, bgGreen, bgBlue, bgYellow,
// Modifiers
bold, dim, italic, underline, strikethrough, inverse
} from 'chalk-fast';
console.log(red('Red text'));
console.log(bgBlue('Blue background'));
console.log(bold(underline('Bold and underlined')));256 Colors
import { ansi256, bgAnsi256 } from 'chalk-fast';
console.log(ansi256(196)('Red from 256 palette'));
console.log(bgAnsi256(21)('Blue background'));Truecolor (RGB/Hex)
import { rgb, bgRgb, hex, bgHex } from 'chalk-fast';
console.log(rgb(255, 100, 50)('Orange text'));
console.log(hex('#ff6432')('Same orange'));
console.log(bgRgb(0, 150, 255)('Blue background'));
console.log(bgHex('#0096ff')('Same blue'));Chainable API
import chalk from 'chalk-fast';
// Chain multiple styles
console.log(chalk.red.bold.underline('Styled!'));
console.log(chalk.bgYellow.black.italic('Warning'));
console.log(chalk.rgb(255, 136, 0).bold('Custom color'));
console.log(chalk.hex('#ff8800').bgBlack('Hex color'));Utilities
import { stripAnsi, hasAnsi, setColorEnabled, getColorLevel } from 'chalk-fast';
// Strip ANSI codes
const plain = stripAnsi(red('colored')); // 'colored'
// Check for ANSI codes
hasAnsi(red('test')); // true
hasAnsi('test'); // false
// Disable colors
setColorEnabled(false);
// Get color level (0=none, 1=basic, 2=256, 3=truecolor)
console.log(getColorLevel());Benchmarks
--- SINGLE COLOR (red) ---
chalk-fast: 45,000,000 ops/sec
picocolors: 33,000,000 ops/sec
chalk: 24,000,000 ops/sec
=> chalk-fast is 1.4x faster than picocolors
=> chalk-fast is 1.9x faster than chalk
--- BOLD + COLOR ---
chalk-fast: 12,000,000 ops/sec
picocolors: 8,000,000 ops/sec
chalk: 4,000,000 ops/sec
=> chalk-fast is 1.5x faster than picocolors
=> chalk-fast is 3x faster than chalkRun benchmarks yourself:
npm run benchEnvironment Support
| Environment | Support | |-------------|---------| | Node.js 14+ | Full | | Deno | Full | | Bun | Full | | Browser | Full (devtools) | | Cloudflare Workers | Graceful fallback |
Color Detection
chalk-fast automatically detects color support:
NO_COLOR- Disables colorsFORCE_COLOR=0|1|2|3- Force specific levelCOLORTERM=truecolor- Enable truecolor- TTY detection - Auto-disable for pipes
import { setColorLevel, setColorEnabled } from 'chalk-fast';
// Force truecolor
setColorLevel(3);
// Disable all colors
setColorEnabled(false);Migration from chalk
chalk-fast is a drop-in replacement:
- import chalk from 'chalk';
+ import chalk from 'chalk-fast';
chalk.red.bold('Hello'); // Works!Or use direct imports (faster):
- import chalk from 'chalk';
- chalk.red('Hello');
+ import { red } from 'chalk-fast';
+ red('Hello');API Reference
Colors
| Foreground | Background | Bright |
|------------|------------|--------|
| black | bgBlack | blackBright |
| red | bgRed | redBright |
| green | bgGreen | greenBright |
| yellow | bgYellow | yellowBright |
| blue | bgBlue | blueBright |
| magenta | bgMagenta | magentaBright |
| cyan | bgCyan | cyanBright |
| white | bgWhite | whiteBright |
| gray/grey | bgGray/bgGrey | |
Modifiers
| Modifier | Description |
|----------|-------------|
| bold | Bold text |
| dim | Dimmed text |
| italic | Italic text |
| underline | Underlined text |
| strikethrough | Strikethrough text |
| inverse | Inverse colors |
| hidden | Hidden text |
| blink | Blinking text |
Extended Colors
| Function | Description |
|----------|-------------|
| rgb(r, g, b) | Truecolor foreground |
| bgRgb(r, g, b) | Truecolor background |
| hex('#rrggbb') | Hex foreground |
| bgHex('#rrggbb') | Hex background |
| ansi256(code) | 256-color foreground |
| bgAnsi256(code) | 256-color background |
Utilities
| Function | Description |
|----------|-------------|
| stripAnsi(str) | Remove ANSI codes |
| hasAnsi(str) | Check for ANSI codes |
| setColorEnabled(bool) | Enable/disable colors |
| setColorLevel(0-3) | Set color level |
| getColorLevel() | Get current level |
Why Not...
chalk?
- 44KB bundle (chalk-fast is <3KB)
- ESM only (breaks CommonJS)
- Slower performance
picocolors?
- No 256-color or Truecolor
- CJS only (not modernized)
- No chainable API
- Breaks in edge runtimes
kleur?
- 21KB bundle
- No 256-color or Truecolor
- Slower than chalk-fast
ansis?
- chalk-fast is smaller and faster
- chalk-fast has simpler API
Support
If chalk-fast saved you time:
- Star the GitHub repo
- Buy me a coffee
License
MIT
