Socket
Book a DemoInstallSign in
Socket

coloriz

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

coloriz

String Extensions for Styling Text with Chalk

latest
Source
npmnpm
Version
1.2.1
Version published
Maintainers
1
Created
Source

Coloriz

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.

Illustration

✨ Features

  • 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

🚀 Installation

npm install coloriz

⚠️ Requires Node.js v16+

📦 Usage

JavaScript

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;

TypeScript ❤️

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;

🎨 Available Properties

🎯 Text Styles

PropertyDescription
resetReset all styles
bldBold
dimDim
italicItalic
underlineUnderlined
inverseInverted foreground/background
hiddenHidden
strikethroughStrike-through

🎨 Text Colors

Color 16/32Bright Variant
black
redredBright
greengreenBright
yellowyellowBright
blueblueBright
magentamagentaBright
cyancyanBright
whitewhiteBright
gray(bright black)

🎨 Background Colors

Color 16/32Bright Variant
bgBlackbgBlackBright
bgRedbgRedBright
bgGreenbgGreenBright
bgYellowbgYellowBright
bgBluebgBlueBright
bgMagentabgMagentaBright
bgCyanbgCyanBright
bgWhitebgWhiteBright

🎨 Custom Color Functions

You can also use functions to apply custom colors:

Text colors

FunctionExample usage
.rgb(r, g, b)"hello".rgb(255, 0, 128)
.hex("#RRGGBB")"hi".hex("#ffcc00")
.ansi256(n)"good bye".ansi256(45)

Background colors

FunctionExample usage
.bgRgb(r, g, b)"hello".bgRgb(255, 0, 128)
.bgHex("#RRGGBB")"hi".bgHex("#ffcc00")
.bgAnsi256(n)"good bye".bgAnsi256(45)

🧹 Utility

NameDescription
.clearANSIString property to strip ANSI codes
.transform(fn)Apply a transformation function to the string
.chalkRetrieve the underlying Chalk instance

🧠 Notes

  • 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

🛠️ Advanced Usag

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.

🦺 Why Not Just Use Chalk?

You still are!
Coloriz is built entirely on top of Chalk. It doesn't replace it — it simplifies how you use it.

ChalkColoriz
chalk.red("Hi")"Hi".red
chalk.bold.green("Ok")"Ok".green.bld
chalk.hex("#f00")("Hi")"Hi".hex("#f00")

⚡ Github

--> GitHub repository

📌 ChangeLog

--> Changelog

📄 License

MIT © Oignontom8283

Keywords

chalk

FAQs

Package last updated on 03 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts