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

colourant

v1.1.0

Published

A Node.js library for formatting terminal text using ANSI

Downloads

5

Readme

GitHub Actions codecov release dependencies license

Node 8+ is required. Only LTS versions of Node are tested.

A Node.js library for formatting terminal text using ANSI

features

install

$ npm install --save colourant

usage

const { blue, bold, red, white } = require( "colourant" );

// basic usage
red( "red text" );

// chained methods
blue().bold().underline( "howdy partner" );

// nested methods
bold(`${ white().bgRed( "[ERROR]" ) } ${ red().italic( "Something happened" ) }`);

Chained Methods

const { bold, green } = require( "colourant" );

console.log( bold().red( "this is a bold red message" ) );
console.log( bold().italic( "this is a bold italicized message" ) );
console.log( bold().yellow().bgRed().italic( "this is a bold yellow italicized message" ) );
console.log( green().bold().underline( "this is a bold green underlined message" ) );

Nested Methods

const { cyan, red, yellow } = require( "colourant" );

console.log( yellow( `foo ${ red().bold( "red" ) } bar ${ cyan( "cyan" ) } baz` ) );
console.log( yellow( "foo " + red().bold( "red" ) + " bar " + cyan( "cyan" ) + " baz" ) );

Conditional Support

Toggle colour support as needed; colourant includes auto-detection, but may not cover all cases.

const colourant = require( "colourant" );

// manually enable
colourant.enable();

// manually disable
colourant.disable();

// or use another library to detect support
colourant.enabled = require( "color-support" ).level;

console.log( colourant.red( "I will only be coloured red if `colourant.enabled` is true" ) );

api

Built-in Styles

Built-in colourant styles return a String when invoked with input; otherwise chaining is expected.

It's up to the developer to pass the output to destinations like console.log, process.stdout.write, etc.

The methods below are grouped by type for legibility purposes only. They each can be chained or nested with one another.

Colours:

black — red — green — yellow — blue — magenta — cyan — white — gray — grey

Backgrounds:

bgBlack — bgRed — bgGreen — bgYellow — bgBlue — bgMagenta — bgCyan — bgWhite

Modifiers:

reset — bold — dim — italic* — underline — inverse — hidden — strikethrough*

* Not widely supported

Utility Methods

As well as supporting the kleur 3 API, colourant also provides:

/*
    `codegroup` refer's to an array containing the start and end codes
    `codemap` refer's to a map of codegroups
*/

const colourant = require( "colourant" );

// Build a custom styled string transformer (stacked, alternative to chain)
colourant( ...codegroups )

// Build a non-chainable string transformer
colourant.from( number, number )
colourant.from( codegroup )

// Build a chainable string transformer
colourant.chain( codemap )

// Build and assign chainable string transformers
colourant.assign( target, codemap )

// Map of default styles
colourant.codes

// Build ANSI string for the given number
colourant.ANSI( number )

// Returns a grey string
colourant.time( string )

// Returns a white string
colourant.info( string )

// Returns a yellow string
colourant.warning( string )

// Returns a red string
colourant.error( string )

// Returns `true` if your env supports colouring by default (checked on library load)
colourant.supportsColour()

TypeScript

This library is written in TypeScript, but I wanted to export the colourant function as a CommonJS default export (assigning it to Node's module.exports) so that it's usable via just calling require( "colourant" ) instead of require( "colourant" ).colourant or require( "colourant" ).default; To import an exported interface or type, juse import the generated modules directly from colourant/out

benchmarks

Using Node v12.13.0 on a laptop powered by an AMD A10-4600M APU & 6GB RAM

Load time

chalk       :: 23.930ms
kleur       :: 11.131ms
ansi-colors ::  8.997ms
colorette   ::  3.244ms
colourant   ::  8.633ms

Performance

# All Colors
  ansi-colors  x  63,296 ops/sec ±1.93% (75 runs sampled)
  chalk        x 227,988 ops/sec ±1.32% (79 runs sampled)
  kleur        x 229,516 ops/sec ±1.67% (81 runs sampled)
  colorette    x 247,387 ops/sec ±3.44% (81 runs sampled)
  colourant    x 294,237 ops/sec ±1.50% (79 runs sampled)

# Stacked colors
  ansi-colors  x   7,408 ops/sec ±1.07% (80 runs sampled)
  chalk        x 174,681 ops/sec ±0.74% (83 runs sampled)
  kleur        x  26,174 ops/sec ±0.79% (82 runs sampled)
  colourant    x  90,674 ops/sec ±1.04% (81 runs sampled)

# Nested colors
  ansi-colors  x  18,684 ops/sec ±1.06% (81 runs sampled)
  chalk        x  42,756 ops/sec ±0.81% (83 runs sampled)
  kleur        x  62,920 ops/sec ±2.09% (84 runs sampled)
  colorette    x  87,270 ops/sec ±0.82% (82 runs sampled)
  colourant    x  61,707 ops/sec ±1.09% (77 runs sampled)

credits

This project is based on kleur 3, and contains content originally from it:

license

Copyright (c) 2019 Futago-za Ryuu The MIT License, http://opensource.org/licenses/MIT