Coloriz is a lightweight extension of Chalk that enhances the String
prototype to make styling terminal output more intuitive and expressive.
Instead of calling functions like chalk.red("text")
, you can now simply write "text".red
or "text".bld.bgYellowBright
.
❗ Note: Coloriz is not a replacement for Chalk — it uses Chalk under the hood. It's a syntactic enhancement, not a standalone coloring engine.
- Extends
String.prototype
with style and color properties - Fully powered by Chalk
- Supports:
- Legacy ANSI colors (16/32 colors)
- Bright and background variants
- Text styles (bold, italic, underline, etc.)
- Additional utility functions:
.rgb()
,.hex()
,.ansi256()
,.clearANSI
,.transform()
property.
- Zero configuration — import once and use everywhere
- Retrieve the chalk instance (useful for retrieving methods and properties. No install
chalk
) - Works in both JavaScript and TypeScript
npm install coloriz
⚠️ Requires Node.js v16+
require("coloriz");
console.log("Hello".green);
console.log("Info".bgCyan.italic);
console.log("Error".red.underline);
console.log("Debug".bgBlackBright.dim);
// Custom text colros
console.log("Custom Color".rgb(128, 0, 128));
console.log("Custom Hex".hex("#ff5733"));
console.log("Ansi256".ansi256(45));
// Custom background colors
console.log("Custom Background color".bgRgb(128, 0, 128));
console.log("Custom Background Hex".bgHex("#ff5733"));
console.log("Custom Background Ansi256".bgAnsi256(45));
// Clear ANSI codes (ex: for writing in file)
console.log("Clear ANSI".green.clearANSI);
// transform function
const condition = true;
console.log(
"Hello, World!".transform(s => condition ? s.green : s.red)
)
// Retrieve the chalk instance
const chalk = "".chalk;
import "coloriz";
console.log("Hello".green);
console.log("Info".bgCyan.italic);
console.log("Error".red.underline);
console.log("Debug".bgBlackBright.dim);
// Custom text colros
console.log("Custom Color".rgb(128, 0, 128));
console.log("Custom Hex".hex("#ff5733"));
console.log("Ansi256".ansi256(45));
// Custom background colors
console.log("Custom Background color".bgRgb(128, 0, 128));
console.log("Custom Background Hex".bgHex("#ff5733"));
console.log("Custom Background Ansi256".bgAnsi256(45));
// Clear ANSI codes (ex: for writing in file)
console.log("Clear ANSI".green.clearANSI);
// transform function
const condition = true;
console.log(
"Hello, World!".transform(s => condition ? s.green : s.red)
)
// Retrieve the chalk instance
const chalk = "".chalk;
Property | Description |
---|---|
reset |
Reset all styles |
bld |
Bold |
dim |
Dim |
italic |
Italic |
underline |
Underlined |
inverse |
Inverted foreground/background |
hidden |
Hidden |
strikethrough |
Strike-through |
Color 16/32 | Bright Variant |
---|---|
black |
|
red |
redBright |
green |
greenBright |
yellow |
yellowBright |
blue |
blueBright |
magenta |
magentaBright |
cyan |
cyanBright |
white |
whiteBright |
gray |
(bright black) |
Color 16/32 | Bright Variant |
---|---|
bgBlack |
bgBlackBright |
bgRed |
bgRedBright |
bgGreen |
bgGreenBright |
bgYellow |
bgYellowBright |
bgBlue |
bgBlueBright |
bgMagenta |
bgMagentaBright |
bgCyan |
bgCyanBright |
bgWhite |
bgWhiteBright |
You can also use functions to apply custom colors:
Function | Example usage |
---|---|
.rgb(r, g, b) |
"hello".rgb(255, 0, 128) |
.hex("#RRGGBB") |
"hi".hex("#ffcc00") |
.ansi256(n) |
"good bye".ansi256(45) |
Function | Example usage |
---|---|
.bgRgb(r, g, b) |
"hello".bgRgb(255, 0, 128) |
.bgHex("#RRGGBB") |
"hi".bgHex("#ffcc00") |
.bgAnsi256(n) |
"good bye".bgAnsi256(45) |
Name | Description |
---|---|
.clearANSI |
String property to strip ANSI codes |
.transform(fn) |
Apply a transformation function to the string |
.chalk |
Retrieve the underlying Chalk instance |
- You must import
"coloriz"
once in your entry point (e.g.,main.ts
,index.js
) - Designed for CLI tools, custom loggers, and developer UX
- Extensions are non-enumerable and do not pollute object iteration
If you need to access the underlying Chalk instance, you can do so by extracting it from .chalk
to a string.
const chalk = "".chalk;
This allows you to use all Chalk methods and properties directly, without needing to install Chalk separately.
You still are!
Coloriz is built entirely on top of Chalk. It doesn't replace it — it simplifies how you use it.
Chalk | Coloriz |
---|---|
chalk.red("Hi") |
"Hi".red |
chalk.bold.green("Ok") |
"Ok".green.bld |
chalk.hex("#f00")("Hi") |
"Hi".hex("#f00") |
--> Changelog
MIT © Oignontom8283