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

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.
Why use this?
- Minimal - No dependencies! (chalk has 7 dependencies in its tree)
- Safe - Does not modify the
String.prototype
- Fast - Loads 5x faster and renders styles 10x faster than chalk.
- Conditional color support
- Supports nested colors
- Supports chained colors!
- Includes commonly used symbols
- Exposes a method for stripping ANSI codes
- printf-like formatting
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!'));
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'));
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'));
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'));
Even works with nested colors!
console.log(c.bold('%s:%s:%s', 'foo', c.red('bar'), 'baz'));
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.) andgrey
(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.3 GHz, 16 GB.
Load time
Time it takes to load the module the first time:
chalk: 11.795ms
clorox: 1.019ms
ansi-colors: 0.867ms
Performance
# All Colors
ansi-colors x 104,559 ops/sec ±0.80% (91 runs sampled)
chalk x 8,869 ops/sec ±2.09% (82 runs sampled)
clorox x 1,315 ops/sec ±2.19% (76 runs sampled)
# Stacked colors
ansi-colors x 36,208 ops/sec ±0.65% (88 runs sampled)
chalk x 1,789 ops/sec ±1.77% (80 runs sampled)
clorox x 528 ops/sec ±2.00% (78 runs sampled)
# Nested colors
ansi-colors x 42,828 ops/sec ±0.36% (90 runs sampled)
chalk x 4,082 ops/sec ±1.93% (83 runs sampled)
clorox x 628 ops/sec ±2.10% (60 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
Related projects
- ansi-wrap: Create ansi colors by passing the open and close codes. | homepage
- strip-color: Strip ANSI color codes from a string. No dependencies. | homepage
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Contributors
Commits | Contributor |
---|---|
21 | doowb |
10 | jonschlinkert |
6 | lukeed |
2 | Silic0nS0ldier |
1 | chapterjason |
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
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
Author
Brian Woodward
License
Copyright © 2018, Brian Woodward. Released under the MIT License.
This file was generated by verb-generate-readme, v0.7.0, on July 16, 2018.