.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / chalk / readme.md
1 <h1 align="center">
2         <br>
3         <br>
4         <img width="320" src="media/logo.svg" alt="Chalk">
5         <br>
6         <br>
7         <br>
8 </h1>
9
10 > Terminal string styling done right
11
12 [![Build Status](https://travis-ci.org/chalk/chalk.svg?branch=master)](https://travis-ci.org/chalk/chalk) [![Coverage Status](https://coveralls.io/repos/github/chalk/chalk/badge.svg?branch=master)](https://coveralls.io/github/chalk/chalk?branch=master) [![npm dependents](https://badgen.net/npm/dependents/chalk)](https://www.npmjs.com/package/chalk?activeTab=dependents) [![Downloads](https://badgen.net/npm/dt/chalk)](https://www.npmjs.com/package/chalk) [![](https://img.shields.io/badge/unicorn-approved-ff69b4.svg)](https://www.youtube.com/watch?v=9auOCbH5Ns4) [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/xojs/xo) ![TypeScript-ready](https://img.shields.io/npm/types/chalk.svg) [![run on repl.it](https://repl.it/badge/github/chalk/chalk)](https://repl.it/github/chalk/chalk)
13
14 <img src="https://cdn.jsdelivr.net/gh/chalk/ansi-styles@8261697c95bf34b6c7767e2cbe9941a851d59385/screenshot.svg" width="900">
15
16 ## Highlights
17
18 - Expressive API
19 - Highly performant
20 - Ability to nest styles
21 - [256/Truecolor color support](#256-and-truecolor-color-support)
22 - Auto-detects color support
23 - Doesn't extend `String.prototype`
24 - Clean and focused
25 - Actively maintained
26 - [Used by ~50,000 packages](https://www.npmjs.com/browse/depended/chalk) as of January 1, 2020
27
28 ## Install
29
30 ```console
31 $ npm install chalk
32 ```
33
34 ## Usage
35
36 ```js
37 const chalk = require('chalk');
38
39 console.log(chalk.blue('Hello world!'));
40 ```
41
42 Chalk comes with an easy to use composable API where you just chain and nest the styles you want.
43
44 ```js
45 const chalk = require('chalk');
46 const log = console.log;
47
48 // Combine styled and normal strings
49 log(chalk.blue('Hello') + ' World' + chalk.red('!'));
50
51 // Compose multiple styles using the chainable API
52 log(chalk.blue.bgRed.bold('Hello world!'));
53
54 // Pass in multiple arguments
55 log(chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz'));
56
57 // Nest styles
58 log(chalk.red('Hello', chalk.underline.bgBlue('world') + '!'));
59
60 // Nest styles of the same type even (color, underline, background)
61 log(chalk.green(
62         'I am a green line ' +
63         chalk.blue.underline.bold('with a blue substring') +
64         ' that becomes green again!'
65 ));
66
67 // ES2015 template literal
68 log(`
69 CPU: ${chalk.red('90%')}
70 RAM: ${chalk.green('40%')}
71 DISK: ${chalk.yellow('70%')}
72 `);
73
74 // ES2015 tagged template literal
75 log(chalk`
76 CPU: {red ${cpu.totalPercent}%}
77 RAM: {green ${ram.used / ram.total * 100}%}
78 DISK: {rgb(255,131,0) ${disk.used / disk.total * 100}%}
79 `);
80
81 // Use RGB colors in terminal emulators that support it.
82 log(chalk.keyword('orange')('Yay for orange colored text!'));
83 log(chalk.rgb(123, 45, 67).underline('Underlined reddish color'));
84 log(chalk.hex('#DEADED').bold('Bold gray!'));
85 ```
86
87 Easily define your own themes:
88
89 ```js
90 const chalk = require('chalk');
91
92 const error = chalk.bold.red;
93 const warning = chalk.keyword('orange');
94
95 console.log(error('Error!'));
96 console.log(warning('Warning!'));
97 ```
98
99 Take advantage of console.log [string substitution](https://nodejs.org/docs/latest/api/console.html#console_console_log_data_args):
100
101 ```js
102 const name = 'Sindre';
103 console.log(chalk.green('Hello %s'), name);
104 //=> 'Hello Sindre'
105 ```
106
107 ## API
108
109 ### chalk.`<style>[.<style>...](string, [string...])`
110
111 Example: `chalk.red.bold.underline('Hello', 'world');`
112
113 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`.
114
115 Multiple arguments will be separated by space.
116
117 ### chalk.level
118
119 Specifies the level of color support.
120
121 Color support is automatically detected, but you can override it by setting the `level` property. You should however only do this in your own code as it applies globally to all Chalk consumers.
122
123 If you need to change this in a reusable module, create a new instance:
124
125 ```js
126 const ctx = new chalk.Instance({level: 0});
127 ```
128
129 | Level | Description |
130 | :---: | :--- |
131 | `0` | All colors disabled |
132 | `1` | Basic color support (16 colors) |
133 | `2` | 256 color support |
134 | `3` | Truecolor support (16 million colors) |
135
136 ### chalk.supportsColor
137
138 Detect whether the terminal [supports color](https://github.com/chalk/supports-color). Used internally and handled for you, but exposed for convenience.
139
140 Can be overridden by the user with the flags `--color` and `--no-color`. For situations where using `--color` is not possible, use the environment variable `FORCE_COLOR=1` (level 1), `FORCE_COLOR=2` (level 2), or `FORCE_COLOR=3` (level 3) to forcefully enable color, or `FORCE_COLOR=0` to forcefully disable. The use of `FORCE_COLOR` overrides all other color support checks.
141
142 Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
143
144 ### chalk.stderr and chalk.stderr.supportsColor
145
146 `chalk.stderr` contains a separate instance configured with color support detected for `stderr` stream instead of `stdout`. Override rules from `chalk.supportsColor` apply to this too. `chalk.stderr.supportsColor` is exposed for convenience.
147
148 ## Styles
149
150 ### Modifiers
151
152 - `reset` - Resets the current color chain.
153 - `bold` - Make text bold.
154 - `dim` - Emitting only a small amount of light.
155 - `italic` - Make text italic. *(Not widely supported)*
156 - `underline` - Make text underline. *(Not widely supported)*
157 - `inverse`- Inverse background and foreground colors.
158 - `hidden` - Prints the text, but makes it invisible.
159 - `strikethrough` - Puts a horizontal line through the center of the text. *(Not widely supported)*
160 - `visible`- Prints the text only when Chalk has a color level > 0. Can be useful for things that are purely cosmetic.
161
162 ### Colors
163
164 - `black`
165 - `red`
166 - `green`
167 - `yellow`
168 - `blue`
169 - `magenta`
170 - `cyan`
171 - `white`
172 - `blackBright` (alias: `gray`, `grey`)
173 - `redBright`
174 - `greenBright`
175 - `yellowBright`
176 - `blueBright`
177 - `magentaBright`
178 - `cyanBright`
179 - `whiteBright`
180
181 ### Background colors
182
183 - `bgBlack`
184 - `bgRed`
185 - `bgGreen`
186 - `bgYellow`
187 - `bgBlue`
188 - `bgMagenta`
189 - `bgCyan`
190 - `bgWhite`
191 - `bgBlackBright` (alias: `bgGray`, `bgGrey`)
192 - `bgRedBright`
193 - `bgGreenBright`
194 - `bgYellowBright`
195 - `bgBlueBright`
196 - `bgMagentaBright`
197 - `bgCyanBright`
198 - `bgWhiteBright`
199
200 ## Tagged template literal
201
202 Chalk can be used as a [tagged template literal](https://exploringjs.com/es6/ch_template-literals.html#_tagged-template-literals).
203
204 ```js
205 const chalk = require('chalk');
206
207 const miles = 18;
208 const calculateFeet = miles => miles * 5280;
209
210 console.log(chalk`
211         There are {bold 5280 feet} in a mile.
212         In {bold ${miles} miles}, there are {green.bold ${calculateFeet(miles)} feet}.
213 `);
214 ```
215
216 Blocks are delimited by an opening curly brace (`{`), a style, some content, and a closing curly brace (`}`).
217
218 Template styles are chained exactly like normal Chalk styles. The following three statements are equivalent:
219
220 ```js
221 console.log(chalk.bold.rgb(10, 100, 200)('Hello!'));
222 console.log(chalk.bold.rgb(10, 100, 200)`Hello!`);
223 console.log(chalk`{bold.rgb(10,100,200) Hello!}`);
224 ```
225
226 Note that function styles (`rgb()`, `hsl()`, `keyword()`, etc.) may not contain spaces between parameters.
227
228 All interpolated values (`` chalk`${foo}` ``) are converted to strings via the `.toString()` method. All curly braces (`{` and `}`) in interpolated value strings are escaped.
229
230 ## 256 and Truecolor color support
231
232 Chalk supports 256 colors and [Truecolor](https://gist.github.com/XVilka/8346728) (16 million colors) on supported terminal apps.
233
234 Colors are downsampled from 16 million RGB values to an ANSI color format that is supported by the terminal emulator (or by specifying `{level: n}` as a Chalk option). For example, Chalk configured to run at level 1 (basic color support) will downsample an RGB value of #FF0000 (red) to 31 (ANSI escape for red).
235
236 Examples:
237
238 - `chalk.hex('#DEADED').underline('Hello, world!')`
239 - `chalk.keyword('orange')('Some orange text')`
240 - `chalk.rgb(15, 100, 204).inverse('Hello!')`
241
242 Background versions of these models are prefixed with `bg` and the first level of the module capitalized (e.g. `keyword` for foreground colors and `bgKeyword` for background colors).
243
244 - `chalk.bgHex('#DEADED').underline('Hello, world!')`
245 - `chalk.bgKeyword('orange')('Some orange text')`
246 - `chalk.bgRgb(15, 100, 204).inverse('Hello!')`
247
248 The following color models can be used:
249
250 - [`rgb`](https://en.wikipedia.org/wiki/RGB_color_model) - Example: `chalk.rgb(255, 136, 0).bold('Orange!')`
251 - [`hex`](https://en.wikipedia.org/wiki/Web_colors#Hex_triplet) - Example: `chalk.hex('#FF8800').bold('Orange!')`
252 - [`keyword`](https://www.w3.org/wiki/CSS/Properties/color/keywords) (CSS keywords) - Example: `chalk.keyword('orange').bold('Orange!')`
253 - [`hsl`](https://en.wikipedia.org/wiki/HSL_and_HSV) - Example: `chalk.hsl(32, 100, 50).bold('Orange!')`
254 - [`hsv`](https://en.wikipedia.org/wiki/HSL_and_HSV) - Example: `chalk.hsv(32, 100, 100).bold('Orange!')`
255 - [`hwb`](https://en.wikipedia.org/wiki/HWB_color_model) - Example: `chalk.hwb(32, 0, 50).bold('Orange!')`
256 - [`ansi`](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) - Example: `chalk.ansi(31).bgAnsi(93)('red on yellowBright')`
257 - [`ansi256`](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) - Example: `chalk.bgAnsi256(194)('Honeydew, more or less')`
258
259 ## Windows
260
261 If you're on Windows, do yourself a favor and use [Windows Terminal](https://github.com/microsoft/terminal) instead of `cmd.exe`.
262
263 ## Origin story
264
265 [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) and the package is unmaintained. Although there are other packages, they either do too much or not enough. Chalk is a clean and focused alternative.
266
267 ## chalk for enterprise
268
269 Available as part of the Tidelift Subscription.
270
271 The maintainers of chalk and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-chalk?utm_source=npm-chalk&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
272
273 ## Related
274
275 - [chalk-cli](https://github.com/chalk/chalk-cli) - CLI for this module
276 - [ansi-styles](https://github.com/chalk/ansi-styles) - ANSI escape codes for styling strings in the terminal
277 - [supports-color](https://github.com/chalk/supports-color) - Detect whether a terminal supports color
278 - [strip-ansi](https://github.com/chalk/strip-ansi) - Strip ANSI escape codes
279 - [strip-ansi-stream](https://github.com/chalk/strip-ansi-stream) - Strip ANSI escape codes from a stream
280 - [has-ansi](https://github.com/chalk/has-ansi) - Check if a string has ANSI escape codes
281 - [ansi-regex](https://github.com/chalk/ansi-regex) - Regular expression for matching ANSI escape codes
282 - [wrap-ansi](https://github.com/chalk/wrap-ansi) - Wordwrap a string with ANSI escape codes
283 - [slice-ansi](https://github.com/chalk/slice-ansi) - Slice a string with ANSI escape codes
284 - [color-convert](https://github.com/qix-/color-convert) - Converts colors between different models
285 - [chalk-animation](https://github.com/bokub/chalk-animation) - Animate strings in the terminal
286 - [gradient-string](https://github.com/bokub/gradient-string) - Apply color gradients to strings
287 - [chalk-pipe](https://github.com/LitoMore/chalk-pipe) - Create chalk style schemes with simpler style strings
288 - [terminal-link](https://github.com/sindresorhus/terminal-link) - Create clickable links in the terminal
289
290 ## Maintainers
291
292 - [Sindre Sorhus](https://github.com/sindresorhus)
293 - [Josh Junon](https://github.com/qix-)