chalk 2.1.0 → 2.3.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/index.js +16 -8
- package/package.json +11 -8
- package/readme.md +10 -7
- package/templates.js +16 -16
- package/types/index.d.ts +97 -0
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,4 +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;
|
|
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.1
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"description": "Terminal string styling done right",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "chalk/chalk",
|
|
@@ -8,13 +8,14 @@
|
|
|
8
8
|
"node": ">=4"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
-
"test": "xo && nyc ava",
|
|
11
|
+
"test": "xo && tsc --project types && nyc ava",
|
|
12
12
|
"bench": "matcha benchmark.js",
|
|
13
13
|
"coveralls": "nyc report --reporter=text-lcov | coveralls"
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
16
|
"index.js",
|
|
17
|
-
"templates.js"
|
|
17
|
+
"templates.js",
|
|
18
|
+
"types/index.d.ts"
|
|
18
19
|
],
|
|
19
20
|
"keywords": [
|
|
20
21
|
"color",
|
|
@@ -40,20 +41,22 @@
|
|
|
40
41
|
"text"
|
|
41
42
|
],
|
|
42
43
|
"dependencies": {
|
|
43
|
-
"ansi-styles": "^3.
|
|
44
|
+
"ansi-styles": "^3.2.0",
|
|
44
45
|
"escape-string-regexp": "^1.0.5",
|
|
45
|
-
"supports-color": "^
|
|
46
|
+
"supports-color": "^5.2.0"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
49
|
"ava": "*",
|
|
49
|
-
"coveralls": "^
|
|
50
|
-
"execa": "^0.
|
|
50
|
+
"coveralls": "^3.0.0",
|
|
51
|
+
"execa": "^0.9.0",
|
|
51
52
|
"import-fresh": "^2.0.0",
|
|
52
53
|
"matcha": "^0.7.0",
|
|
53
54
|
"nyc": "^11.0.2",
|
|
54
|
-
"resolve-from": "^
|
|
55
|
+
"resolve-from": "^4.0.0",
|
|
56
|
+
"typescript": "^2.5.3",
|
|
55
57
|
"xo": "*"
|
|
56
58
|
},
|
|
59
|
+
"types": "types/index.d.ts",
|
|
57
60
|
"xo": {
|
|
58
61
|
"envs": [
|
|
59
62
|
"node",
|
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/sindresorhus/xo)
|
|
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/sindresorhus/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
|
|
|
@@ -286,6 +287,7 @@ If you're on Windows, do yourself a favor and use [`cmder`](http://cmder.net/) i
|
|
|
286
287
|
- [ansi-styles](https://github.com/chalk/ansi-styles) - ANSI escape codes for styling strings in the terminal
|
|
287
288
|
- [supports-color](https://github.com/chalk/supports-color) - Detect whether a terminal supports color
|
|
288
289
|
- [strip-ansi](https://github.com/chalk/strip-ansi) - Strip ANSI escape codes
|
|
290
|
+
- [strip-ansi-stream](https://github.com/chalk/strip-ansi-stream) - Strip ANSI escape codes from a stream
|
|
289
291
|
- [has-ansi](https://github.com/chalk/has-ansi) - Check if a string has ANSI escape codes
|
|
290
292
|
- [ansi-regex](https://github.com/chalk/ansi-regex) - Regular expression for matching ANSI escape codes
|
|
291
293
|
- [wrap-ansi](https://github.com/chalk/wrap-ansi) - Wordwrap a string with ANSI escape codes
|
|
@@ -293,6 +295,7 @@ If you're on Windows, do yourself a favor and use [`cmder`](http://cmder.net/) i
|
|
|
293
295
|
- [color-convert](https://github.com/qix-/color-convert) - Converts colors between different models
|
|
294
296
|
- [chalk-animation](https://github.com/bokub/chalk-animation) - Animate strings in the terminal
|
|
295
297
|
- [gradient-string](https://github.com/bokub/gradient-string) - Apply color gradients to strings
|
|
298
|
+
- [chalk-pipe](https://github.com/LitoMore/chalk-pipe) - Create chalk style schemes with simpler style strings
|
|
296
299
|
|
|
297
300
|
|
|
298
301
|
## Maintainers
|
package/templates.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const TEMPLATE_REGEX = /(?:\\(u[a-
|
|
2
|
+
const TEMPLATE_REGEX = /(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
|
|
3
3
|
const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
|
|
4
4
|
const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
|
|
5
|
-
const ESCAPE_REGEX = /\\(u[
|
|
6
|
-
|
|
7
|
-
const ESCAPES =
|
|
8
|
-
n
|
|
9
|
-
r
|
|
10
|
-
t
|
|
11
|
-
b
|
|
12
|
-
f
|
|
13
|
-
v
|
|
14
|
-
0
|
|
15
|
-
'\\'
|
|
16
|
-
e
|
|
17
|
-
a
|
|
18
|
-
|
|
5
|
+
const ESCAPE_REGEX = /\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi;
|
|
6
|
+
|
|
7
|
+
const ESCAPES = new Map([
|
|
8
|
+
['n', '\n'],
|
|
9
|
+
['r', '\r'],
|
|
10
|
+
['t', '\t'],
|
|
11
|
+
['b', '\b'],
|
|
12
|
+
['f', '\f'],
|
|
13
|
+
['v', '\v'],
|
|
14
|
+
['0', '\0'],
|
|
15
|
+
['\\', '\\'],
|
|
16
|
+
['e', '\u001B'],
|
|
17
|
+
['a', '\u0007']
|
|
18
|
+
]);
|
|
19
19
|
|
|
20
20
|
function unescape(c) {
|
|
21
21
|
if ((c[0] === 'u' && c.length === 5) || (c[0] === 'x' && c.length === 3)) {
|
|
22
22
|
return String.fromCharCode(parseInt(c.slice(1), 16));
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
return ESCAPES
|
|
25
|
+
return ESCAPES.get(c) || c;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
function parseArguments(name, args) {
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Type definitions for Chalk
|
|
2
|
+
// Definitions by: Thomas Sauer <https://github.com/t-sauer>
|
|
3
|
+
|
|
4
|
+
export const enum Level {
|
|
5
|
+
None = 0,
|
|
6
|
+
Basic = 1,
|
|
7
|
+
Ansi256 = 2,
|
|
8
|
+
TrueColor = 3
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ChalkOptions {
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
level?: Level;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ChalkConstructor {
|
|
17
|
+
new (options?: ChalkOptions): Chalk;
|
|
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 {
|
|
29
|
+
(...text: string[]): string;
|
|
30
|
+
(text: TemplateStringsArray, ...placeholders: string[]): string;
|
|
31
|
+
constructor: ChalkConstructor;
|
|
32
|
+
enabled: boolean;
|
|
33
|
+
level: Level;
|
|
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;
|
|
46
|
+
|
|
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;
|
|
55
|
+
|
|
56
|
+
readonly visible: this;
|
|
57
|
+
|
|
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;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
declare const chalk: Chalk & { supportsColor: ColorSupport };
|
|
96
|
+
|
|
97
|
+
export default chalk
|