chalk 5.1.0 → 5.1.1
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/package.json +1 -1
- package/readme.md +5 -5
- package/source/index.d.ts +66 -38
- package/source/index.js +13 -5
- package/source/vendor/ansi-styles/index.d.ts +46 -0
- package/source/vendor/ansi-styles/index.js +66 -62
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -210,19 +210,19 @@ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=
|
|
|
210
210
|
|
|
211
211
|
`chalkStderr` contains a separate instance configured with color support detected for `stderr` stream instead of `stdout`. Override rules from `supportsColor` apply to this too. `supportsColorStderr` is exposed for convenience.
|
|
212
212
|
|
|
213
|
-
###
|
|
213
|
+
### modifierNames, foregroundColorNames, backgroundColorNames, and colorNames
|
|
214
214
|
|
|
215
|
-
All supported style strings are exposed as an array of strings for convenience. `
|
|
215
|
+
All supported style strings are exposed as an array of strings for convenience. `colorNames` is the combination of `foregroundColorNames` and `backgroundColorNames`.
|
|
216
216
|
|
|
217
217
|
This can be useful if you wrap Chalk and need to validate input:
|
|
218
218
|
|
|
219
219
|
```js
|
|
220
|
-
import {
|
|
220
|
+
import {modifierNames, foregroundColorNames} from 'chalk';
|
|
221
221
|
|
|
222
|
-
console.log(
|
|
222
|
+
console.log(modifierNames.includes('bold'));
|
|
223
223
|
//=> true
|
|
224
224
|
|
|
225
|
-
console.log(
|
|
225
|
+
console.log(foregroundColorNames.includes('pink'));
|
|
226
226
|
//=> false
|
|
227
227
|
```
|
|
228
228
|
|
package/source/index.d.ts
CHANGED
|
@@ -1,45 +1,9 @@
|
|
|
1
1
|
// TODO: Make it this when TS suports that.
|
|
2
|
+
// import {ModifierName, ForegroundColor, BackgroundColor, ColorName} from '#ansi-styles';
|
|
2
3
|
// import {ColorInfo, ColorSupportLevel} from '#supports-color';
|
|
4
|
+
import {ModifierName, ForegroundColorName, BackgroundColorName, ColorName} from './vendor/ansi-styles/index.js';
|
|
3
5
|
import {ColorInfo, ColorSupportLevel} from './vendor/supports-color/index.js';
|
|
4
6
|
|
|
5
|
-
type BasicColor = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white';
|
|
6
|
-
type BrightColor = `${BasicColor}Bright`;
|
|
7
|
-
type Grey = 'gray' | 'grey';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
Basic foreground colors.
|
|
11
|
-
|
|
12
|
-
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
export type ForegroundColor = BasicColor | BrightColor | Grey;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
Basic background colors.
|
|
19
|
-
|
|
20
|
-
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
|
21
|
-
*/
|
|
22
|
-
export type BackgroundColor = `bg${Capitalize<ForegroundColor>}`;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
Basic colors.
|
|
26
|
-
|
|
27
|
-
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
|
28
|
-
*/
|
|
29
|
-
export type Color = ForegroundColor | BackgroundColor;
|
|
30
|
-
|
|
31
|
-
export type Modifiers =
|
|
32
|
-
| 'reset'
|
|
33
|
-
| 'bold'
|
|
34
|
-
| 'dim'
|
|
35
|
-
| 'italic'
|
|
36
|
-
| 'underline'
|
|
37
|
-
| 'overline'
|
|
38
|
-
| 'inverse'
|
|
39
|
-
| 'hidden'
|
|
40
|
-
| 'strikethrough'
|
|
41
|
-
| 'visible';
|
|
42
|
-
|
|
43
7
|
export interface Options {
|
|
44
8
|
/**
|
|
45
9
|
Specify the color support for Chalk.
|
|
@@ -277,6 +241,12 @@ export const supportsColor: ColorInfo;
|
|
|
277
241
|
export const chalkStderr: typeof chalk;
|
|
278
242
|
export const supportsColorStderr: typeof supportsColor;
|
|
279
243
|
|
|
244
|
+
export {
|
|
245
|
+
ModifierName, ForegroundColorName, BackgroundColorName, ColorName,
|
|
246
|
+
modifierNames, foregroundColorNames, backgroundColorNames, colorNames,
|
|
247
|
+
// } from '#ansi-styles';
|
|
248
|
+
} from './vendor/ansi-styles/index.js';
|
|
249
|
+
|
|
280
250
|
export {
|
|
281
251
|
ColorInfo,
|
|
282
252
|
ColorSupport,
|
|
@@ -284,9 +254,67 @@ export {
|
|
|
284
254
|
// } from '#supports-color';
|
|
285
255
|
} from './vendor/supports-color/index.js';
|
|
286
256
|
|
|
257
|
+
// TODO: Remove these aliases in the next major version
|
|
258
|
+
/**
|
|
259
|
+
@deprecated Use `ModifierName` instead.
|
|
260
|
+
|
|
261
|
+
Basic modifier names.
|
|
262
|
+
*/
|
|
263
|
+
export type Modifiers = ModifierName;
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
@deprecated Use `ForegroundColorName` instead.
|
|
267
|
+
|
|
268
|
+
Basic foreground color names.
|
|
269
|
+
|
|
270
|
+
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
|
271
|
+
*/
|
|
272
|
+
export type ForegroundColor = ForegroundColorName;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
@deprecated Use `BackgroundColorName` instead.
|
|
276
|
+
|
|
277
|
+
Basic background color names.
|
|
278
|
+
|
|
279
|
+
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
|
280
|
+
*/
|
|
281
|
+
export type BackgroundColor = BackgroundColorName;
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
@deprecated Use `ColorName` instead.
|
|
285
|
+
|
|
286
|
+
Basic color names. The combination of foreground and background color names.
|
|
287
|
+
|
|
288
|
+
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
|
289
|
+
*/
|
|
290
|
+
export type Color = ColorName;
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
@deprecated Use `modifierNames` instead.
|
|
294
|
+
|
|
295
|
+
Basic modifier names.
|
|
296
|
+
*/
|
|
287
297
|
export const modifiers: readonly Modifiers[];
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
@deprecated Use `foregroundColorNames` instead.
|
|
301
|
+
|
|
302
|
+
Basic foreground color names.
|
|
303
|
+
*/
|
|
288
304
|
export const foregroundColors: readonly ForegroundColor[];
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
@deprecated Use `backgroundColorNames` instead.
|
|
308
|
+
|
|
309
|
+
Basic background color names.
|
|
310
|
+
*/
|
|
289
311
|
export const backgroundColors: readonly BackgroundColor[];
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
@deprecated Use `colorNames` instead.
|
|
315
|
+
|
|
316
|
+
Basic color names. The combination of foreground and background color names.
|
|
317
|
+
*/
|
|
290
318
|
export const colors: readonly Color[];
|
|
291
319
|
|
|
292
320
|
export default chalk;
|
package/source/index.js
CHANGED
|
@@ -204,14 +204,22 @@ Object.defineProperties(createChalk.prototype, styles);
|
|
|
204
204
|
const chalk = createChalk();
|
|
205
205
|
export const chalkStderr = createChalk({level: stderrColor ? stderrColor.level : 0});
|
|
206
206
|
|
|
207
|
+
export {
|
|
208
|
+
modifierNames,
|
|
209
|
+
foregroundColorNames,
|
|
210
|
+
backgroundColorNames,
|
|
211
|
+
colorNames,
|
|
212
|
+
|
|
213
|
+
// TODO: Remove these aliases in the next major version
|
|
214
|
+
modifierNames as modifiers,
|
|
215
|
+
foregroundColorNames as foregroundColors,
|
|
216
|
+
backgroundColorNames as backgroundColors,
|
|
217
|
+
colorNames as colors,
|
|
218
|
+
} from './vendor/ansi-styles/index.js';
|
|
219
|
+
|
|
207
220
|
export {
|
|
208
221
|
stdoutColor as supportsColor,
|
|
209
222
|
stderrColor as supportsColorStderr,
|
|
210
223
|
};
|
|
211
224
|
|
|
212
|
-
export const modifiers = Object.keys(ansiStyles.modifier);
|
|
213
|
-
export const foregroundColors = Object.keys(ansiStyles.color);
|
|
214
|
-
export const backgroundColors = Object.keys(ansiStyles.bgColor);
|
|
215
|
-
export const colors = [...foregroundColors, ...backgroundColors];
|
|
216
|
-
|
|
217
225
|
export default chalk;
|
|
@@ -180,6 +180,52 @@ export interface ConvertColor {
|
|
|
180
180
|
hexToAnsi(hex: string): number;
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
+
/**
|
|
184
|
+
Basic modifier names.
|
|
185
|
+
*/
|
|
186
|
+
export type ModifierName = keyof Modifier;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
Basic foreground color names.
|
|
190
|
+
|
|
191
|
+
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
|
192
|
+
*/
|
|
193
|
+
export type ForegroundColorName = keyof ForegroundColor;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
Basic background color names.
|
|
197
|
+
|
|
198
|
+
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
|
199
|
+
*/
|
|
200
|
+
export type BackgroundColorName = keyof BackgroundColor;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
Basic color names. The combination of foreground and background color names.
|
|
204
|
+
|
|
205
|
+
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
|
206
|
+
*/
|
|
207
|
+
export type ColorName = ForegroundColorName | BackgroundColorName;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
Basic modifier names.
|
|
211
|
+
*/
|
|
212
|
+
export const modifierNames: readonly ModifierName[];
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
Basic foreground color names.
|
|
216
|
+
*/
|
|
217
|
+
export const foregroundColorNames: readonly ForegroundColorName[];
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
Basic background color names.
|
|
221
|
+
*/
|
|
222
|
+
export const backgroundColorNames: readonly BackgroundColorName[];
|
|
223
|
+
|
|
224
|
+
/*
|
|
225
|
+
Basic color names. The combination of foreground and background color names.
|
|
226
|
+
*/
|
|
227
|
+
export const colorNames: readonly ColorName[];
|
|
228
|
+
|
|
183
229
|
declare const ansiStyles: {
|
|
184
230
|
readonly modifier: Modifier;
|
|
185
231
|
readonly color: ColorBase & ForegroundColor;
|
|
@@ -6,68 +6,67 @@ const wrapAnsi256 = (offset = 0) => code => `\u001B[${38 + offset};5;${code}m`;
|
|
|
6
6
|
|
|
7
7
|
const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u001B[${38 + offset};2;${red};${green};${blue}m`;
|
|
8
8
|
|
|
9
|
+
const styles = {
|
|
10
|
+
modifier: {
|
|
11
|
+
reset: [0, 0],
|
|
12
|
+
// 21 isn't widely supported and 22 does the same thing
|
|
13
|
+
bold: [1, 22],
|
|
14
|
+
dim: [2, 22],
|
|
15
|
+
italic: [3, 23],
|
|
16
|
+
underline: [4, 24],
|
|
17
|
+
overline: [53, 55],
|
|
18
|
+
inverse: [7, 27],
|
|
19
|
+
hidden: [8, 28],
|
|
20
|
+
strikethrough: [9, 29],
|
|
21
|
+
},
|
|
22
|
+
color: {
|
|
23
|
+
black: [30, 39],
|
|
24
|
+
red: [31, 39],
|
|
25
|
+
green: [32, 39],
|
|
26
|
+
yellow: [33, 39],
|
|
27
|
+
blue: [34, 39],
|
|
28
|
+
magenta: [35, 39],
|
|
29
|
+
cyan: [36, 39],
|
|
30
|
+
white: [37, 39],
|
|
31
|
+
|
|
32
|
+
// Bright color
|
|
33
|
+
blackBright: [90, 39],
|
|
34
|
+
gray: [90, 39], // Alias of `blackBright`
|
|
35
|
+
grey: [90, 39], // Alias of `blackBright`
|
|
36
|
+
redBright: [91, 39],
|
|
37
|
+
greenBright: [92, 39],
|
|
38
|
+
yellowBright: [93, 39],
|
|
39
|
+
blueBright: [94, 39],
|
|
40
|
+
magentaBright: [95, 39],
|
|
41
|
+
cyanBright: [96, 39],
|
|
42
|
+
whiteBright: [97, 39],
|
|
43
|
+
},
|
|
44
|
+
bgColor: {
|
|
45
|
+
bgBlack: [40, 49],
|
|
46
|
+
bgRed: [41, 49],
|
|
47
|
+
bgGreen: [42, 49],
|
|
48
|
+
bgYellow: [43, 49],
|
|
49
|
+
bgBlue: [44, 49],
|
|
50
|
+
bgMagenta: [45, 49],
|
|
51
|
+
bgCyan: [46, 49],
|
|
52
|
+
bgWhite: [47, 49],
|
|
53
|
+
|
|
54
|
+
// Bright color
|
|
55
|
+
bgBlackBright: [100, 49],
|
|
56
|
+
bgGray: [100, 49], // Alias of `bgBlackBright`
|
|
57
|
+
bgGrey: [100, 49], // Alias of `bgBlackBright`
|
|
58
|
+
bgRedBright: [101, 49],
|
|
59
|
+
bgGreenBright: [102, 49],
|
|
60
|
+
bgYellowBright: [103, 49],
|
|
61
|
+
bgBlueBright: [104, 49],
|
|
62
|
+
bgMagentaBright: [105, 49],
|
|
63
|
+
bgCyanBright: [106, 49],
|
|
64
|
+
bgWhiteBright: [107, 49],
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
9
68
|
function assembleStyles() {
|
|
10
69
|
const codes = new Map();
|
|
11
|
-
const styles = {
|
|
12
|
-
modifier: {
|
|
13
|
-
reset: [0, 0],
|
|
14
|
-
// 21 isn't widely supported and 22 does the same thing
|
|
15
|
-
bold: [1, 22],
|
|
16
|
-
dim: [2, 22],
|
|
17
|
-
italic: [3, 23],
|
|
18
|
-
underline: [4, 24],
|
|
19
|
-
overline: [53, 55],
|
|
20
|
-
inverse: [7, 27],
|
|
21
|
-
hidden: [8, 28],
|
|
22
|
-
strikethrough: [9, 29],
|
|
23
|
-
},
|
|
24
|
-
color: {
|
|
25
|
-
black: [30, 39],
|
|
26
|
-
red: [31, 39],
|
|
27
|
-
green: [32, 39],
|
|
28
|
-
yellow: [33, 39],
|
|
29
|
-
blue: [34, 39],
|
|
30
|
-
magenta: [35, 39],
|
|
31
|
-
cyan: [36, 39],
|
|
32
|
-
white: [37, 39],
|
|
33
|
-
|
|
34
|
-
// Bright color
|
|
35
|
-
blackBright: [90, 39],
|
|
36
|
-
redBright: [91, 39],
|
|
37
|
-
greenBright: [92, 39],
|
|
38
|
-
yellowBright: [93, 39],
|
|
39
|
-
blueBright: [94, 39],
|
|
40
|
-
magentaBright: [95, 39],
|
|
41
|
-
cyanBright: [96, 39],
|
|
42
|
-
whiteBright: [97, 39],
|
|
43
|
-
},
|
|
44
|
-
bgColor: {
|
|
45
|
-
bgBlack: [40, 49],
|
|
46
|
-
bgRed: [41, 49],
|
|
47
|
-
bgGreen: [42, 49],
|
|
48
|
-
bgYellow: [43, 49],
|
|
49
|
-
bgBlue: [44, 49],
|
|
50
|
-
bgMagenta: [45, 49],
|
|
51
|
-
bgCyan: [46, 49],
|
|
52
|
-
bgWhite: [47, 49],
|
|
53
|
-
|
|
54
|
-
// Bright color
|
|
55
|
-
bgBlackBright: [100, 49],
|
|
56
|
-
bgRedBright: [101, 49],
|
|
57
|
-
bgGreenBright: [102, 49],
|
|
58
|
-
bgYellowBright: [103, 49],
|
|
59
|
-
bgBlueBright: [104, 49],
|
|
60
|
-
bgMagentaBright: [105, 49],
|
|
61
|
-
bgCyanBright: [106, 49],
|
|
62
|
-
bgWhiteBright: [107, 49],
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
// Alias bright black as gray (and grey)
|
|
67
|
-
styles.color.gray = styles.color.blackBright;
|
|
68
|
-
styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
|
|
69
|
-
styles.color.grey = styles.color.blackBright;
|
|
70
|
-
styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
|
|
71
70
|
|
|
72
71
|
for (const [groupName, group] of Object.entries(styles)) {
|
|
73
72
|
for (const [styleName, style] of Object.entries(group)) {
|
|
@@ -129,12 +128,12 @@ function assembleStyles() {
|
|
|
129
128
|
},
|
|
130
129
|
hexToRgb: {
|
|
131
130
|
value(hex) {
|
|
132
|
-
const matches = /
|
|
131
|
+
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
|
|
133
132
|
if (!matches) {
|
|
134
133
|
return [0, 0, 0];
|
|
135
134
|
}
|
|
136
135
|
|
|
137
|
-
let
|
|
136
|
+
let [colorString] = matches;
|
|
138
137
|
|
|
139
138
|
if (colorString.length === 3) {
|
|
140
139
|
colorString = [...colorString].map(character => character + character).join('');
|
|
@@ -217,3 +216,8 @@ function assembleStyles() {
|
|
|
217
216
|
const ansiStyles = assembleStyles();
|
|
218
217
|
|
|
219
218
|
export default ansiStyles;
|
|
219
|
+
|
|
220
|
+
export const modifierNames = Object.keys(styles.modifier);
|
|
221
|
+
export const foregroundColorNames = Object.keys(styles.color);
|
|
222
|
+
export const backgroundColorNames = Object.keys(styles.bgColor);
|
|
223
|
+
export const colorNames = [...foregroundColorNames, ...backgroundColorNames];
|