๐ Modern terminal string styling library built with TypeScript
A powerful, feature-rich alternative to chalk with enhanced capabilities, TrueColor support, visual effects, and modern development experience.
- ๐จ Rich Color Support: 20+ built-in colors, TrueColor (RGB/HEX/HSL)
- ๐ญ Advanced Effects: Gradients, rainbow, pulse, neon, shadow, zebra stripes
- ๐ ๏ธ Built-in Utilities: Tables, progress bars, boxes, spinners
- ๐ฏ Semantic Theming: Create reusable theme configurations
- ๐ TypeScript First: Full type safety with excellent IntelliSense
- ๐ฆ Zero Dependencies: No external packages, minimal bundle size (~15KB)
- ๐ณ Tree Shakeable: Import only what you need
- โก High Performance: Optimized for speed and efficiency
- ๐ง Easy Migration: Drop-in replacement for most chalk usage
- ๐ Web Demo: Interactive browser-based demo with live examples
- ๐ Comprehensive Docs: Extensive documentation and examples
- ๐งช Well Tested: 98%+ test coverage with 98 passing tests
Try out all features in your browser: Live Web Demo
The demo includes:
- โ All 20+ colors and backgrounds
- โ TrueColor (RGB/HEX/HSL) examples
- โ Visual effects (gradients, rainbow, neon, etc.)
- โ Utilities (boxes, tables, progress bars)
- โ Code snippets with copy functionality
- โ Live terminal output rendering
npm install chalk-tsyarn add chalk-tspnpm add chalk-tsbun add chalk-tsimport chalk from "chalk-ts";
// Basic colors
console.log(chalk.red("Hello World!"));
console.log(chalk.green.bold("Success message"));
// TrueColor support
console.log(chalk.rgb(255, 136, 0)("Custom RGB color"));
console.log(chalk.hex("#ff8800")("HEX color"));
console.log(chalk.hsl(30, 100, 50)("HSL color"));
// Method chaining
console.log(chalk.bold.red.bgYellow("Styled text"));
// Advanced effects
import { gradient, rainbow, box, createTheme } from "chalk-ts";
console.log(gradient("Gradient text!", ["#ff0000", "#00ff00", "#0000ff"]));
console.log(rainbow("Rainbow colors!"));
console.log(box("Boxed text"));
// Semantic theming
const theme = createTheme({
info: chalk.blue.bold,
success: chalk.green,
error: chalk.red.bold,
});
console.log(theme.info("Info message"));
console.log(theme.success("Success!"));
console.log(theme.error("Error occurred"));import chalk from "chalk-ts";
console.log(chalk.bold("Bold text"));
console.log(chalk.italic("Italic text"));
console.log(chalk.underline("Underlined text"));
console.log(chalk.strikethrough("Strikethrough text"));
console.log(chalk.dim("Dimmed text"));
console.log(chalk.inverse("Inverted text"));// Foreground colors
console.log(chalk.black("Black text"));
console.log(chalk.red("Red text"));
console.log(chalk.green("Green text"));
console.log(chalk.yellow("Yellow text"));
console.log(chalk.blue("Blue text"));
console.log(chalk.magenta("Magenta text"));
console.log(chalk.cyan("Cyan text"));
console.log(chalk.white("White text"));
console.log(chalk.gray("Gray text"));
// Background colors
console.log(chalk.bgRed("Red background"));
console.log(chalk.bgGreen("Green background"));
console.log(chalk.bgBlue("Blue background"));
console.log(chalk.bgYellow("Yellow background"));
// Bright colors
console.log(chalk.redBright("Bright red"));
console.log(chalk.greenBright("Bright green"));
console.log(chalk.blueBright("Bright blue"));
console.log(chalk.yellowBright("Bright yellow"));chalk-ts includes 20+ built-in colors beyond the standard ANSI colors:
console.log(chalk.orange("Orange text"));
console.log(chalk.purple("Purple text"));
console.log(chalk.pink("Pink text"));
console.log(chalk.brown("Brown text"));
console.log(chalk.lime("Lime text"));
console.log(chalk.indigo("Indigo text"));
console.log(chalk.violet("Violet text"));
console.log(chalk.turquoise("Turquoise text"));
console.log(chalk.gold("Gold text"));
console.log(chalk.silver("Silver text"));
console.log(chalk.crimson("Crimson text"));
console.log(chalk.navy("Navy text"));
console.log(chalk.teal("Teal text"));
console.log(chalk.olive("Olive text"));
console.log(chalk.maroon("Maroon text"));// Foreground RGB
console.log(chalk.rgb(255, 136, 0)("Custom Orange"));
console.log(chalk.rgb(100, 200, 255)("Sky Blue"));
// Background RGB
console.log(chalk.bgRgb(255, 136, 0)("Orange background"));
console.log(chalk.bgRgb(100, 200, 255)("Sky blue background"));// Foreground HEX
console.log(chalk.hex("#ff8800")("Orange HEX"));
console.log(chalk.hex("#64c8ff")("Sky Blue HEX"));
// Background HEX
console.log(chalk.bgHex("#ff8800")("Orange background"));
console.log(chalk.bgHex("#64c8ff")("Sky blue background"));// Foreground HSL (Hue, Saturation, Lightness)
console.log(chalk.hsl(30, 100, 50)("Orange HSL"));
console.log(chalk.hsl(200, 100, 70)("Sky Blue HSL"));
// Background HSL
console.log(chalk.bgHsl(30, 100, 50)("Orange background"));
console.log(chalk.bgHsl(200, 100, 70)("Sky blue background"));Create beautiful gradient effects with multiple color stops:
import { gradient } from "chalk-ts";
// Two-color gradient
console.log(gradient("Gradient Text!", ["#ff0000", "#0000ff"]));
// Multi-color gradient
console.log(gradient("Rainbow Gradient!", ["#ff0000", "#00ff00", "#0000ff"]));
// Fire effect
console.log(gradient("Fire Effect", ["#ff4500", "#ffd700"]));
// Ocean effect
console.log(gradient("Ocean Waves", ["#006994", "#00d4ff", "#7fffd4"]));Apply rainbow colors to text:
import { rainbow } from "chalk-ts";
console.log(rainbow("Rainbow Colors!"));
console.log(rainbow("๐ Colorful text ๐"));Create pulsing effects with alternating bright and dim:
import { pulse } from "chalk-ts";
console.log(pulse("Pulsing text", "red"));
console.log(pulse("Attention!", "yellow"));Alternate between two colors:
import { zebra } from "chalk-ts";
console.log(zebra("Zebra effect", "red", "blue"));
console.log(zebra("Alternating colors!", "green", "yellow"));Create glowing neon-style text:
import { neon } from "chalk-ts";
console.log(neon("Neon text!", "cyan"));
console.log(neon("Glowing!", "magenta"));
console.log(neon("Electric!", "blue"));Add shadow to text:
import { shadow } from "chalk-ts";
console.log(shadow("Text with shadow", "cyan", "gray"));
console.log(shadow("Depth effect", "yellow", "black"));Create beautiful boxes around text with various styles:
import { box } from "chalk-ts";
// Simple box
console.log(box("Hello World!"));
// Customized box
console.log(
box("Fancy Box", {
padding: 2,
color: "cyan",
style: "double",
}),
);
// Different styles
console.log(box("Single Border", { style: "single" }));
console.log(box("Double Border", { style: "double" }));
console.log(box("Rounded Corners", { style: "rounded" }));
console.log(box("Thick Border", { style: "thick" }));
// Multi-line content
console.log(
box("Line 1\nLine 2\nLine 3", {
padding: 1,
color: "green",
}),
);Create customizable progress indicators:
import { progressBar } from "chalk-ts";
// Simple progress bar
console.log(progressBar(75, 100)); // 75% progress
// Customized progress bar
console.log(
progressBar(50, 100, {
width: 30,
complete: "โ ",
incomplete: "โก",
color: "green",
}),
);
// Different styles
console.log(
progressBar(80, 100, {
complete: "โ",
incomplete: "โ",
color: "cyan",
}),
);Create formatted tables with headers and custom styling:
import { table } from "chalk-ts";
const data = [
["John Doe", "28", "Developer"],
["Jane Smith", "34", "Designer"],
["Bob Johnson", "45", "Manager"],
];
const headers = ["Name", "Age", "Role"];
// Table with headers
console.log(
table(data, {
headers,
headerColor: "cyan",
borderColor: "gray",
}),
);
// Table without headers
console.log(table(data));
// Custom styling
console.log(
table(data, {
headers,
headerColor: "yellow",
borderColor: "blue",
}),
);Animated loading indicators:
import { spinner } from "chalk-ts";
// Display different frames
for (let i = 0; i < 10; i++) {
console.clear();
console.log(spinner(i, "cyan") + " Loading...");
await new Promise((resolve) => setTimeout(resolve, 100));
}
// Different colors
console.log(spinner(0, "green") + " Processing...");
console.log(spinner(1, "yellow") + " Working...");
console.log(spinner(2, "magenta") + " Please wait...");Create reusable theme configurations for consistent styling:
import { createTheme } from "chalk-ts";
import chalk from "chalk-ts";
// Define your theme
const theme = createTheme({
info: chalk.blue.bold,
success: chalk.green,
warning: chalk.yellow.bold,
error: chalk.red.bold.bgWhite,
debug: chalk.gray.dim,
});
// Use the theme
console.log(theme.info("Application started"));
console.log(theme.success("โ Task completed successfully"));
console.log(theme.warning("โ Warning: Low memory"));
console.log(theme.error("โ Error: Connection failed"));
console.log(theme.debug("Debug: Variable value = 42"));
// Themes can use any chalk styling
const fancyTheme = createTheme({
header: chalk.bold.underline.cyan,
subheader: chalk.italic.blue,
highlight: chalk.bgYellow.black.bold,
muted: chalk.dim.gray,
});
console.log(fancyTheme.header("Main Title"));
console.log(fancyTheme.subheader("Subtitle"));
console.log(fancyTheme.highlight("Important!"));
console.log(fancyTheme.muted("Less important"));chalk-ts supports full method chaining for complex styling:
// Combine multiple styles
console.log(chalk.bold.red.bgYellow("Complex styling"));
// Chain with TrueColor
console.log(chalk.bold.rgb(255, 100, 0).bgHex("#000000")("Custom chain"));
// Multiple text effects
console.log(chalk.bold.italic.underline.red("All effects"));
// Nested styling
console.log(
chalk.blue("Blue text with " + chalk.red.bold("red bold") + " inside"),
);Remove styling from text:
const styled = chalk.red.bold("Styled text");
const plain = chalk.strip(styled);
console.log(plain); // 'Styled text'Get the actual text length without ANSI codes:
const styled = chalk.red.bold("Hello");
console.log(styled.length); // Includes ANSI codes (e.g., 23)
console.log(chalk.length(styled)); // 5 (actual text length)Support for template strings with embedded styling:
const name = "World";
const greeting = chalk.template`Hello {red.bold ${name}}!`;
console.log(greeting);
// More complex templates
const status = "success";
const message = chalk.template`Status: {green.bold ${status}} - All systems operational`;
console.log(message);Control color output levels for different environments:
import { ChalkTS } from "chalk-ts";
// Level 0: No colors
const noColors = new ChalkTS({ level: 0 });
console.log(noColors.red("Plain text"));
// Level 1: Basic 16 colors
const basicColors = new ChalkTS({ level: 1 });
console.log(basicColors.red("Basic red"));
// Level 2: 256 colors
const extendedColors = new ChalkTS({ level: 2 });
console.log(extendedColors.rgb(255, 100, 0)("Downsampled to 256"));
// Level 3: TrueColor (16 million colors)
const trueColor = new ChalkTS({ level: 3 });
console.log(trueColor.rgb(255, 100, 0)("Full RGB"));
// Auto-detect (default)
import chalk from "chalk-ts";
console.log(chalk.red("Auto-detected color level"));chalk-ts is designed for performance while providing more features:
| Library | Bundle Size | Colors | Effects | Utilities | TypeScript | Tests |
|---|---|---|---|---|---|---|
| chalk-ts | ~15KB | 20+ | 6+ | 4+ | โญโญโญโญโญ | 98 |
| Chalk | ~17KB | 8 | 0 | 0 | โญโญโญโญ | - |
| Colorette | ~8KB | 8 | 0 | 0 | โญโญโญ | - |
- ๐จ More Colors: 20+ built-in colors + TrueColor support
- ๐ญ Visual Effects: Gradients, rainbow, pulse, neon, shadow, zebra
- ๐ ๏ธ Built-in Utilities: Tables, progress bars, boxes, spinners
- ๐ฏ Theming: Semantic theme system for consistent styling
- ๐ Better Types: Full TypeScript support with strict typing
- ๐ฆ Modern Build: ES modules, tree-shaking, zero dependencies
- ๐งช Well Tested: 98%+ coverage with 98 passing tests
- ๐ Great Docs: Comprehensive documentation + interactive demo
- ๐ง Easy Migration: Drop-in replacement for chalk
chalk-ts is designed as a drop-in replacement for chalk:
// Before (chalk)
import chalk from "chalk";
console.log(chalk.red.bold("Hello"));
// After (chalk-ts) - same API!
import chalk from "chalk-ts";
console.log(chalk.red.bold("Hello"));
// Plus new features!
import { gradient, createTheme } from "chalk-ts";
console.log(gradient("Gradient!", ["#ff0000", "#0000ff"]));Most chalk code will work without changes, but you'll get:
- โ 20+ additional colors
- โ TrueColor (RGB/HEX/HSL) support
- โ Visual effects (gradients, rainbow, etc.)
- โ Built-in utilities (tables, boxes, etc.)
- โ Semantic theming
- โ Better TypeScript support
black, red, green, yellow, blue, magenta, cyan, white, gray
redBright, greenBright, yellowBright, blueBright, magentaBright, cyanBright, whiteBright
bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, bgGray
bgRedBright, bgGreenBright, bgYellowBright, bgBlueBright, bgMagentaBright, bgCyanBright, bgWhiteBright
orange, purple, pink, brown, lime, indigo, violet, turquoise, gold, silver, crimson, navy, teal, olive, maroon
bold, dim, italic, underline, blink, inverse, hidden, strikethrough
rgb(r, g, b)- Foreground RGB colorbgRgb(r, g, b)- Background RGB colorhex(color)- Foreground HEX colorbgHex(color)- Background HEX colorhsl(h, s, l)- Foreground HSL colorbgHsl(h, s, l)- Background HSL color
strip(text)- Remove ANSI codes from textlength(text)- Get text length without ANSI codestemplate- Template literal support
gradient(text, colors[])- Multi-color gradientrainbow(text)- Rainbow effectpulse(text, color?)- Pulsing effectzebra(text, color1?, color2?)- Alternating colorsneon(text, color?)- Neon glow effectshadow(text, color?, shadowColor?)- Shadow effect
box(text, options?)- Create bordered boxprogressBar(current, total, options?)- Progress indicatorspinner(frame, color?)- Loading spinnertable(data, options?)- Formatted table
createTheme(config)- Create semantic theme
import chalk from "chalk-ts";
import { box, progressBar, createTheme } from "chalk-ts";
const theme = createTheme({
info: chalk.blue.bold,
success: chalk.green.bold,
error: chalk.red.bold,
});
console.log(
box("My CLI App v1.0.0", {
padding: 1,
color: "cyan",
style: "rounded",
}),
);
console.log(theme.info("Starting installation..."));
console.log(progressBar(50, 100, { color: "cyan" }));
console.log(theme.success("โ Installation complete!"));import chalk from "chalk-ts";
import { createTheme } from "chalk-ts";
const logTheme = createTheme({
debug: chalk.gray.dim,
info: chalk.blue,
warn: chalk.yellow.bold,
error: chalk.red.bold.bgWhite,
success: chalk.green.bold,
});
class Logger {
debug(msg: string) {
console.log(logTheme.debug(`[DEBUG] ${msg}`));
}
info(msg: string) {
console.log(logTheme.info(`[INFO] ${msg}`));
}
warn(msg: string) {
console.log(logTheme.warn(`[WARN] ${msg}`));
}
error(msg: string) {
console.log(logTheme.error(`[ERROR] ${msg}`));
}
success(msg: string) {
console.log(logTheme.success(`[SUCCESS] ${msg}`));
}
}
const logger = new Logger();
logger.info("Application started");
logger.success("Connected to database");
logger.warn("High memory usage detected");
logger.error("Failed to load configuration");import { table, progressBar, gradient } from "chalk-ts";
// Sales report
const salesData = [
["Product A", "$1,234", "โ 15%"],
["Product B", "$2,456", "โ 23%"],
["Product C", "$987", "โ 5%"],
];
console.log(gradient("SALES REPORT", ["#00d4ff", "#7fffd4"]));
console.log(
table(salesData, {
headers: ["Product", "Revenue", "Change"],
headerColor: "cyan",
borderColor: "gray",
}),
);
console.log("\nQuarterly Progress:");
console.log(
progressBar(75, 100, {
width: 40,
color: "green",
complete: "โ",
incomplete: "โ",
}),
);Check out more examples:
- Complete Demo - All features showcase
- Web Demo - Interactive browser demo
Run the test suite:
npm testRun tests with coverage:
npm run test:coverageRun demo:
npm run demoContributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
MIT License - see the LICENSE file for details.
Inspired by:
- chalk - The original terminal styling library
- Thanks to all contributors and the open source community
If you have any questions or need help, please:
- ๐ Homepage: reactbd.com/npm-packages/chalk-ts-typescript
- ๐ฎ Playground: chalk.reactbd.com
- ๐ฆ NPM: npmjs.com/package/chalk-ts
- ๐ป GitHub: github.com/noorjsdivs/chalk-ts
- ๐ Issues: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
- ๐ง Email: dev.reactbd@gmail.com
- ๐ฅ YouTube: @reactjsBD
If this library helped you, please give it a โญ๏ธ on GitHub!
You can also support the development of this project by buying me a coffee:
Made with โค๏ธ by Noor Mohammad
โญ Star this repo if you find it useful!
