ansi-styles 6.1.1 → 6.2.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 +46 -0
- package/index.js +64 -60
- package/package.json +1 -1
- package/readme.md +18 -0
package/index.d.ts
CHANGED
@@ -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;
|
package/index.js
CHANGED
@@ -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)) {
|
@@ -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];
|
package/package.json
CHANGED
package/readme.md
CHANGED
@@ -32,8 +32,26 @@ console.log(`${styles.color.ansi16m(...styles.hexToRgb('#abcdef'))}Hello World${
|
|
32
32
|
|
33
33
|
## API
|
34
34
|
|
35
|
+
### `open` and `close`
|
36
|
+
|
35
37
|
Each style has an `open` and `close` property.
|
36
38
|
|
39
|
+
### `modifierNames`, `foregroundColorNames`, `backgroundColorNames`, and `colorNames`
|
40
|
+
|
41
|
+
All supported style strings are exposed as an array of strings for convenience. `colorNames` is the combination of `foregroundColorNames` and `backgroundColorNames`.
|
42
|
+
|
43
|
+
This can be useful if you need to validate input:
|
44
|
+
|
45
|
+
```js
|
46
|
+
import {modifierNames, foregroundColorNames} from 'ansi-styles';
|
47
|
+
|
48
|
+
console.log(modifierNames.includes('bold'));
|
49
|
+
//=> true
|
50
|
+
|
51
|
+
console.log(foregroundColorNames.includes('pink'));
|
52
|
+
//=> false
|
53
|
+
```
|
54
|
+
|
37
55
|
## Styles
|
38
56
|
|
39
57
|
### Modifiers
|