chalk 2.2.0 → 2.3.2
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.js +15 -8
- package/package.json +4 -4
- package/readme.md +8 -7
- package/types/index.d.ts +71 -64
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
const escapeStringRegexp = require('escape-string-regexp');
|
|
3
3
|
const ansiStyles = require('ansi-styles');
|
|
4
|
-
const
|
|
4
|
+
const stdoutColor = require('supports-color').stdout;
|
|
5
5
|
|
|
6
6
|
const template = require('./templates.js');
|
|
7
7
|
|
|
@@ -19,7 +19,7 @@ function applyOptions(obj, options) {
|
|
|
19
19
|
options = options || {};
|
|
20
20
|
|
|
21
21
|
// Detect level if not set manually
|
|
22
|
-
const scLevel =
|
|
22
|
+
const scLevel = stdoutColor ? stdoutColor.level : 0;
|
|
23
23
|
obj.level = options.level === undefined ? scLevel : options.level;
|
|
24
24
|
obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
|
|
25
25
|
}
|
|
@@ -58,11 +58,17 @@ for (const key of Object.keys(ansiStyles)) {
|
|
|
58
58
|
styles[key] = {
|
|
59
59
|
get() {
|
|
60
60
|
const codes = ansiStyles[key];
|
|
61
|
-
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], key);
|
|
61
|
+
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
styles.visible = {
|
|
67
|
+
get() {
|
|
68
|
+
return build.call(this, this._styles || [], true, 'visible');
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
66
72
|
ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
|
|
67
73
|
for (const model of Object.keys(ansiStyles.color.ansi)) {
|
|
68
74
|
if (skipModels.has(model)) {
|
|
@@ -79,7 +85,7 @@ for (const model of Object.keys(ansiStyles.color.ansi)) {
|
|
|
79
85
|
close: ansiStyles.color.close,
|
|
80
86
|
closeRe: ansiStyles.color.closeRe
|
|
81
87
|
};
|
|
82
|
-
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], model);
|
|
88
|
+
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
|
|
83
89
|
};
|
|
84
90
|
}
|
|
85
91
|
};
|
|
@@ -102,7 +108,7 @@ for (const model of Object.keys(ansiStyles.bgColor.ansi)) {
|
|
|
102
108
|
close: ansiStyles.bgColor.close,
|
|
103
109
|
closeRe: ansiStyles.bgColor.closeRe
|
|
104
110
|
};
|
|
105
|
-
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], model);
|
|
111
|
+
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
|
|
106
112
|
};
|
|
107
113
|
}
|
|
108
114
|
};
|
|
@@ -110,12 +116,13 @@ for (const model of Object.keys(ansiStyles.bgColor.ansi)) {
|
|
|
110
116
|
|
|
111
117
|
const proto = Object.defineProperties(() => {}, styles);
|
|
112
118
|
|
|
113
|
-
function build(_styles, key) {
|
|
119
|
+
function build(_styles, _empty, key) {
|
|
114
120
|
const builder = function () {
|
|
115
121
|
return applyStyle.apply(builder, arguments);
|
|
116
122
|
};
|
|
117
123
|
|
|
118
124
|
builder._styles = _styles;
|
|
125
|
+
builder._empty = _empty;
|
|
119
126
|
|
|
120
127
|
const self = this;
|
|
121
128
|
|
|
@@ -167,7 +174,7 @@ function applyStyle() {
|
|
|
167
174
|
}
|
|
168
175
|
|
|
169
176
|
if (!this.enabled || this.level <= 0 || !str) {
|
|
170
|
-
return str;
|
|
177
|
+
return this._empty ? '' : str;
|
|
171
178
|
}
|
|
172
179
|
|
|
173
180
|
// Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
|
|
@@ -217,5 +224,5 @@ function chalkTag(chalk, strings) {
|
|
|
217
224
|
Object.defineProperties(Chalk.prototype, styles);
|
|
218
225
|
|
|
219
226
|
module.exports = Chalk(); // eslint-disable-line new-cap
|
|
220
|
-
module.exports.supportsColor =
|
|
227
|
+
module.exports.supportsColor = stdoutColor;
|
|
221
228
|
module.exports.default = module.exports; // For TypeScript
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chalk",
|
|
3
|
-
"version": "2.2
|
|
3
|
+
"version": "2.3.2",
|
|
4
4
|
"description": "Terminal string styling done right",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "chalk/chalk",
|
|
@@ -41,14 +41,14 @@
|
|
|
41
41
|
"text"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"ansi-styles": "^3.1
|
|
44
|
+
"ansi-styles": "^3.2.1",
|
|
45
45
|
"escape-string-regexp": "^1.0.5",
|
|
46
|
-
"supports-color": "^
|
|
46
|
+
"supports-color": "^5.3.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"ava": "*",
|
|
50
50
|
"coveralls": "^3.0.0",
|
|
51
|
-
"execa": "^0.
|
|
51
|
+
"execa": "^0.9.0",
|
|
52
52
|
"import-fresh": "^2.0.0",
|
|
53
53
|
"matcha": "^0.7.0",
|
|
54
54
|
"nyc": "^11.0.2",
|
package/readme.md
CHANGED
|
@@ -9,11 +9,11 @@
|
|
|
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/
|
|
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) [](https://github.com/sindresorhus/awesome-nodejs)
|
|
13
13
|
|
|
14
14
|
### [See what's new in Chalk 2](https://github.com/chalk/chalk/releases/tag/v2.0.0)
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
<img src="https://cdn.rawgit.com/chalk/ansi-styles/8261697c95bf34b6c7767e2cbe9941a851d59385/screenshot.svg" alt="" width="900">
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
## Highlights
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
- Doesn't extend `String.prototype`
|
|
27
27
|
- Clean and focused
|
|
28
28
|
- Actively maintained
|
|
29
|
-
- [Used by ~
|
|
29
|
+
- [Used by ~23,000 packages](https://www.npmjs.com/browse/depended/chalk) as of December 31, 2017
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
## Install
|
|
@@ -51,7 +51,7 @@ const chalk = require('chalk');
|
|
|
51
51
|
const log = console.log;
|
|
52
52
|
|
|
53
53
|
// Combine styled and normal strings
|
|
54
|
-
log(chalk.blue('Hello') + 'World' + chalk.red('!'));
|
|
54
|
+
log(chalk.blue('Hello') + ' World' + chalk.red('!'));
|
|
55
55
|
|
|
56
56
|
// Compose multiple styles using the chainable API
|
|
57
57
|
log(chalk.blue.bgRed.bold('Hello world!'));
|
|
@@ -124,7 +124,7 @@ Multiple arguments will be separated by space.
|
|
|
124
124
|
|
|
125
125
|
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.
|
|
126
126
|
|
|
127
|
-
Chalk is enabled by default unless
|
|
127
|
+
Chalk is enabled by default unless explicitly disabled via the constructor or `chalk.level` is `0`.
|
|
128
128
|
|
|
129
129
|
If you need to change this in a reusable module, create a new instance:
|
|
130
130
|
|
|
@@ -170,6 +170,7 @@ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=
|
|
|
170
170
|
- `inverse`
|
|
171
171
|
- `hidden`
|
|
172
172
|
- `strikethrough` *(Not widely supported)*
|
|
173
|
+
- `visible` (Text is emitted only if enabled)
|
|
173
174
|
|
|
174
175
|
### Colors
|
|
175
176
|
|
|
@@ -264,8 +265,8 @@ The following color models can be used:
|
|
|
264
265
|
- [`hex`](https://en.wikipedia.org/wiki/Web_colors#Hex_triplet) - Example: `chalk.hex('#FF8800').bold('Orange!')`
|
|
265
266
|
- [`keyword`](https://www.w3.org/wiki/CSS/Properties/color/keywords) (CSS keywords) - Example: `chalk.keyword('orange').bold('Orange!')`
|
|
266
267
|
- [`hsl`](https://en.wikipedia.org/wiki/HSL_and_HSV) - Example: `chalk.hsl(32, 100, 50).bold('Orange!')`
|
|
267
|
-
- [`hsv`](https://en.wikipedia.org/wiki/HSL_and_HSV) - Example: `chalk.
|
|
268
|
-
- [`hwb`](https://en.wikipedia.org/wiki/HWB_color_model) - Example: `chalk.
|
|
268
|
+
- [`hsv`](https://en.wikipedia.org/wiki/HSL_and_HSV) - Example: `chalk.hsv(32, 100, 100).bold('Orange!')`
|
|
269
|
+
- [`hwb`](https://en.wikipedia.org/wiki/HWB_color_model) - Example: `chalk.hwb(32, 0, 50).bold('Orange!')`
|
|
269
270
|
- `ansi16`
|
|
270
271
|
- `ansi256`
|
|
271
272
|
|
package/types/index.d.ts
CHANGED
|
@@ -13,78 +13,85 @@ export interface ChalkOptions {
|
|
|
13
13
|
level?: Level;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export interface
|
|
16
|
+
export interface ChalkConstructor {
|
|
17
17
|
new (options?: ChalkOptions): Chalk;
|
|
18
18
|
(options?: ChalkOptions): Chalk;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ColorSupport {
|
|
22
|
+
level: Level;
|
|
23
|
+
hasBasic: boolean;
|
|
24
|
+
has256: boolean;
|
|
25
|
+
has16m: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface Chalk {
|
|
19
29
|
(...text: string[]): string;
|
|
20
30
|
(text: TemplateStringsArray, ...placeholders: string[]): string;
|
|
21
|
-
constructor:
|
|
31
|
+
constructor: ChalkConstructor;
|
|
22
32
|
enabled: boolean;
|
|
23
33
|
level: Level;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
bgRgb(r: number, g: number, b: number): Chalk;
|
|
37
|
-
bgHsl(h: number, s: number, l: number): Chalk;
|
|
38
|
-
bgHsv(h: number, s: number, v: number): Chalk;
|
|
39
|
-
bgHwb(h: number, w: number, b: number): Chalk;
|
|
40
|
-
hex(color: string): Chalk;
|
|
41
|
-
keyword(color: string): Chalk;
|
|
34
|
+
rgb(r: number, g: number, b: number): this;
|
|
35
|
+
hsl(h: number, s: number, l: number): this;
|
|
36
|
+
hsv(h: number, s: number, v: number): this;
|
|
37
|
+
hwb(h: number, w: number, b: number): this;
|
|
38
|
+
bgHex(color: string): this;
|
|
39
|
+
bgKeyword(color: string): this;
|
|
40
|
+
bgRgb(r: number, g: number, b: number): this;
|
|
41
|
+
bgHsl(h: number, s: number, l: number): this;
|
|
42
|
+
bgHsv(h: number, s: number, v: number): this;
|
|
43
|
+
bgHwb(h: number, w: number, b: number): this;
|
|
44
|
+
hex(color: string): this;
|
|
45
|
+
keyword(color: string): this;
|
|
42
46
|
|
|
43
|
-
reset:
|
|
44
|
-
bold:
|
|
45
|
-
dim:
|
|
46
|
-
italic:
|
|
47
|
-
underline:
|
|
48
|
-
inverse:
|
|
49
|
-
hidden:
|
|
50
|
-
strikethrough:
|
|
47
|
+
readonly reset: this;
|
|
48
|
+
readonly bold: this;
|
|
49
|
+
readonly dim: this;
|
|
50
|
+
readonly italic: this;
|
|
51
|
+
readonly underline: this;
|
|
52
|
+
readonly inverse: this;
|
|
53
|
+
readonly hidden: this;
|
|
54
|
+
readonly strikethrough: this;
|
|
51
55
|
|
|
52
|
-
|
|
53
|
-
red: Chalk;
|
|
54
|
-
green: Chalk;
|
|
55
|
-
yellow: Chalk;
|
|
56
|
-
blue: Chalk;
|
|
57
|
-
magenta: Chalk;
|
|
58
|
-
cyan: Chalk;
|
|
59
|
-
white: Chalk;
|
|
60
|
-
gray: Chalk;
|
|
61
|
-
grey: Chalk;
|
|
62
|
-
blackBright: Chalk;
|
|
63
|
-
redBright: Chalk;
|
|
64
|
-
greenBright: Chalk;
|
|
65
|
-
yellowBright: Chalk;
|
|
66
|
-
blueBright: Chalk;
|
|
67
|
-
magentaBright: Chalk;
|
|
68
|
-
cyanBright: Chalk;
|
|
69
|
-
whiteBright: Chalk;
|
|
56
|
+
readonly visible: this;
|
|
70
57
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
58
|
+
readonly black: this;
|
|
59
|
+
readonly red: this;
|
|
60
|
+
readonly green: this;
|
|
61
|
+
readonly yellow: this;
|
|
62
|
+
readonly blue: this;
|
|
63
|
+
readonly magenta: this;
|
|
64
|
+
readonly cyan: this;
|
|
65
|
+
readonly white: this;
|
|
66
|
+
readonly gray: this;
|
|
67
|
+
readonly grey: this;
|
|
68
|
+
readonly blackBright: this;
|
|
69
|
+
readonly redBright: this;
|
|
70
|
+
readonly greenBright: this;
|
|
71
|
+
readonly yellowBright: this;
|
|
72
|
+
readonly blueBright: this;
|
|
73
|
+
readonly magentaBright: this;
|
|
74
|
+
readonly cyanBright: this;
|
|
75
|
+
readonly whiteBright: this;
|
|
76
|
+
|
|
77
|
+
readonly bgBlack: this;
|
|
78
|
+
readonly bgRed: this;
|
|
79
|
+
readonly bgGreen: this;
|
|
80
|
+
readonly bgYellow: this;
|
|
81
|
+
readonly bgBlue: this;
|
|
82
|
+
readonly bgMagenta: this;
|
|
83
|
+
readonly bgCyan: this;
|
|
84
|
+
readonly bgWhite: this;
|
|
85
|
+
readonly bgBlackBright: this;
|
|
86
|
+
readonly bgRedBright: this;
|
|
87
|
+
readonly bgGreenBright: this;
|
|
88
|
+
readonly bgYellowBright: this;
|
|
89
|
+
readonly bgBlueBright: this;
|
|
90
|
+
readonly bgMagentaBright: this;
|
|
91
|
+
readonly bgCyanBright: this;
|
|
92
|
+
readonly bgWhiteBright: this;
|
|
87
93
|
}
|
|
88
94
|
|
|
89
|
-
declare
|
|
90
|
-
|
|
95
|
+
declare const chalk: Chalk & { supportsColor: ColorSupport };
|
|
96
|
+
|
|
97
|
+
export default chalk
|