chalk 5.0.0 → 5.1.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/package.json +7 -3
- package/readme.md +34 -14
- package/source/index.d.ts +12 -38
- package/source/index.js +5 -0
- package/source/utilities.js +2 -2
- package/source/vendor/ansi-styles/index.js +3 -3
- package/source/vendor/supports-color/browser.js +3 -1
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chalk",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "Terminal string styling done right",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "chalk/chalk",
|
|
7
7
|
"funding": "https://github.com/chalk/chalk?sponsor=1",
|
|
8
8
|
"type": "module",
|
|
9
|
+
"main": "./source/index.js",
|
|
9
10
|
"exports": "./source/index.js",
|
|
10
11
|
"imports": {
|
|
11
12
|
"#ansi-styles": "./source/vendor/ansi-styles/index.js",
|
|
@@ -57,12 +58,15 @@
|
|
|
57
58
|
"log-update": "^5.0.0",
|
|
58
59
|
"matcha": "^0.7.0",
|
|
59
60
|
"tsd": "^0.19.0",
|
|
60
|
-
"xo": "^0.
|
|
61
|
+
"xo": "^0.52.4",
|
|
61
62
|
"yoctodelay": "^2.0.0"
|
|
62
63
|
},
|
|
63
64
|
"xo": {
|
|
64
65
|
"rules": {
|
|
65
|
-
"unicorn/prefer-string-slice": "off"
|
|
66
|
+
"unicorn/prefer-string-slice": "off",
|
|
67
|
+
"@typescript-eslint/consistent-type-imports": "off",
|
|
68
|
+
"@typescript-eslint/consistent-type-exports": "off",
|
|
69
|
+
"@typescript-eslint/consistent-type-definitions": "off"
|
|
66
70
|
}
|
|
67
71
|
},
|
|
68
72
|
"c8": {
|
package/readme.md
CHANGED
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
> Terminal string styling done right
|
|
11
11
|
|
|
12
12
|
[](https://codecov.io/gh/chalk/chalk)
|
|
13
|
-
[](https://www.npmjs.com/package/chalk?activeTab=dependents)
|
|
14
|
-
[](https://www.npmjs.com/package/chalk?activeTab=dependents)
|
|
14
|
+
[](https://www.npmjs.com/package/chalk)
|
|
15
|
+
[](https://repl.it/github/chalk/chalk)
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+

|
|
18
18
|
|
|
19
19
|
<br>
|
|
20
20
|
|
|
@@ -24,19 +24,19 @@
|
|
|
24
24
|
<p>
|
|
25
25
|
<p>
|
|
26
26
|
<sup>
|
|
27
|
-
Sindre Sorhus' open source work is supported by the community on <a href="https://github.com/sponsors/sindresorhus">GitHub Sponsors</a>
|
|
27
|
+
Sindre Sorhus' open source work is supported by the community on <a href="https://github.com/sponsors/sindresorhus">GitHub Sponsors</a>
|
|
28
28
|
</sup>
|
|
29
29
|
</p>
|
|
30
30
|
<sup>Special thanks to:</sup>
|
|
31
31
|
<br>
|
|
32
32
|
<br>
|
|
33
33
|
<a href="https://standardresume.co/tech">
|
|
34
|
-
<img src="https://sindresorhus.com/assets/thanks/standard-resume-logo.svg" width="160"
|
|
34
|
+
<img src="https://sindresorhus.com/assets/thanks/standard-resume-logo.svg" width="160">
|
|
35
35
|
</a>
|
|
36
36
|
<br>
|
|
37
37
|
<br>
|
|
38
38
|
<a href="https://retool.com/?utm_campaign=sindresorhus">
|
|
39
|
-
<img src="https://sindresorhus.com/assets/thanks/retool-logo.svg" width="230"
|
|
39
|
+
<img src="https://sindresorhus.com/assets/thanks/retool-logo.svg" width="230">
|
|
40
40
|
</a>
|
|
41
41
|
<br>
|
|
42
42
|
<br>
|
|
@@ -61,6 +61,16 @@
|
|
|
61
61
|
<sup>It’s 100% JavaScript, fully customizable, and developer-first.</sup>
|
|
62
62
|
</div>
|
|
63
63
|
</a>
|
|
64
|
+
<br>
|
|
65
|
+
<br>
|
|
66
|
+
<a href="https://www.stackaid.us/?utm_campaign=sindre">
|
|
67
|
+
<div>
|
|
68
|
+
<img src="https://sindresorhus.com/assets/thanks/stackaid-logo.png" width="230" alt="StackAid">
|
|
69
|
+
</div>
|
|
70
|
+
<b>Fund your open source dependencies</b>
|
|
71
|
+
</a>
|
|
72
|
+
<br>
|
|
73
|
+
<br>
|
|
64
74
|
</p>
|
|
65
75
|
</div>
|
|
66
76
|
|
|
@@ -79,7 +89,7 @@
|
|
|
79
89
|
- Doesn't extend `String.prototype`
|
|
80
90
|
- Clean and focused
|
|
81
91
|
- Actively maintained
|
|
82
|
-
- [Used by ~
|
|
92
|
+
- [Used by ~86,000 packages](https://www.npmjs.com/browse/depended/chalk) as of October 4, 2022
|
|
83
93
|
|
|
84
94
|
## Install
|
|
85
95
|
|
|
@@ -200,6 +210,22 @@ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=
|
|
|
200
210
|
|
|
201
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.
|
|
202
212
|
|
|
213
|
+
### modifiers, foregroundColors, backgroundColors, and colors
|
|
214
|
+
|
|
215
|
+
All supported style strings are exposed as an array of strings for convenience. `colors` is the combination of `foregroundColors` and `backgroundColors`.
|
|
216
|
+
|
|
217
|
+
This can be useful if you wrap Chalk and need to validate input:
|
|
218
|
+
|
|
219
|
+
```js
|
|
220
|
+
import {modifiers, foregroundColors} from 'chalk';
|
|
221
|
+
|
|
222
|
+
console.log(modifiers.includes('bold'));
|
|
223
|
+
//=> true
|
|
224
|
+
|
|
225
|
+
console.log(foregroundColors.includes('pink'));
|
|
226
|
+
//=> false
|
|
227
|
+
```
|
|
228
|
+
|
|
203
229
|
## Styles
|
|
204
230
|
|
|
205
231
|
### Modifiers
|
|
@@ -287,12 +313,6 @@ If you're on Windows, do yourself a favor and use [Windows Terminal](https://git
|
|
|
287
313
|
|
|
288
314
|
[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.
|
|
289
315
|
|
|
290
|
-
## chalk for enterprise
|
|
291
|
-
|
|
292
|
-
Available as part of the Tidelift Subscription.
|
|
293
|
-
|
|
294
|
-
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)
|
|
295
|
-
|
|
296
316
|
## Related
|
|
297
317
|
|
|
298
318
|
- [chalk-template](https://github.com/chalk/chalk-template) - [Tagged template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates) support for this module
|
package/source/index.d.ts
CHANGED
|
@@ -2,55 +2,24 @@
|
|
|
2
2
|
// import {ColorInfo, ColorSupportLevel} from '#supports-color';
|
|
3
3
|
import {ColorInfo, ColorSupportLevel} from './vendor/supports-color/index.js';
|
|
4
4
|
|
|
5
|
+
type BasicColor = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white';
|
|
6
|
+
type BrightColor = `${BasicColor}Bright`;
|
|
7
|
+
type Grey = 'gray' | 'grey';
|
|
8
|
+
|
|
5
9
|
/**
|
|
6
10
|
Basic foreground colors.
|
|
7
11
|
|
|
8
12
|
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
|
9
13
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
| 'red'
|
|
13
|
-
| 'green'
|
|
14
|
-
| 'yellow'
|
|
15
|
-
| 'blue'
|
|
16
|
-
| 'magenta'
|
|
17
|
-
| 'cyan'
|
|
18
|
-
| 'white'
|
|
19
|
-
| 'gray'
|
|
20
|
-
| 'grey'
|
|
21
|
-
| 'blackBright'
|
|
22
|
-
| 'redBright'
|
|
23
|
-
| 'greenBright'
|
|
24
|
-
| 'yellowBright'
|
|
25
|
-
| 'blueBright'
|
|
26
|
-
| 'magentaBright'
|
|
27
|
-
| 'cyanBright'
|
|
28
|
-
| 'whiteBright';
|
|
14
|
+
|
|
15
|
+
export type ForegroundColor = BasicColor | BrightColor | Grey;
|
|
29
16
|
|
|
30
17
|
/**
|
|
31
18
|
Basic background colors.
|
|
32
19
|
|
|
33
20
|
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
|
34
21
|
*/
|
|
35
|
-
export type BackgroundColor =
|
|
36
|
-
| 'bgBlack'
|
|
37
|
-
| 'bgRed'
|
|
38
|
-
| 'bgGreen'
|
|
39
|
-
| 'bgYellow'
|
|
40
|
-
| 'bgBlue'
|
|
41
|
-
| 'bgMagenta'
|
|
42
|
-
| 'bgCyan'
|
|
43
|
-
| 'bgWhite'
|
|
44
|
-
| 'bgGray'
|
|
45
|
-
| 'bgGrey'
|
|
46
|
-
| 'bgBlackBright'
|
|
47
|
-
| 'bgRedBright'
|
|
48
|
-
| 'bgGreenBright'
|
|
49
|
-
| 'bgYellowBright'
|
|
50
|
-
| 'bgBlueBright'
|
|
51
|
-
| 'bgMagentaBright'
|
|
52
|
-
| 'bgCyanBright'
|
|
53
|
-
| 'bgWhiteBright';
|
|
22
|
+
export type BackgroundColor = `bg${Capitalize<ForegroundColor>}`;
|
|
54
23
|
|
|
55
24
|
/**
|
|
56
25
|
Basic colors.
|
|
@@ -315,4 +284,9 @@ export {
|
|
|
315
284
|
// } from '#supports-color';
|
|
316
285
|
} from './vendor/supports-color/index.js';
|
|
317
286
|
|
|
287
|
+
export const modifiers: readonly Modifiers[];
|
|
288
|
+
export const foregroundColors: readonly ForegroundColor[];
|
|
289
|
+
export const backgroundColors: readonly BackgroundColor[];
|
|
290
|
+
export const colors: readonly Color[];
|
|
291
|
+
|
|
318
292
|
export default chalk;
|
package/source/index.js
CHANGED
|
@@ -209,4 +209,9 @@ export {
|
|
|
209
209
|
stderrColor as supportsColorStderr,
|
|
210
210
|
};
|
|
211
211
|
|
|
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
|
+
|
|
212
217
|
export default chalk;
|
package/source/utilities.js
CHANGED
|
@@ -9,7 +9,7 @@ export function stringReplaceAll(string, substring, replacer) {
|
|
|
9
9
|
let endIndex = 0;
|
|
10
10
|
let returnValue = '';
|
|
11
11
|
do {
|
|
12
|
-
returnValue += string.
|
|
12
|
+
returnValue += string.slice(endIndex, index) + substring + replacer;
|
|
13
13
|
endIndex = index + substringLength;
|
|
14
14
|
index = string.indexOf(substring, endIndex);
|
|
15
15
|
} while (index !== -1);
|
|
@@ -23,7 +23,7 @@ export function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
|
|
|
23
23
|
let returnValue = '';
|
|
24
24
|
do {
|
|
25
25
|
const gotCR = string[index - 1] === '\r';
|
|
26
|
-
returnValue += string.
|
|
26
|
+
returnValue += string.slice(endIndex, (gotCR ? index - 1 : index)) + prefix + (gotCR ? '\r\n' : '\n') + postfix;
|
|
27
27
|
endIndex = index + 1;
|
|
28
28
|
index = string.indexOf('\n', endIndex);
|
|
29
29
|
} while (index !== -1);
|
|
@@ -105,7 +105,7 @@ function assembleStyles() {
|
|
|
105
105
|
// From https://github.com/Qix-/color-convert/blob/3f0e0d4e92e235796ccb17f6e85c72094a651f49/conversions.js
|
|
106
106
|
Object.defineProperties(styles, {
|
|
107
107
|
rgbToAnsi256: {
|
|
108
|
-
value
|
|
108
|
+
value(red, green, blue) {
|
|
109
109
|
// We use the extended greyscale palette here, with the exception of
|
|
110
110
|
// black and white. normal palette only has 4 greyscale shades.
|
|
111
111
|
if (red === green && green === blue) {
|
|
@@ -128,7 +128,7 @@ function assembleStyles() {
|
|
|
128
128
|
enumerable: false,
|
|
129
129
|
},
|
|
130
130
|
hexToRgb: {
|
|
131
|
-
value
|
|
131
|
+
value(hex) {
|
|
132
132
|
const matches = /(?<colorString>[a-f\d]{6}|[a-f\d]{3})/i.exec(hex.toString(16));
|
|
133
133
|
if (!matches) {
|
|
134
134
|
return [0, 0, 0];
|
|
@@ -157,7 +157,7 @@ function assembleStyles() {
|
|
|
157
157
|
enumerable: false,
|
|
158
158
|
},
|
|
159
159
|
ansi256ToAnsi: {
|
|
160
|
-
value
|
|
160
|
+
value(code) {
|
|
161
161
|
if (code < 8) {
|
|
162
162
|
return 30 + code;
|
|
163
163
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* eslint-env browser */
|
|
2
2
|
|
|
3
|
-
const isBlinkBasedBrowser =
|
|
3
|
+
const isBlinkBasedBrowser = navigator.userAgentData
|
|
4
|
+
? navigator.userAgentData.brands.some(({brand}) => brand === 'Chromium')
|
|
5
|
+
: /\b(Chrome|Chromium)\//.test(navigator.userAgent);
|
|
4
6
|
|
|
5
7
|
const colorSupport = isBlinkBasedBrowser ? {
|
|
6
8
|
level: 1,
|