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 🙏

© 2025 – Pkg Stats / Ryan Hefner

oli-colors

v4.6.2

Published

lets you use terminal colors esser

Readme

Features

  • Chainable API: Combine multiple styles and colors (e.g., colors.bold.red.bgYellow('text')).

  • Foreground Colors: A wide range of standard and bright foreground colors.

  • Background Colors: A wide range of standard and bright background colors.

  • Text Effects: Apply effects like bold, dim, italic, underline, strikethrough, and more.

  • Automatic Reset: Each styled string automatically resets the console style at its end.

Usage

1. Import the Utility

First, you need to import the oli-colors utility into your Node.js script:

const colors = require('oli-colors'); // Adjust path if your file is named differently

2. Basic Usage

To apply a single color or effect, simply call the corresponding method on the colors object and pass your text as an argument:

console.log(colors.red('This text is red.'));
console.log(colors.green('Success message!'));
console.log(colors.bold('This text is bold.'));
console.log(colors.underline('This text is underlined.'));

3. Chainable Usage

The real power of oli-colors comes from its chainable API. You can chain multiple color and effect methods together to create complex styles. The order of chaining generally doesn't matter for colors, but effects might combine in specific ways.

console.log(colors.bold.yellow('Warning: Something important happened!'));
console.log(colors.italic.cyan('This is an italicized cyan message.'));
console.log(colors.bgBlue.white.bold('White text on a blue background, and bold!'));
console.log(colors.red.strikethrough('This text is red and crossed out.'));
console.log(colors.brightMagenta.underline('A bright magenta, underlined string.'));

4. Available Styles and Colors

Here's a comprehensive list of the available methods:

Text Effects

  • colors.reset('text')

  • colors.bold('text')

  • colors.dim('text')

  • colors.italic('text')

  • colors.underline('text')

  • colors.blink('text')

  • colors.inverse('text') (swaps foreground and background colors)

  • colors.hidden('text') (makes text invisible)

  • colors.strikethrough('text')

Foreground Colors

  • colors.black('text')

  • colors.red('text')

  • colors.green('text')

  • colors.yellow('text')

  • colors.blue('text')

  • colors.magenta('text')

  • colors.cyan('text')

  • colors.white('text')

  • colors.brightBlack('text') (often appears as gray)

  • colors.brightRed('text')

  • colors.brightGreen('text')

  • colors.brightYellow('text')

  • colors.brightBlue('text')

  • colors.brightMagenta('text')

  • colors.brightCyan('text')

  • colors.brightWhite('text')

Background Colors

  • colors.bgBlack('text')

  • colors.bgRed('text')

  • colors.bgGreen('text')

  • colors.bgYellow('text')

  • colors.bgBlue('text')

  • colors.bgMagenta('text')

  • colors.bgCyan('text')

  • colors.bgWhite('text')

  • colors.bgBrightBlack('text')

  • colors.bgBrightRed('text')

  • colors.bgBrightGreen('text')

  • colors.bgBrightYellow('text')

  • colors.bgBrightBlue('text')

  • colors.bgBrightMagenta('text')

  • colors.bgBrightCyan('text')

  • colors.bgBrightWhite('text')

Example Usage

Here's a more complete example demonstrating various styles:

const colors = require('oli-colors');

console.log(colors.green('Hello, world!'));
console.log(colors.bold.red('Error: Something went wrong!'));
console.log(colors.underline.cyan('This is a link or important note.'));
console.log(colors.bgYellow.black('Black text on a yellow background.'));
console.log(colors.brightBlue('This is a bright blue message.'));
console.log(colors.dim('This text is less prominent.'));
console.log(colors.italic.brightGreen.bgBlack('A stylish message with multiple effects!'));
console.log(colors.inverse('Inverted colors!'));
console.log(colors.hidden('You cannot see this text.')); // It's there, just hidden!
console.log(colors.strikethrough('This text is cancelled.'));

// You can also combine with regular strings
console.log(`This is a ${colors.red('red')} word and a ${colors.blue('blue')} word.`);

How it Works (Briefly)

The utility uses ANSI escape codes which are special sequences of characters that terminals interpret as commands to control formatting, color, and other output options. Each method (.red, .bold, etc.) appends the corresponding ANSI code before your text and an ANSI reset code at the end, ensuring that subsequent console output is not affected.

The chainable nature is achieved using a JavaScript Proxy object, which allows method calls like colors.bold.red to build up a list of ANSI codes before the final function call (('text')) applies them to the string.