mini-chalk
v0.1.2
Published
A lightweight alternative to Chalk with no dependencies.
Maintainers
Readme
mini-chalk
A tiny, dependency-free alternative to chalk for styling terminal output with ANSI colors.
Features
- Basic colors: red, green, blue, yellow, cyan, magenta, black, white, gray/grey
- Background colors: via
.bgColorshortcuts (bgRed,bgGreen, or.bg.red) - Text modifiers:
bold,dim,italic,underline,inverse,hidden,strikethrough - RGB & Hex colors:
.rgb(r,g,b),.bgRgb(r,g,b),.hex("#ff8800"),.bgHex("#0088ff") - Chained styles: combine multiple colors and modifiers (
chalk.red.bold.underline(...)) - Template tag support:
{style text}syntax inside template literals (chalk.templateor chalk`...`) - Enable/disable colors dynamically with
chalk.enabled - Auto color level detection: detects 16, 256, or truecolor support
Installation
npm install mini-chalkBasic Usage
import chalk from "mini-chalk";
// Basic colors
console.log(chalk.red("Red text"));
console.log(chalk.green("Green text"));
// Background colors
console.log(chalk.bg.red("Red background"));
console.log(chalk.bgGreen.white("White on green"));
// Modifiers
console.log(chalk.bold("Bold text"));
console.log(chalk.underline("Underlined text"));
// RGB / Hex
console.log(chalk.rgb(123, 45, 67)("RGB Text"));
console.log(chalk.hex("#ff8800")("Hex Text"));
// Chaining
console.log(chalk.red.bold.underline("Red Bold Underline"));
console.log(chalk.yellow.bgMagenta.italic("Yellow on Magenta Italic"));
console.log(chalk.blue.bgYellow.inverse.underline("Blue on Yellow Inverse Underline"));
// Multiple arguments
console.log(chalk.green("Multiple", "arguments", "test"));
// Enable / Disable
chalk.enabled = false;
console.log(chalk.red("No color"));
chalk.enabled = true;Template Tag
Supports {style text} syntax:
console.log(chalk.template`This is a {red.bold red bold} and {#00ff00 green hex} text`);
console.log(chalk`Nested {blue.bgYellow text} example`);
console.log(chalk.template`RGB example: {rgb(255,0,0) red rgb}`);stylecan be a basic color, dot-chained modifiers, hex, or rgb.- Nested
{}is supported flatly (not recursive for now).
API Reference
Chalk Function:
chalk(text, ...args)Modifiers:
.bold,.dim,.italic,.underline,.inverse,.hidden,.strikethroughForeground Colors:
.red,.green,.blue,.yellow,.cyan,.magenta,.white,.black,.gray/.greyBackground Colors:
.bgRed,.bgGreen,.bgBlue, etc., or.bg.red,.bg.green, etc.RGB/Hex:
.rgb(r,g,b).bgRgb(r,g,b).hex("#rrggbb").bgHex("#rrggbb")
Template:
chalk.template`...`Enable / Disable:
chalk.enabled = true | falseColor Level:
chalk.levelSupportsColor:
chalk.supportsColor
