π Modern terminal string styling library built with TypeScript
A powerful, feature-rich alternative to chalk with enhanced capabilities, better performance, and modern development experience.
- π¨ Rich Color Support: 20+ built-in colors, RGB, HEX, HSL support
- π Advanced Effects: Gradient, rainbow, pulse, neon, shadow effects
- π οΈ Built-in Utilities: Tables, progress bars, boxes, spinners
- π TypeScript First: Full type safety with excellent IntelliSense
- π¦ Zero Dependencies: No external packages, minimal bundle size
- π³ Tree Shakeable: Import only what you need
- β‘ High Performance: Optimized for speed and efficiency
- π§ Easy Migration: Drop-in replacement for most chalk usage
- π Comprehensive Docs: Extensive documentation and examples
- π§ͺ Well Tested: 95%+ test coverage
npm install chalk-ts
yarn add chalk-ts
pnpm add chalk-ts
import chalkTs from "chalk-ts";
// Basic colors
console.log(chalkTs.red("Hello World!"));
console.log(chalkTs.green.bold("Success message"));
// Advanced colors
console.log(chalkTs.rgb(255, 136, 0)("Custom RGB color"));
console.log(chalkTs.hex("#ff8800")("HEX color"));
console.log(chalkTs.hsl(30, 100, 50)("HSL color"));
// Method chaining
console.log(chalkTs.bold.red.bgYellow("Styled text"));
// Advanced effects
import { gradient, rainbow, box } from "chalk-ts";
console.log(gradient("Gradient text!", "#ff0000", "#0000ff"));
console.log(rainbow("Rainbow colors!"));
console.log(box("Boxed text"));
import chalkTs from "chalk-ts";
console.log(chalkTs.bold("Bold text"));
console.log(chalkTs.italic("Italic text"));
console.log(chalkTs.underline("Underlined text"));
console.log(chalkTs.strikethrough("Strikethrough text"));
console.log(chalkTs.dim("Dimmed text"));
console.log(chalkTs.inverse("Inverted text"));
// Foreground colors
console.log(chalkTs.red("Red text"));
console.log(chalkTs.green("Green text"));
console.log(chalkTs.blue("Blue text"));
console.log(chalkTs.yellow("Yellow text"));
console.log(chalkTs.magenta("Magenta text"));
console.log(chalkTs.cyan("Cyan text"));
console.log(chalkTs.white("White text"));
console.log(chalkTs.gray("Gray text"));
// Background colors
console.log(chalkTs.bgRed("Red background"));
console.log(chalkTs.bgGreen("Green background"));
console.log(chalkTs.bgBlue("Blue background"));
// Bright colors
console.log(chalkTs.redBright("Bright red"));
console.log(chalkTs.greenBright("Bright green"));
console.log(chalkTs.blueBright("Bright blue"));
chalk-ts includes 20+ built-in colors beyond the standard ANSI colors:
console.log(chalkTs.orange("Orange text"));
console.log(chalkTs.purple("Purple text"));
console.log(chalkTs.pink("Pink text"));
console.log(chalkTs.brown("Brown text"));
console.log(chalkTs.lime("Lime text"));
console.log(chalkTs.indigo("Indigo text"));
console.log(chalkTs.violet("Violet text"));
console.log(chalkTs.turquoise("Turquoise text"));
console.log(chalkTs.gold("Gold text"));
console.log(chalkTs.silver("Silver text"));
// Foreground RGB
console.log(chalkTs.rgb(255, 136, 0)("Orange RGB"));
// Background RGB
console.log(chalkTs.bgRgb(255, 136, 0)("Orange background"));
// Foreground HEX
console.log(chalkTs.hex("#ff8800")("Orange HEX"));
// Background HEX
console.log(chalkTs.bgHex("#ff8800")("Orange background"));
// Foreground HSL
console.log(chalkTs.hsl(30, 100, 50)("Orange HSL"));
// Background HSL
console.log(chalkTs.bgHsl(30, 100, 50)("Orange background"));
Create beautiful gradient effects between two colors:
import { gradient } from "chalk-ts";
console.log(gradient("Gradient Text!", "#ff0000", "#0000ff"));
console.log(gradient("Fire Effect", "#ff4500", "#ffd700"));
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!", "green", "yellow"));
Create glowing neon-style text:
import { neon } from "chalk-ts";
console.log(neon("Neon text!", "cyan"));
console.log(neon("Glowing!", "magenta"));
Add shadow to text:
import { shadow } from "chalk-ts";
console.log(shadow("Text with shadow", "cyan", "gray"));
Create beautiful boxes around text:
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: 'single', 'double', 'rounded', 'thick'
console.log(box("Rounded", { style: "rounded" }));
Create progress indicators:
import { progressBar } from "chalk-ts";
console.log(progressBar(75, 100)); // 75% progress
console.log(
progressBar(50, 100, {
width: 30,
complete: "β ",
incomplete: "β‘",
color: "green",
})
);
Create formatted tables:
import { table } from "chalk-ts";
const data = [
["John", "25", "Engineer"],
["Jane", "30", "Designer"],
["Bob", "35", "Manager"],
];
const headers = ["Name", "Age", "Role"];
console.log(
table(data, {
headers,
headerColor: "cyan",
borderColor: "gray",
})
);
Animated loading indicators:
import { spinner } from "chalk-ts";
// Display different frames
for (let i = 0; i < 10; i++) {
console.log(spinner(i, "cyan"));
}
chalk-ts supports full method chaining for complex styling:
// Combine multiple styles
console.log(chalkTs.bold.red.bgYellow("Complex styling"));
// Chain with custom colors
console.log(chalkTs.bold.rgb(255, 100, 0).bgHex("#000000")("Custom chain"));
// Multiple text effects
console.log(chalkTs.bold.italic.underline.red("All effects"));
Remove styling from text:
const styled = chalkTs.red.bold("Styled text");
const plain = chalkTs.strip(styled);
console.log(plain); // 'Styled text'
Get the actual text length without ANSI codes:
const styled = chalkTs.red.bold("Hello");
console.log(styled.length); // Includes ANSI codes
console.log(chalkTs.length(styled)); // 5 (actual text length)
Support for template strings:
const name = "World";
console.log(chalkTs.template`Hello ${chalkTs.red(name)}!`);
Control color output:
import { ChalkTS } from "chalk-ts";
// Force disable colors
const noColors = new ChalkTS(false);
console.log(noColors.red("Plain text"));
// Force enable colors
const withColors = new ChalkTS(true);
console.log(withColors.red("Red text"));
chalk-ts is designed for performance while providing more features:
Library | Bundle Size | Features | Performance | TypeScript |
---|---|---|---|---|
chalk-ts | ~15KB | βββββ | βββββ | βββββ |
Chalk | ~17KB | βββ | ββββ | ββββ |
Colorette | ~8KB | ββ | βββββ | βββ |
- π¨ More Colors: 20+ built-in colors vs 8 in most libraries
- π More Effects: Gradient, rainbow, pulse, neon, and more
- π οΈ More Utilities: Tables, progress bars, boxes, spinners
- π Better Types: Full TypeScript support with strict typing
- π¦ Modern Build: ES modules, tree-shaking, zero dependencies
- π§ͺ Well Tested: 95%+ test coverage
- π Great Docs: Comprehensive documentation
- π§ 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)
import chalkTs from "chalk-ts";
console.log(chalkTs.red.bold("Hello"));
Most chalk code will work without changes, but you'll get additional features and 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
bold
,dim
,italic
,underline
,blink
,inverse
,hidden
,strikethrough
rgb(r, g, b)
,bgRgb(r, g, b)
hex(color)
,bgHex(color)
hsl(h, s, l)
,bgHsl(h, s, l)
strip(text)
- Remove ANSI codeslength(text)
- Get text length without ANSI codestemplate
- Template literal support
gradient(text, startColor, endColor)
rainbow(text)
pulse(text, color?)
zebra(text, color1?, color2?)
neon(text, color?)
shadow(text, color?, shadowColor?)
box(text, options?)
progressBar(progress, total, options?)
spinner(frame, color?)
table(data, options?)
Check out the examples directory for more comprehensive usage examples:
- Basic Usage - Complete feature demonstration
- Performance Benchmark - Performance comparison
Run the test suite:
npm test
Run tests with coverage:
npm run test:coverage
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the 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
- π§ Email: dev.reactbd@gmail.com
- π Issues: GitHub Issues
- π¬ Discussions: GitHub Discussions
Made with β€οΈ by Noor Mohammad
β Star this repo if you find it useful!