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

use-colors

v0.1.0

Published

ANSI terminal styling.

Readme

use-colors

ANSI terminal styling library

npm version Downloads codecov

A lightweight ANSI styling library for Node.js that supports chained styles, template literals, RGB colors, and automatic terminal color detection.

preview

Installation

npm install use-colors

Usage

import colors from 'use-colors';

// basic colors
console.log(colors.red('Error message'));
console.log(colors.green('Success message'));
console.log(colors.yellow('Warning message'));
console.log(colors.blue('Information message'));

// style modifiers
console.log(colors.bold('Bold text'));
console.log(colors.underline('Underlined text'));
console.log(colors.italic('Italic text'));

// chained styles
console.log(colors.bold.red('Bold red text'));
console.log(colors.underline.blue('Underlined blue text'));
console.log(colors.inverse.yellow('Inverse yellow text'));

// bright colors
console.log(colors.redBright('Bright red'));
console.log(colors.greenBright('Bright green'));
console.log(colors.blueBright('Bright blue'));

// background colors
console.log(colors.bgRed.white('White text on red background'));
console.log(colors.bgGreen.black('Black text on green background'));
console.log(colors.bgBlue.white('White text on blue background'));

// nested styles
const user = colors.green('Alex');
console.log(colors.blue(`User ${user} logged in`));

// template literal
const name = 'Alex';
const score = 42;

console.log(colors.green`User ${name} logged in`);
console.log(colors.yellow`Score: ${score}`);
console.log(colors.red.bold`Error: ${'Connection failed'}`);

// custom colors

// RGB
console.log(colors.rgb(255, 0, 0)('Custom red'));
console.log(colors.rgb(0, 255, 0)('Custom green'));
console.log(colors.rgb(0, 128, 255)('Custom blue'));

// HEX
console.log(colors.hex('#ff5733')('HEX color example'));
console.log(colors.hex('#00ffcc')('Bright teal text'));
console.log(colors.hex('#f00')('Short hex red'));

// ANSI256
console.log(colors.ansi256(196)('Bright red'));
console.log(colors.ansi256(33)('Blue tone'));
console.log(colors.ansi256(82)('Green tone'));

// ANSI Utilities

// Strip ANSI codes
// Remove ANSI styling from text.
const text = colors.red('Hello');

console.log(colors.strip(text));
// Hello

// Detect ANSI codes
// Check if a string contains ANSI escape sequences.
const styled = colors.green('Hello');

console.log(colors.hasAnsi(styled));
// true

Configuration

You can control the color level manually.

import colors from 'use-colors';

colors.config({ level: 0 }); // disable colors

console.log(colors.red('No colors'));

Available levels:

| Level | Description | | ----- | ------------------ | | 0 | No colors | | 1 | ANSI16 colors | | 2 | ANSI256 colors | | 3 | Truecolor (24-bit) |

Custom Instances

Create an isolated color instance.

import { createColors } from 'use-colors';

const c = createColors({ level: 3 });

console.log(c.blue('Custom instance'));

This is useful when building tools or libraries that need their own color configuration.

Supported ANSI Styles

Modifiers

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

Colors

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • gray
  • redBright
  • greenBright
  • yellowBright
  • blueBright
  • magentaBright
  • cyanBright
  • whiteBright

Background Colors

  • bgBlack
  • bgRed
  • bgGreen
  • bgYellow
  • bgBlue
  • bgMagenta
  • bgCyan
  • bgWhite
  • bgBlackBright
  • bgRedBright
  • bgGreenBright
  • bgYellowBright
  • bgBlueBright
  • bgMagentaBright
  • bgCyanBright
  • bgWhiteBright

Automatic Color Detection

use-colors automatically detects the terminal's color capability and adjusts the output accordingly.

The library checks common environment variables and terminal settings to determine the supported color level.

Detection Order

Color support is determined using the following signals:

  • NO_COLOR → disables colors
  • FORCE_COLOR → forces colors
  • COLORTERM=truecolor or COLORTERM=24bit → enables truecolor
  • TERM=*-256color → enables ANSI256 colors
  • otherwise → falls back to basic ANSI16 colors

Color Levels

| Level | Description | | ----- | ------------------ | | 0 | No colors | | 1 | ANSI16 colors | | 2 | ANSI256 colors | | 3 | Truecolor (24-bit) |

Environment Examples

Disable colors:

NO_COLOR=1 node app.js

Force colors:

FORCE_COLOR=1 node app.js

Force truecolor terminals:

COLORTERM=truecolor node app.js