chalk 2.4.2 → 4.0.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.js DELETED
@@ -1,228 +0,0 @@
1
- 'use strict';
2
- const escapeStringRegexp = require('escape-string-regexp');
3
- const ansiStyles = require('ansi-styles');
4
- const stdoutColor = require('supports-color').stdout;
5
-
6
- const template = require('./templates.js');
7
-
8
- const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm');
9
-
10
- // `supportsColor.level` → `ansiStyles.color[name]` mapping
11
- const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m'];
12
-
13
- // `color-convert` models to exclude from the Chalk API due to conflicts and such
14
- const skipModels = new Set(['gray']);
15
-
16
- const styles = Object.create(null);
17
-
18
- function applyOptions(obj, options) {
19
- options = options || {};
20
-
21
- // Detect level if not set manually
22
- const scLevel = stdoutColor ? stdoutColor.level : 0;
23
- obj.level = options.level === undefined ? scLevel : options.level;
24
- obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
25
- }
26
-
27
- function Chalk(options) {
28
- // We check for this.template here since calling `chalk.constructor()`
29
- // by itself will have a `this` of a previously constructed chalk object
30
- if (!this || !(this instanceof Chalk) || this.template) {
31
- const chalk = {};
32
- applyOptions(chalk, options);
33
-
34
- chalk.template = function () {
35
- const args = [].slice.call(arguments);
36
- return chalkTag.apply(null, [chalk.template].concat(args));
37
- };
38
-
39
- Object.setPrototypeOf(chalk, Chalk.prototype);
40
- Object.setPrototypeOf(chalk.template, chalk);
41
-
42
- chalk.template.constructor = Chalk;
43
-
44
- return chalk.template;
45
- }
46
-
47
- applyOptions(this, options);
48
- }
49
-
50
- // Use bright blue on Windows as the normal blue color is illegible
51
- if (isSimpleWindowsTerm) {
52
- ansiStyles.blue.open = '\u001B[94m';
53
- }
54
-
55
- for (const key of Object.keys(ansiStyles)) {
56
- ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
57
-
58
- styles[key] = {
59
- get() {
60
- const codes = ansiStyles[key];
61
- return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
62
- }
63
- };
64
- }
65
-
66
- styles.visible = {
67
- get() {
68
- return build.call(this, this._styles || [], true, 'visible');
69
- }
70
- };
71
-
72
- ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
73
- for (const model of Object.keys(ansiStyles.color.ansi)) {
74
- if (skipModels.has(model)) {
75
- continue;
76
- }
77
-
78
- styles[model] = {
79
- get() {
80
- const level = this.level;
81
- return function () {
82
- const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
83
- const codes = {
84
- open,
85
- close: ansiStyles.color.close,
86
- closeRe: ansiStyles.color.closeRe
87
- };
88
- return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
89
- };
90
- }
91
- };
92
- }
93
-
94
- ansiStyles.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles.bgColor.close), 'g');
95
- for (const model of Object.keys(ansiStyles.bgColor.ansi)) {
96
- if (skipModels.has(model)) {
97
- continue;
98
- }
99
-
100
- const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
101
- styles[bgModel] = {
102
- get() {
103
- const level = this.level;
104
- return function () {
105
- const open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments);
106
- const codes = {
107
- open,
108
- close: ansiStyles.bgColor.close,
109
- closeRe: ansiStyles.bgColor.closeRe
110
- };
111
- return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
112
- };
113
- }
114
- };
115
- }
116
-
117
- const proto = Object.defineProperties(() => {}, styles);
118
-
119
- function build(_styles, _empty, key) {
120
- const builder = function () {
121
- return applyStyle.apply(builder, arguments);
122
- };
123
-
124
- builder._styles = _styles;
125
- builder._empty = _empty;
126
-
127
- const self = this;
128
-
129
- Object.defineProperty(builder, 'level', {
130
- enumerable: true,
131
- get() {
132
- return self.level;
133
- },
134
- set(level) {
135
- self.level = level;
136
- }
137
- });
138
-
139
- Object.defineProperty(builder, 'enabled', {
140
- enumerable: true,
141
- get() {
142
- return self.enabled;
143
- },
144
- set(enabled) {
145
- self.enabled = enabled;
146
- }
147
- });
148
-
149
- // See below for fix regarding invisible grey/dim combination on Windows
150
- builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey';
151
-
152
- // `__proto__` is used because we must return a function, but there is
153
- // no way to create a function with a different prototype
154
- builder.__proto__ = proto; // eslint-disable-line no-proto
155
-
156
- return builder;
157
- }
158
-
159
- function applyStyle() {
160
- // Support varags, but simply cast to string in case there's only one arg
161
- const args = arguments;
162
- const argsLen = args.length;
163
- let str = String(arguments[0]);
164
-
165
- if (argsLen === 0) {
166
- return '';
167
- }
168
-
169
- if (argsLen > 1) {
170
- // Don't slice `arguments`, it prevents V8 optimizations
171
- for (let a = 1; a < argsLen; a++) {
172
- str += ' ' + args[a];
173
- }
174
- }
175
-
176
- if (!this.enabled || this.level <= 0 || !str) {
177
- return this._empty ? '' : str;
178
- }
179
-
180
- // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
181
- // see https://github.com/chalk/chalk/issues/58
182
- // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
183
- const originalDim = ansiStyles.dim.open;
184
- if (isSimpleWindowsTerm && this.hasGrey) {
185
- ansiStyles.dim.open = '';
186
- }
187
-
188
- for (const code of this._styles.slice().reverse()) {
189
- // Replace any instances already present with a re-opening code
190
- // otherwise only the part of the string until said closing code
191
- // will be colored, and the rest will simply be 'plain'.
192
- str = code.open + str.replace(code.closeRe, code.open) + code.close;
193
-
194
- // Close the styling before a linebreak and reopen
195
- // after next line to fix a bleed issue on macOS
196
- // https://github.com/chalk/chalk/pull/92
197
- str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`);
198
- }
199
-
200
- // Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
201
- ansiStyles.dim.open = originalDim;
202
-
203
- return str;
204
- }
205
-
206
- function chalkTag(chalk, strings) {
207
- if (!Array.isArray(strings)) {
208
- // If chalk() was called by itself or with a string,
209
- // return the string itself as a string.
210
- return [].slice.call(arguments, 1).join(' ');
211
- }
212
-
213
- const args = [].slice.call(arguments, 2);
214
- const parts = [strings.raw[0]];
215
-
216
- for (let i = 1; i < strings.length; i++) {
217
- parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&'));
218
- parts.push(String(strings.raw[i]));
219
- }
220
-
221
- return template(chalk, parts.join(''));
222
- }
223
-
224
- Object.defineProperties(Chalk.prototype, styles);
225
-
226
- module.exports = Chalk(); // eslint-disable-line new-cap
227
- module.exports.supportsColor = stdoutColor;
228
- module.exports.default = module.exports; // For TypeScript
package/index.js.flow DELETED
@@ -1,93 +0,0 @@
1
- // @flow strict
2
-
3
- type TemplateStringsArray = $ReadOnlyArray<string>;
4
-
5
- export type Level = $Values<{
6
- None: 0,
7
- Basic: 1,
8
- Ansi256: 2,
9
- TrueColor: 3
10
- }>;
11
-
12
- export type ChalkOptions = {|
13
- enabled?: boolean,
14
- level?: Level
15
- |};
16
-
17
- export type ColorSupport = {|
18
- level: Level,
19
- hasBasic: boolean,
20
- has256: boolean,
21
- has16m: boolean
22
- |};
23
-
24
- export interface Chalk {
25
- (...text: string[]): string,
26
- (text: TemplateStringsArray, ...placeholders: string[]): string,
27
- constructor(options?: ChalkOptions): Chalk,
28
- enabled: boolean,
29
- level: Level,
30
- rgb(r: number, g: number, b: number): Chalk,
31
- hsl(h: number, s: number, l: number): Chalk,
32
- hsv(h: number, s: number, v: number): Chalk,
33
- hwb(h: number, w: number, b: number): Chalk,
34
- bgHex(color: string): Chalk,
35
- bgKeyword(color: string): Chalk,
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,
42
-
43
- +reset: Chalk,
44
- +bold: Chalk,
45
- +dim: Chalk,
46
- +italic: Chalk,
47
- +underline: Chalk,
48
- +inverse: Chalk,
49
- +hidden: Chalk,
50
- +strikethrough: Chalk,
51
-
52
- +visible: Chalk,
53
-
54
- +black: Chalk,
55
- +red: Chalk,
56
- +green: Chalk,
57
- +yellow: Chalk,
58
- +blue: Chalk,
59
- +magenta: Chalk,
60
- +cyan: Chalk,
61
- +white: Chalk,
62
- +gray: Chalk,
63
- +grey: Chalk,
64
- +blackBright: Chalk,
65
- +redBright: Chalk,
66
- +greenBright: Chalk,
67
- +yellowBright: Chalk,
68
- +blueBright: Chalk,
69
- +magentaBright: Chalk,
70
- +cyanBright: Chalk,
71
- +whiteBright: Chalk,
72
-
73
- +bgBlack: Chalk,
74
- +bgRed: Chalk,
75
- +bgGreen: Chalk,
76
- +bgYellow: Chalk,
77
- +bgBlue: Chalk,
78
- +bgMagenta: Chalk,
79
- +bgCyan: Chalk,
80
- +bgWhite: Chalk,
81
- +bgBlackBright: Chalk,
82
- +bgRedBright: Chalk,
83
- +bgGreenBright: Chalk,
84
- +bgYellowBright: Chalk,
85
- +bgBlueBright: Chalk,
86
- +bgMagentaBright: Chalk,
87
- +bgCyanBright: Chalk,
88
- +bgWhiteBrigh: Chalk,
89
-
90
- supportsColor: ColorSupport
91
- };
92
-
93
- declare module.exports: Chalk;
package/types/index.d.ts DELETED
@@ -1,97 +0,0 @@
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