npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@0xkahi/cli-dye

v1.1.0

Published

fast nodejs cli library for formatting terminal text

Downloads

303

Readme

@0xkahi/cli-dye

A lightweight, dependency-free ANSI styling library for terminal output.

Dye provides reusable modifier chains, named terminal colors, truecolor hexadecimal values, automatic color detection, and ANSI stripping while always returning primitive strings.

Installation

npm install @0xkahi/cli-dye
bun add @0xkahi/cli-dye

Usage

import { dye } from '@0xkahi/cli-dye';

console.log(dye.bold('Important'));
console.log(dye.italic().underline('Styled text'));
console.log(dye.colorize('Success', { fg: 'brightGreen' }));

Modifiers

Dye supports the following modifiers:

  • reset
  • bold
  • dim
  • italic
  • underline
  • inverse
  • hidden
  • strikethrough

Use a modifier directly:

const message = dye.bold('Hello');

Or call it without text to create a reusable builder:

const heading = dye.bold().underline();

console.log(heading('First heading'));
console.log(heading('Second heading'));

Modifiers can be chained in any order. Repeated modifiers are automatically deduplicated.

Colors

Use colorize() to apply an optional foreground, background, or both:

console.log(dye.colorize('Error', { fg: 'brightWhite', bg: 'red' }));
console.log(dye.colorize('Info', { fg: 'cyan' }));
console.log(dye.colorize('Highlighted', { bg: 'yellow' }));

Named colors

The following foreground and background colors are available:

| Regular | Bright | | --- | --- | | black | brightBlack | | red | brightRed | | green | brightGreen | | yellow | brightYellow | | blue | brightBlue | | magenta | brightMagenta | | cyan | brightCyan | | white | brightWhite | | gray | |

The exact appearance of named colors depends on the user's terminal palette. gray and brightBlack use the same ANSI color code.

Hexadecimal colors

Create truecolor values with dye.hex():

const pink = dye.hex('#ed7892');
const blue = dye.hex('#00f');

console.log(dye.colorize('Truecolor', {
  fg: pink,
  bg: blue,
}));

Both #RGB and #RRGGBB forms are accepted, case-insensitively. Hashless values, invalid digits, and alpha-bearing values throw a TypeError.

Hex colors are emitted directly using terminal 24-bit color sequences. Dye does not convert them to ANSI-256 or ANSI-16 palettes.

Color builders

Calling colorize() with only options creates a reusable builder. Color builders support all modifiers:

const warning = dye
  .colorize({ fg: 'brightYellow' })
  .bold()
  .underline();

console.log(warning('Check your configuration'));
console.log(warning('Connection is unstable'));

Rendered values are always primitive strings—not string-like wrapper objects.

Color output control

Dye detects terminal color support when the module is loaded. The resolved state is exposed through the read-only enabled property:

console.log(dye.enabled);

Override color output when needed:

dye.setEnabled(true);      // Always emit ANSI sequences
dye.setEnabled(false);     // Always return plain text
dye.setEnabled(undefined); // Restore automatic detection

When output is disabled, styling and color functions return the supplied text without adding ANSI sequences.

Dye respects common terminal signals, including TTY support, NO_COLOR, FORCE_COLOR, and TERM=dumb.

Strip ANSI sequences

Use strip() to remove ANSI CSI sequences from a string:

const message = dye.colorize({ fg: 'red' }).bold('Failure');

console.log(dye.strip(message)); // "Failure"

It works with modifier-only output too:

console.log(dye.strip(dye.bold('Hello'))); // "Hello"

strip() also removes supported CSI sequences generated by other ANSI libraries.

TypeScript

Dye includes TypeScript declarations and exports its public color and builder types:

import { dye } from '@0xkahi/cli-dye';
import type {
  DyeColor,
  ColorizeOptions,
  HexColor,
  StandardColor,
  DyeStyler,
} from '@0xkahi/cli-dye';

API

dye.<modifier>(text)

Applies a modifier immediately and returns a string.

dye.<modifier>()

Returns a reusable DyeStyler builder.

dye.colorize(text, options?)

Applies foreground and/or background colors immediately.

dye.colorize(options?)

Returns a reusable color and modifier builder.

dye.hex(value)

Validates and converts #RGB or #RRGGBB into an opaque HexColor.

dye.strip(text)

Removes ANSI CSI escape sequences.

dye.enabled

Reports whether styling output is currently enabled.

dye.setEnabled(value)

Sets a true or false override. Pass undefined to restore automatic detection.