chalk 2.4.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +411 -0
- package/package.json +21 -29
- package/readme.md +42 -52
- package/source/index.js +233 -0
- package/{templates.js → source/templates.js} +31 -25
- package/source/util.js +39 -0
- package/index.js +0 -228
- package/index.js.flow +0 -93
- package/types/index.d.ts +0 -97
package/index.d.ts
ADDED
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
declare const enum LevelEnum {
|
|
2
|
+
/**
|
|
3
|
+
All colors disabled.
|
|
4
|
+
*/
|
|
5
|
+
None = 0,
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
Basic 16 colors support.
|
|
9
|
+
*/
|
|
10
|
+
Basic = 1,
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
ANSI 256 colors support.
|
|
14
|
+
*/
|
|
15
|
+
Ansi256 = 2,
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
Truecolor 16 million colors support.
|
|
19
|
+
*/
|
|
20
|
+
TrueColor = 3
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
Basic foreground colors.
|
|
25
|
+
|
|
26
|
+
[More colors here.](https://github.com/chalk/chalk/blob/master/readme.md#256-and-truecolor-color-support)
|
|
27
|
+
*/
|
|
28
|
+
declare type ForegroundColor =
|
|
29
|
+
| 'black'
|
|
30
|
+
| 'red'
|
|
31
|
+
| 'green'
|
|
32
|
+
| 'yellow'
|
|
33
|
+
| 'blue'
|
|
34
|
+
| 'magenta'
|
|
35
|
+
| 'cyan'
|
|
36
|
+
| 'white'
|
|
37
|
+
| 'gray'
|
|
38
|
+
| 'grey'
|
|
39
|
+
| 'blackBright'
|
|
40
|
+
| 'redBright'
|
|
41
|
+
| 'greenBright'
|
|
42
|
+
| 'yellowBright'
|
|
43
|
+
| 'blueBright'
|
|
44
|
+
| 'magentaBright'
|
|
45
|
+
| 'cyanBright'
|
|
46
|
+
| 'whiteBright';
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
Basic background colors.
|
|
50
|
+
|
|
51
|
+
[More colors here.](https://github.com/chalk/chalk/blob/master/readme.md#256-and-truecolor-color-support)
|
|
52
|
+
*/
|
|
53
|
+
declare type BackgroundColor =
|
|
54
|
+
| 'bgBlack'
|
|
55
|
+
| 'bgRed'
|
|
56
|
+
| 'bgGreen'
|
|
57
|
+
| 'bgYellow'
|
|
58
|
+
| 'bgBlue'
|
|
59
|
+
| 'bgMagenta'
|
|
60
|
+
| 'bgCyan'
|
|
61
|
+
| 'bgWhite'
|
|
62
|
+
| 'bgGray'
|
|
63
|
+
| 'bgGrey'
|
|
64
|
+
| 'bgBlackBright'
|
|
65
|
+
| 'bgRedBright'
|
|
66
|
+
| 'bgGreenBright'
|
|
67
|
+
| 'bgYellowBright'
|
|
68
|
+
| 'bgBlueBright'
|
|
69
|
+
| 'bgMagentaBright'
|
|
70
|
+
| 'bgCyanBright'
|
|
71
|
+
| 'bgWhiteBright';
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
Basic colors.
|
|
75
|
+
|
|
76
|
+
[More colors here.](https://github.com/chalk/chalk/blob/master/readme.md#256-and-truecolor-color-support)
|
|
77
|
+
*/
|
|
78
|
+
declare type Color = ForegroundColor | BackgroundColor;
|
|
79
|
+
|
|
80
|
+
declare type Modifiers =
|
|
81
|
+
| 'reset'
|
|
82
|
+
| 'bold'
|
|
83
|
+
| 'dim'
|
|
84
|
+
| 'italic'
|
|
85
|
+
| 'underline'
|
|
86
|
+
| 'inverse'
|
|
87
|
+
| 'hidden'
|
|
88
|
+
| 'strikethrough'
|
|
89
|
+
| 'visible';
|
|
90
|
+
|
|
91
|
+
declare namespace chalk {
|
|
92
|
+
type Level = LevelEnum;
|
|
93
|
+
|
|
94
|
+
interface Options {
|
|
95
|
+
/**
|
|
96
|
+
Specify the color support for Chalk.
|
|
97
|
+
By default, color support is automatically detected based on the environment.
|
|
98
|
+
*/
|
|
99
|
+
level?: Level;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
interface Instance {
|
|
103
|
+
/**
|
|
104
|
+
Return a new Chalk instance.
|
|
105
|
+
*/
|
|
106
|
+
new (options?: Options): Chalk;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
Detect whether the terminal supports color.
|
|
111
|
+
*/
|
|
112
|
+
interface ColorSupport {
|
|
113
|
+
/**
|
|
114
|
+
The color level used by Chalk.
|
|
115
|
+
*/
|
|
116
|
+
level: Level;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
Return whether Chalk supports basic 16 colors.
|
|
120
|
+
*/
|
|
121
|
+
hasBasic: boolean;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
Return whether Chalk supports ANSI 256 colors.
|
|
125
|
+
*/
|
|
126
|
+
has256: boolean;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
Return whether Chalk supports Truecolor 16 million colors.
|
|
130
|
+
*/
|
|
131
|
+
has16m: boolean;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
interface ChalkFunction {
|
|
135
|
+
/**
|
|
136
|
+
Use a template string.
|
|
137
|
+
|
|
138
|
+
@remarks Template literals are unsupported for nested calls (see [issue #341](https://github.com/chalk/chalk/issues/341))
|
|
139
|
+
|
|
140
|
+
@example
|
|
141
|
+
```
|
|
142
|
+
import chalk = require('chalk');
|
|
143
|
+
|
|
144
|
+
log(chalk`
|
|
145
|
+
CPU: {red ${cpu.totalPercent}%}
|
|
146
|
+
RAM: {green ${ram.used / ram.total * 100}%}
|
|
147
|
+
DISK: {rgb(255,131,0) ${disk.used / disk.total * 100}%}
|
|
148
|
+
`);
|
|
149
|
+
```
|
|
150
|
+
*/
|
|
151
|
+
(text: TemplateStringsArray, ...placeholders: unknown[]): string;
|
|
152
|
+
|
|
153
|
+
(...text: unknown[]): string;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
interface Chalk extends ChalkFunction {
|
|
157
|
+
/**
|
|
158
|
+
Return a new Chalk instance.
|
|
159
|
+
*/
|
|
160
|
+
Instance: Instance;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
The color support for Chalk.
|
|
164
|
+
By default, color support is automatically detected based on the environment.
|
|
165
|
+
*/
|
|
166
|
+
level: Level;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
Use HEX value to set text color.
|
|
170
|
+
|
|
171
|
+
@param color - Hexadecimal value representing the desired color.
|
|
172
|
+
|
|
173
|
+
@example
|
|
174
|
+
```
|
|
175
|
+
import chalk = require('chalk');
|
|
176
|
+
|
|
177
|
+
chalk.hex('#DEADED');
|
|
178
|
+
```
|
|
179
|
+
*/
|
|
180
|
+
hex(color: string): Chalk;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
Use keyword color value to set text color.
|
|
184
|
+
|
|
185
|
+
@param color - Keyword value representing the desired color.
|
|
186
|
+
|
|
187
|
+
@example
|
|
188
|
+
```
|
|
189
|
+
import chalk = require('chalk');
|
|
190
|
+
|
|
191
|
+
chalk.keyword('orange');
|
|
192
|
+
```
|
|
193
|
+
*/
|
|
194
|
+
keyword(color: string): Chalk;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
Use RGB values to set text color.
|
|
198
|
+
*/
|
|
199
|
+
rgb(red: number, green: number, blue: number): Chalk;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
Use HSL values to set text color.
|
|
203
|
+
*/
|
|
204
|
+
hsl(hue: number, saturation: number, lightness: number): Chalk;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
Use HSV values to set text color.
|
|
208
|
+
*/
|
|
209
|
+
hsv(hue: number, saturation: number, value: number): Chalk;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
Use HWB values to set text color.
|
|
213
|
+
*/
|
|
214
|
+
hwb(hue: number, whiteness: number, blackness: number): Chalk;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set text color.
|
|
218
|
+
|
|
219
|
+
30 <= code && code < 38 || 90 <= code && code < 98
|
|
220
|
+
For example, 31 for red, 91 for redBright.
|
|
221
|
+
*/
|
|
222
|
+
ansi(code: number): Chalk;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
|
|
226
|
+
*/
|
|
227
|
+
ansi256(index: number): Chalk;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
Use HEX value to set background color.
|
|
231
|
+
|
|
232
|
+
@param color - Hexadecimal value representing the desired color.
|
|
233
|
+
|
|
234
|
+
@example
|
|
235
|
+
```
|
|
236
|
+
import chalk = require('chalk');
|
|
237
|
+
|
|
238
|
+
chalk.bgHex('#DEADED');
|
|
239
|
+
```
|
|
240
|
+
*/
|
|
241
|
+
bgHex(color: string): Chalk;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
Use keyword color value to set background color.
|
|
245
|
+
|
|
246
|
+
@param color - Keyword value representing the desired color.
|
|
247
|
+
|
|
248
|
+
@example
|
|
249
|
+
```
|
|
250
|
+
import chalk = require('chalk');
|
|
251
|
+
|
|
252
|
+
chalk.bgKeyword('orange');
|
|
253
|
+
```
|
|
254
|
+
*/
|
|
255
|
+
bgKeyword(color: string): Chalk;
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
Use RGB values to set background color.
|
|
259
|
+
*/
|
|
260
|
+
bgRgb(red: number, green: number, blue: number): Chalk;
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
Use HSL values to set background color.
|
|
264
|
+
*/
|
|
265
|
+
bgHsl(hue: number, saturation: number, lightness: number): Chalk;
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
Use HSV values to set background color.
|
|
269
|
+
*/
|
|
270
|
+
bgHsv(hue: number, saturation: number, value: number): Chalk;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
Use HWB values to set background color.
|
|
274
|
+
*/
|
|
275
|
+
bgHwb(hue: number, whiteness: number, blackness: number): Chalk;
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set background color.
|
|
279
|
+
|
|
280
|
+
30 <= code && code < 38 || 90 <= code && code < 98
|
|
281
|
+
For example, 31 for red, 91 for redBright.
|
|
282
|
+
Use the foreground code, not the background code (for example, not 41, nor 101).
|
|
283
|
+
*/
|
|
284
|
+
bgAnsi(code: number): Chalk;
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set background color.
|
|
288
|
+
*/
|
|
289
|
+
bgAnsi256(index: number): Chalk;
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
Modifier: Resets the current color chain.
|
|
293
|
+
*/
|
|
294
|
+
readonly reset: Chalk;
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
Modifier: Make text bold.
|
|
298
|
+
*/
|
|
299
|
+
readonly bold: Chalk;
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
Modifier: Emitting only a small amount of light.
|
|
303
|
+
*/
|
|
304
|
+
readonly dim: Chalk;
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
Modifier: Make text italic. (Not widely supported)
|
|
308
|
+
*/
|
|
309
|
+
readonly italic: Chalk;
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
Modifier: Make text underline. (Not widely supported)
|
|
313
|
+
*/
|
|
314
|
+
readonly underline: Chalk;
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
Modifier: Inverse background and foreground colors.
|
|
318
|
+
*/
|
|
319
|
+
readonly inverse: Chalk;
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
Modifier: Prints the text, but makes it invisible.
|
|
323
|
+
*/
|
|
324
|
+
readonly hidden: Chalk;
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
Modifier: Puts a horizontal line through the center of the text. (Not widely supported)
|
|
328
|
+
*/
|
|
329
|
+
readonly strikethrough: Chalk;
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
Modifier: Prints the text only when Chalk has a color support level > 0.
|
|
333
|
+
Can be useful for things that are purely cosmetic.
|
|
334
|
+
*/
|
|
335
|
+
readonly visible: Chalk;
|
|
336
|
+
|
|
337
|
+
readonly black: Chalk;
|
|
338
|
+
readonly red: Chalk;
|
|
339
|
+
readonly green: Chalk;
|
|
340
|
+
readonly yellow: Chalk;
|
|
341
|
+
readonly blue: Chalk;
|
|
342
|
+
readonly magenta: Chalk;
|
|
343
|
+
readonly cyan: Chalk;
|
|
344
|
+
readonly white: Chalk;
|
|
345
|
+
|
|
346
|
+
/*
|
|
347
|
+
Alias for `blackBright`.
|
|
348
|
+
*/
|
|
349
|
+
readonly gray: Chalk;
|
|
350
|
+
|
|
351
|
+
/*
|
|
352
|
+
Alias for `blackBright`.
|
|
353
|
+
*/
|
|
354
|
+
readonly grey: Chalk;
|
|
355
|
+
|
|
356
|
+
readonly blackBright: Chalk;
|
|
357
|
+
readonly redBright: Chalk;
|
|
358
|
+
readonly greenBright: Chalk;
|
|
359
|
+
readonly yellowBright: Chalk;
|
|
360
|
+
readonly blueBright: Chalk;
|
|
361
|
+
readonly magentaBright: Chalk;
|
|
362
|
+
readonly cyanBright: Chalk;
|
|
363
|
+
readonly whiteBright: Chalk;
|
|
364
|
+
|
|
365
|
+
readonly bgBlack: Chalk;
|
|
366
|
+
readonly bgRed: Chalk;
|
|
367
|
+
readonly bgGreen: Chalk;
|
|
368
|
+
readonly bgYellow: Chalk;
|
|
369
|
+
readonly bgBlue: Chalk;
|
|
370
|
+
readonly bgMagenta: Chalk;
|
|
371
|
+
readonly bgCyan: Chalk;
|
|
372
|
+
readonly bgWhite: Chalk;
|
|
373
|
+
|
|
374
|
+
/*
|
|
375
|
+
Alias for `bgBlackBright`.
|
|
376
|
+
*/
|
|
377
|
+
readonly bgGray: Chalk;
|
|
378
|
+
|
|
379
|
+
/*
|
|
380
|
+
Alias for `bgBlackBright`.
|
|
381
|
+
*/
|
|
382
|
+
readonly bgGrey: Chalk;
|
|
383
|
+
|
|
384
|
+
readonly bgBlackBright: Chalk;
|
|
385
|
+
readonly bgRedBright: Chalk;
|
|
386
|
+
readonly bgGreenBright: Chalk;
|
|
387
|
+
readonly bgYellowBright: Chalk;
|
|
388
|
+
readonly bgBlueBright: Chalk;
|
|
389
|
+
readonly bgMagentaBright: Chalk;
|
|
390
|
+
readonly bgCyanBright: Chalk;
|
|
391
|
+
readonly bgWhiteBright: Chalk;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
Main Chalk object that allows to chain styles together.
|
|
397
|
+
Call the last one as a method with a string argument.
|
|
398
|
+
Order doesn't matter, and later styles take precedent in case of a conflict.
|
|
399
|
+
This simply means that `chalk.red.yellow.green` is equivalent to `chalk.green`.
|
|
400
|
+
*/
|
|
401
|
+
declare const chalk: chalk.Chalk & chalk.ChalkFunction & {
|
|
402
|
+
supportsColor: chalk.ColorSupport | false;
|
|
403
|
+
Level: typeof LevelEnum;
|
|
404
|
+
Color: Color;
|
|
405
|
+
ForegroundColor: ForegroundColor;
|
|
406
|
+
BackgroundColor: BackgroundColor;
|
|
407
|
+
Modifiers: Modifiers;
|
|
408
|
+
stderr: chalk.Chalk & {supportsColor: chalk.ColorSupport | false};
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
export = chalk;
|
package/package.json
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chalk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Terminal string styling done right",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "chalk/chalk",
|
|
7
|
+
"main": "source",
|
|
7
8
|
"engines": {
|
|
8
|
-
"node": ">=
|
|
9
|
+
"node": ">=8"
|
|
9
10
|
},
|
|
10
11
|
"scripts": {
|
|
11
|
-
"test": "xo &&
|
|
12
|
-
"bench": "matcha benchmark.js"
|
|
13
|
-
"coveralls": "nyc report --reporter=text-lcov | coveralls"
|
|
12
|
+
"test": "xo && nyc ava && tsd",
|
|
13
|
+
"bench": "matcha benchmark.js"
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"types/index.d.ts",
|
|
19
|
-
"index.js.flow"
|
|
16
|
+
"source",
|
|
17
|
+
"index.d.ts"
|
|
20
18
|
],
|
|
21
19
|
"keywords": [
|
|
22
20
|
"color",
|
|
@@ -42,30 +40,24 @@
|
|
|
42
40
|
"text"
|
|
43
41
|
],
|
|
44
42
|
"dependencies": {
|
|
45
|
-
"ansi-styles": "^
|
|
46
|
-
"
|
|
47
|
-
"supports-color": "^5.3.0"
|
|
43
|
+
"ansi-styles": "^4.1.0",
|
|
44
|
+
"supports-color": "^7.1.0"
|
|
48
45
|
},
|
|
49
46
|
"devDependencies": {
|
|
50
|
-
"ava": "
|
|
51
|
-
"coveralls": "^3.0.
|
|
52
|
-
"execa": "^
|
|
53
|
-
"
|
|
54
|
-
"import-fresh": "^2.0.0",
|
|
47
|
+
"ava": "^2.4.0",
|
|
48
|
+
"coveralls": "^3.0.7",
|
|
49
|
+
"execa": "^3.2.0",
|
|
50
|
+
"import-fresh": "^3.1.0",
|
|
55
51
|
"matcha": "^0.7.0",
|
|
56
|
-
"nyc": "^
|
|
57
|
-
"resolve-from": "^
|
|
58
|
-
"
|
|
59
|
-
"xo": "
|
|
52
|
+
"nyc": "^14.1.1",
|
|
53
|
+
"resolve-from": "^5.0.0",
|
|
54
|
+
"tsd": "^0.7.4",
|
|
55
|
+
"xo": "^0.25.3"
|
|
60
56
|
},
|
|
61
|
-
"types": "types/index.d.ts",
|
|
62
57
|
"xo": {
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
|
|
67
|
-
"ignores": [
|
|
68
|
-
"test/_flow.js"
|
|
69
|
-
]
|
|
58
|
+
"rules": {
|
|
59
|
+
"unicorn/prefer-string-slice": "off",
|
|
60
|
+
"unicorn/prefer-includes": "off"
|
|
61
|
+
}
|
|
70
62
|
}
|
|
71
63
|
}
|
package/readme.md
CHANGED
|
@@ -9,11 +9,9 @@
|
|
|
9
9
|
|
|
10
10
|
> Terminal string styling done right
|
|
11
11
|
|
|
12
|
-
[](https://travis-ci.org/chalk/chalk) [](https://coveralls.io/github/chalk/chalk?branch=master) [](https://www.youtube.com/watch?v=9auOCbH5Ns4) [](https://github.com/xojs/xo)
|
|
12
|
+
[](https://travis-ci.org/chalk/chalk) [](https://coveralls.io/github/chalk/chalk?branch=master) [](https://www.npmjs.com/package/chalk?activeTab=dependents) [](https://www.npmjs.com/package/chalk) [](https://www.youtube.com/watch?v=9auOCbH5Ns4) [](https://github.com/xojs/xo) 
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
<img src="https://cdn.rawgit.com/chalk/ansi-styles/8261697c95bf34b6c7767e2cbe9941a851d59385/screenshot.svg" alt="" width="900">
|
|
14
|
+
<img src="https://cdn.jsdelivr.net/gh/chalk/ansi-styles@8261697c95bf34b6c7767e2cbe9941a851d59385/screenshot.svg" width="900">
|
|
17
15
|
|
|
18
16
|
|
|
19
17
|
## Highlights
|
|
@@ -26,7 +24,7 @@
|
|
|
26
24
|
- Doesn't extend `String.prototype`
|
|
27
25
|
- Clean and focused
|
|
28
26
|
- Actively maintained
|
|
29
|
-
- [Used by ~
|
|
27
|
+
- [Used by ~46,000 packages](https://www.npmjs.com/browse/depended/chalk) as of October 1, 2019
|
|
30
28
|
|
|
31
29
|
|
|
32
30
|
## Install
|
|
@@ -35,10 +33,6 @@
|
|
|
35
33
|
$ npm install chalk
|
|
36
34
|
```
|
|
37
35
|
|
|
38
|
-
<a href="https://www.patreon.com/sindresorhus">
|
|
39
|
-
<img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" width="160">
|
|
40
|
-
</a>
|
|
41
|
-
|
|
42
36
|
|
|
43
37
|
## Usage
|
|
44
38
|
|
|
@@ -124,57 +118,51 @@ Chain [styles](#styles) and call the last one as a method with a string argument
|
|
|
124
118
|
|
|
125
119
|
Multiple arguments will be separated by space.
|
|
126
120
|
|
|
127
|
-
### chalk.enabled
|
|
128
|
-
|
|
129
|
-
Color support is automatically detected, as is the level (see `chalk.level`). However, if you'd like to simply enable/disable Chalk, you can do so via the `.enabled` property.
|
|
130
|
-
|
|
131
|
-
Chalk is enabled by default unless explicitly disabled via the constructor or `chalk.level` is `0`.
|
|
132
|
-
|
|
133
|
-
If you need to change this in a reusable module, create a new instance:
|
|
134
|
-
|
|
135
|
-
```js
|
|
136
|
-
const ctx = new chalk.constructor({enabled: false});
|
|
137
|
-
```
|
|
138
|
-
|
|
139
121
|
### chalk.level
|
|
140
122
|
|
|
123
|
+
Specifies the level of color support.
|
|
124
|
+
|
|
141
125
|
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.
|
|
142
126
|
|
|
143
127
|
If you need to change this in a reusable module, create a new instance:
|
|
144
128
|
|
|
145
129
|
```js
|
|
146
|
-
const ctx = new chalk.
|
|
130
|
+
const ctx = new chalk.Instance({level: 0});
|
|
147
131
|
```
|
|
148
132
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
0
|
|
152
|
-
1
|
|
153
|
-
2
|
|
154
|
-
3
|
|
133
|
+
| Level | Description |
|
|
134
|
+
| :---: | :--- |
|
|
135
|
+
| `0` | All colors disabled |
|
|
136
|
+
| `1` | Basic color support (16 colors) |
|
|
137
|
+
| `2` | 256 color support |
|
|
138
|
+
| `3` | Truecolor support (16 million colors) |
|
|
155
139
|
|
|
156
140
|
### chalk.supportsColor
|
|
157
141
|
|
|
158
142
|
Detect whether the terminal [supports color](https://github.com/chalk/supports-color). Used internally and handled for you, but exposed for convenience.
|
|
159
143
|
|
|
160
|
-
Can be overridden by the user with the flags `--color` and `--no-color`. For situations where using `--color` is not possible,
|
|
144
|
+
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.
|
|
161
145
|
|
|
162
146
|
Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
|
|
163
147
|
|
|
148
|
+
### chalk.stderr and chalk.stderr.supportsColor
|
|
149
|
+
|
|
150
|
+
`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.
|
|
151
|
+
|
|
164
152
|
|
|
165
153
|
## Styles
|
|
166
154
|
|
|
167
155
|
### Modifiers
|
|
168
156
|
|
|
169
|
-
- `reset`
|
|
170
|
-
- `bold`
|
|
171
|
-
- `dim`
|
|
172
|
-
- `italic` *(Not widely supported)*
|
|
173
|
-
- `underline`
|
|
174
|
-
- `inverse
|
|
175
|
-
- `hidden`
|
|
176
|
-
- `strikethrough` *(Not widely supported)*
|
|
177
|
-
- `visible
|
|
157
|
+
- `reset` - Resets the current color chain.
|
|
158
|
+
- `bold` - Make text bold.
|
|
159
|
+
- `dim` - Emitting only a small amount of light.
|
|
160
|
+
- `italic` - Make text italic. *(Not widely supported)*
|
|
161
|
+
- `underline` - Make text underline. *(Not widely supported)*
|
|
162
|
+
- `inverse`- Inverse background and foreground colors.
|
|
163
|
+
- `hidden` - Prints the text, but makes it invisible.
|
|
164
|
+
- `strikethrough` - Puts a horizontal line through the center of the text. *(Not widely supported)*
|
|
165
|
+
- `visible`- Prints the text only when Chalk has a color level > 0. Can be useful for things that are purely cosmetic.
|
|
178
166
|
|
|
179
167
|
### Colors
|
|
180
168
|
|
|
@@ -182,11 +170,11 @@ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=
|
|
|
182
170
|
- `red`
|
|
183
171
|
- `green`
|
|
184
172
|
- `yellow`
|
|
185
|
-
- `blue`
|
|
173
|
+
- `blue`
|
|
186
174
|
- `magenta`
|
|
187
175
|
- `cyan`
|
|
188
176
|
- `white`
|
|
189
|
-
- `
|
|
177
|
+
- `blackBright` (alias: `gray`, `grey`)
|
|
190
178
|
- `redBright`
|
|
191
179
|
- `greenBright`
|
|
192
180
|
- `yellowBright`
|
|
@@ -205,7 +193,7 @@ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=
|
|
|
205
193
|
- `bgMagenta`
|
|
206
194
|
- `bgCyan`
|
|
207
195
|
- `bgWhite`
|
|
208
|
-
- `bgBlackBright`
|
|
196
|
+
- `bgBlackBright` (alias: `bgGray`, `bgGrey`)
|
|
209
197
|
- `bgRedBright`
|
|
210
198
|
- `bgGreenBright`
|
|
211
199
|
- `bgYellowBright`
|
|
@@ -226,8 +214,8 @@ const miles = 18;
|
|
|
226
214
|
const calculateFeet = miles => miles * 5280;
|
|
227
215
|
|
|
228
216
|
console.log(chalk`
|
|
229
|
-
|
|
230
|
-
|
|
217
|
+
There are {bold 5280 feet} in a mile.
|
|
218
|
+
In {bold ${miles} miles}, there are {green.bold ${calculateFeet(miles)} feet}.
|
|
231
219
|
`);
|
|
232
220
|
```
|
|
233
221
|
|
|
@@ -270,14 +258,14 @@ The following color models can be used:
|
|
|
270
258
|
- [`keyword`](https://www.w3.org/wiki/CSS/Properties/color/keywords) (CSS keywords) - Example: `chalk.keyword('orange').bold('Orange!')`
|
|
271
259
|
- [`hsl`](https://en.wikipedia.org/wiki/HSL_and_HSV) - Example: `chalk.hsl(32, 100, 50).bold('Orange!')`
|
|
272
260
|
- [`hsv`](https://en.wikipedia.org/wiki/HSL_and_HSV) - Example: `chalk.hsv(32, 100, 100).bold('Orange!')`
|
|
273
|
-
- [`hwb`](https://en.wikipedia.org/wiki/HWB_color_model)
|
|
274
|
-
- `
|
|
275
|
-
- `ansi256`
|
|
261
|
+
- [`hwb`](https://en.wikipedia.org/wiki/HWB_color_model) - Example: `chalk.hwb(32, 0, 50).bold('Orange!')`
|
|
262
|
+
- [`ansi`](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) - Example: `chalk.ansi(31).bgAnsi(93)('red on yellowBright')`
|
|
263
|
+
- [`ansi256`](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) - Example: `chalk.bgAnsi256(194)('Honeydew, more or less')`
|
|
276
264
|
|
|
277
265
|
|
|
278
266
|
## Windows
|
|
279
267
|
|
|
280
|
-
If you're on Windows, do yourself a favor and use [
|
|
268
|
+
If you're on Windows, do yourself a favor and use [Windows Terminal](https://github.com/microsoft/terminal) instead of `cmd.exe`.
|
|
281
269
|
|
|
282
270
|
|
|
283
271
|
## Origin story
|
|
@@ -285,6 +273,13 @@ If you're on Windows, do yourself a favor and use [`cmder`](http://cmder.net/) i
|
|
|
285
273
|
[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.
|
|
286
274
|
|
|
287
275
|
|
|
276
|
+
## chalk for enterprise
|
|
277
|
+
|
|
278
|
+
Available as part of the Tidelift Subscription.
|
|
279
|
+
|
|
280
|
+
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)
|
|
281
|
+
|
|
282
|
+
|
|
288
283
|
## Related
|
|
289
284
|
|
|
290
285
|
- [chalk-cli](https://github.com/chalk/chalk-cli) - CLI for this module
|
|
@@ -307,8 +302,3 @@ If you're on Windows, do yourself a favor and use [`cmder`](http://cmder.net/) i
|
|
|
307
302
|
|
|
308
303
|
- [Sindre Sorhus](https://github.com/sindresorhus)
|
|
309
304
|
- [Josh Junon](https://github.com/qix-)
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
## License
|
|
313
|
-
|
|
314
|
-
MIT
|