JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 53139721
  • Score
    100M100P100Q264438F
  • License MIT

Collection of ansi colors and styles.

Package Exports

  • ansi-colors

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ansi-colors) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ansi-colors NPM version NPM monthly downloads NPM total downloads Linux Build Status Windows Build Status

Collection of ansi colors and styles.

Please consider following this project's author, Brian Woodward, and consider starring the project to show your ❤️ and support.

Install

Install with npm:

$ npm install --save ansi-colors

ansi-colors is a Node.js library for adding colors to text in the terminal. A more performant drop-in replacement for chalk, with no dependencies.

image

Why use this?

See a comparison to other libraries

Usage

const c = require('ansi-colors');

console.log(c.red('This is a red string!'));
console.log(c.green('This is a red string!'));
console.log(c.cyan('This is a cyan string!'));
console.log(c.yellow('This is a yellow string!'));

image

Features

Colors take multiple arguments.

console.log(c.red('Some', 'red', 'text', 'to', 'display'));

Chained styles

Supports chained styles.

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

image

Nested styles

Supports nested styles.

// using template literals
console.log(c.yellow(`foo ${c.red.bold('red')} bar ${c.cyan('cyan')} baz`));

// or as arguments
console.log(c.yellow('foo', c.red.bold('red'), 'bar', c.cyan('cyan'), 'baz'));

image

Conditional color support

Easily enable/disable colors.

const c = require('ansi-colors');

// disable colors manually
c.enabled = false;

// or use a library to automatically detect support
c.enabled = require('color-support').stdout;

console.log(c.red('I will only be colored red if the terminal supports colors'));

printf-like formatting

Uses node's built-in util.format() to achieve printf-like formatting. The first argument is a string containing zero or more placeholder tokens. Each placeholder token is replaced with the converted value from the corresponding argument.

console.log(c.bold.red('%s:%s', 'foo', 'bar', 'baz'));

image

Even works with nested colors!

console.log(c.bold('%s:%s:%s', 'foo', c.red('bar'), 'baz'));

image

Strip ANSI codes

Use the .unstyle method to manually strip ANSI codes from a string.

console.log(c.unstyle(c.blue.bold('foo bar baz')));
//=> 'foo bar baz'

Available styles

Note that bright and bright-background colors are not always supported.

Colors

  • black
  • blue
  • cyan
  • gray (U.S.) and grey (everyone else)
  • green
  • magenta
  • red
  • white
  • yellow

Bright colors

  • blueBright
  • cyanBright
  • greenBright
  • magentaBright
  • redBright
  • whiteBright
  • yellowBright

Background colors

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

Bright background colors

  • bgBlackBright
  • bgBlueBright
  • bgCyanBright
  • bgGreenBright
  • bgMagentaBright
  • bgRedBright
  • bgWhiteBright
  • bgYellowBright

Modifiers

  • bold

  • dim

  • hidden

  • inverse

  • italic (Not widely supported)

  • reset

  • strikethrough (Not widely supported)

  • underline

Symbols

A handful of common useful symbols are available on the c.symbols property.

console.log(c.symbols);

Available symbols

Windows

  • check:
  • cross: ×
  • ellipsis: '...
  • info: i
  • line:
  • pointer: '>
  • pointerSmall: »
  • question: ?
  • questionSmall:
  • warning:

Other platforms

  • check:
  • cross:
  • ellipsis:
  • info:
  • line:
  • pointer:
  • pointerSmall:
  • question: ?
  • questionSmall:
  • warning:

Benchmarks

MacBook Pro, Intel Core i7, 2.5 GHz, 16 GB.

Load time

Time it takes to load the module the first time:

ansi-colors: 2.057ms
chalk: 9.063ms
clorox: 1.701ms

Performance

# All Colors
  ansi-colors x 93,508 ops/sec ±1.19% (88 runs sampled)
  chalk x 8,871 ops/sec ±2.33% (81 runs sampled)
  clorox x 1,401 ops/sec ±2.62% (77 runs sampled)

# Stacked colors
  ansi-colors x 14,413 ops/sec ±1.35% (88 runs sampled)
  chalk x 1,824 ops/sec ±2.46% (79 runs sampled)
  clorox x 563 ops/sec ±2.83% (75 runs sampled)

# Nested colors
  ansi-colors x 37,897 ops/sec ±1.02% (92 runs sampled)
  chalk x 4,196 ops/sec ±1.88% (81 runs sampled)
  clorox x 676 ops/sec ±2.70% (69 runs sampled)

Comparison

Feature ansi-colors chalk clorox colors
Nested colors yes yes no yes
Chained colors yes yes You must call .toString() on result yes
Toggle color support yes yes no yes
printf-like formatting yes no no no
Includes symbols yes no no no

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Running Tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test
Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

You might also be interested in these projects:

Contributors

Commits Contributor
18 doowb
7 jonschlinkert
2 Silic0nS0ldier

Author

Brian Woodward

License

Copyright © 2018, Brian Woodward. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on May 04, 2018.