4 <img width="360" src="https://cdn.rawgit.com/chalk/chalk/19935d6484811c5e468817f846b7b3d417d7bf4a/logo.svg" alt="chalk">
10 > Terminal string styling done right
12 [![Build Status](https://travis-ci.org/chalk/chalk.svg?branch=master)](https://travis-ci.org/chalk/chalk)
13 [![Coverage Status](https://coveralls.io/repos/chalk/chalk/badge.svg?branch=master)](https://coveralls.io/r/chalk/chalk?branch=master)
14 [![](http://img.shields.io/badge/unicorn-approved-ff69b4.svg)](https://www.youtube.com/watch?v=9auOCbH5Ns4)
17 [colors.js](https://github.com/Marak/colors.js) used to be the most popular string styling module, but it has serious deficiencies like extending `String.prototype` which causes all kinds of [problems](https://github.com/yeoman/yo/issues/68). Although there are other ones, they either do too much or not enough.
19 **Chalk is a clean and focused alternative.**
21 ![](https://github.com/chalk/ansi-styles/raw/master/screenshot.png)
27 - Doesn't extend `String.prototype`
29 - Ability to nest styles
31 - Auto-detects color support
33 - [Used by ~4500 modules](https://www.npmjs.com/browse/depended/chalk) as of July 15, 2015
39 $ npm install --save chalk
45 Chalk comes with an easy to use composable API where you just chain and nest the styles you want.
48 var chalk = require('chalk');
51 chalk.blue('Hello world!');
53 // combine styled and normal strings
54 chalk.blue('Hello') + 'World' + chalk.red('!');
56 // compose multiple styles using the chainable API
57 chalk.blue.bgRed.bold('Hello world!');
59 // pass in multiple arguments
60 chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz');
63 chalk.red('Hello', chalk.underline.bgBlue('world') + '!');
65 // nest styles of the same type even (color, underline, background)
67 'I am a green line ' +
68 chalk.blue.underline.bold('with a blue substring') +
69 ' that becomes green again!'
73 Easily define your own themes.
76 var chalk = require('chalk');
77 var error = chalk.bold.red;
78 console.log(error('Error!'));
81 Take advantage of console.log [string substitution](http://nodejs.org/docs/latest/api/console.html#console_console_log_data).
85 console.log(chalk.green('Hello %s'), name);
92 ### chalk.`<style>[.<style>...](string, [string...])`
94 Example: `chalk.red.bold.underline('Hello', 'world');`
96 Chain [styles](#styles) and call the last one as a method with a string argument. Order doesn't matter, and later styles take precedent in case of a conflict. This simply means that `Chalk.red.yellow.green` is equivalent to `Chalk.green`.
98 Multiple arguments will be separated by space.
102 Color support is automatically detected, but you can override it by setting the `enabled` property. You should however only do this in your own code as it applies globally to all chalk consumers.
104 If you need to change this in a reusable module create a new instance:
107 var ctx = new chalk.constructor({enabled: false});
110 ### chalk.supportsColor
112 Detect whether the terminal [supports color](https://github.com/chalk/supports-color). Used internally and handled for you, but exposed for convenience.
114 Can be overridden by the user with the flags `--color` and `--no-color`. For situations where using `--color` is not possible, add an environment variable `FORCE_COLOR` with any value to force color. Trumps `--no-color`.
118 Exposes the styles as [ANSI escape codes](https://github.com/chalk/ansi-styles).
120 Generally not useful, but you might need just the `.open` or `.close` escape code if you're mixing externally styled strings with your own.
123 var chalk = require('chalk');
125 console.log(chalk.styles.red);
126 //=> {open: '\u001b[31m', close: '\u001b[39m'}
128 console.log(chalk.styles.red.open + 'Hello' + chalk.styles.red.close);
131 ### chalk.hasColor(string)
133 Check whether a string [has color](https://github.com/chalk/has-ansi).
135 ### chalk.stripColor(string)
137 [Strip color](https://github.com/chalk/strip-ansi) from a string.
139 Can be useful in combination with `.supportsColor` to strip color on externally styled text when it's not supported.
144 var chalk = require('chalk');
145 var styledString = getText();
147 if (!chalk.supportsColor) {
148 styledString = chalk.stripColor(styledString);
160 - `italic` *(not widely supported)*
164 - `strikethrough` *(not widely supported)*
172 - `blue` *(on Windows the bright version is used as normal blue is illegible)*
178 ### Background colors
192 Chalk does not support anything other than the base eight colors, which guarantees it will work on all terminals and systems. Some terminals, specifically `xterm` compliant ones, will support the full range of 8-bit colors. For this the lower level [ansi-256-colors](https://github.com/jbnicolai/ansi-256-colors) package can be used.
197 If you're on Windows, do yourself a favor and use [`cmder`](http://bliker.github.io/cmder/) instead of `cmd.exe`.
202 - [chalk-cli](https://github.com/chalk/chalk-cli) - CLI for this module
203 - [ansi-styles](https://github.com/chalk/ansi-styles/) - ANSI escape codes for styling strings in the terminal
204 - [supports-color](https://github.com/chalk/supports-color/) - Detect whether a terminal supports color
205 - [strip-ansi](https://github.com/chalk/strip-ansi) - Strip ANSI escape codes
206 - [has-ansi](https://github.com/chalk/has-ansi) - Check if a string has ANSI escape codes
207 - [ansi-regex](https://github.com/chalk/ansi-regex) - Regular expression for matching ANSI escape codes
208 - [wrap-ansi](https://github.com/chalk/wrap-ansi) - Wordwrap a string with ANSI escape codes
213 MIT © [Sindre Sorhus](http://sindresorhus.com)