chalk 3.0.0 → 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.d.ts CHANGED
@@ -1,25 +1,3 @@
1
- declare const enum LevelEnum {
2
- /**
3
- All colors disabled.
4
- */
5
- None = 0,
6
-
7
- /**
8
- Basic 16 colors support.
9
- */
10
- Basic = 1,
11
-
12
- /**
13
- ANSI 256 colors support.
14
- */
15
- Ansi256 = 2,
16
-
17
- /**
18
- Truecolor 16 million colors support.
19
- */
20
- TrueColor = 3
21
- }
22
-
23
1
  /**
24
2
  Basic foreground colors.
25
3
 
@@ -89,22 +67,34 @@ declare type Modifiers =
89
67
  | 'visible';
90
68
 
91
69
  declare namespace chalk {
92
- type Level = LevelEnum;
70
+ /**
71
+ Levels:
72
+ - `0` - All colors disabled.
73
+ - `1` - Basic 16 colors support.
74
+ - `2` - ANSI 256 colors support.
75
+ - `3` - Truecolor 16 million colors support.
76
+ */
77
+ type Level = 0 | 1 | 2 | 3;
93
78
 
94
79
  interface Options {
95
80
  /**
96
81
  Specify the color support for Chalk.
82
+
97
83
  By default, color support is automatically detected based on the environment.
84
+
85
+ Levels:
86
+ - `0` - All colors disabled.
87
+ - `1` - Basic 16 colors support.
88
+ - `2` - ANSI 256 colors support.
89
+ - `3` - Truecolor 16 million colors support.
98
90
  */
99
91
  level?: Level;
100
92
  }
101
93
 
102
- interface Instance {
103
- /**
104
- Return a new Chalk instance.
105
- */
106
- new (options?: Options): Chalk;
107
- }
94
+ /**
95
+ Return a new Chalk instance.
96
+ */
97
+ type Instance = new (options?: Options) => Chalk;
108
98
 
109
99
  /**
110
100
  Detect whether the terminal supports color.
@@ -161,7 +151,14 @@ declare namespace chalk {
161
151
 
162
152
  /**
163
153
  The color support for Chalk.
154
+
164
155
  By default, color support is automatically detected based on the environment.
156
+
157
+ Levels:
158
+ - `0` - All colors disabled.
159
+ - `1` - Basic 16 colors support.
160
+ - `2` - ANSI 256 colors support.
161
+ - `3` - Truecolor 16 million colors support.
165
162
  */
166
163
  level: Level;
167
164
 
@@ -400,7 +397,7 @@ This simply means that `chalk.red.yellow.green` is equivalent to `chalk.green`.
400
397
  */
401
398
  declare const chalk: chalk.Chalk & chalk.ChalkFunction & {
402
399
  supportsColor: chalk.ColorSupport | false;
403
- Level: typeof LevelEnum;
400
+ Level: chalk.Level;
404
401
  Color: Color;
405
402
  ForegroundColor: ForegroundColor;
406
403
  BackgroundColor: BackgroundColor;
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "chalk",
3
- "version": "3.0.0",
3
+ "version": "4.0.0",
4
4
  "description": "Terminal string styling done right",
5
5
  "license": "MIT",
6
6
  "repository": "chalk/chalk",
7
+ "funding": "https://github.com/chalk/chalk?sponsor=1",
7
8
  "main": "source",
8
9
  "engines": {
9
- "node": ">=8"
10
+ "node": ">=10"
10
11
  },
11
12
  "scripts": {
12
13
  "test": "xo && nyc ava && tsd",
@@ -46,18 +47,22 @@
46
47
  "devDependencies": {
47
48
  "ava": "^2.4.0",
48
49
  "coveralls": "^3.0.7",
49
- "execa": "^3.2.0",
50
+ "execa": "^4.0.0",
50
51
  "import-fresh": "^3.1.0",
51
52
  "matcha": "^0.7.0",
52
- "nyc": "^14.1.1",
53
+ "nyc": "^15.0.0",
53
54
  "resolve-from": "^5.0.0",
54
55
  "tsd": "^0.7.4",
55
- "xo": "^0.25.3"
56
+ "xo": "^0.28.2"
56
57
  },
57
58
  "xo": {
58
59
  "rules": {
59
60
  "unicorn/prefer-string-slice": "off",
60
- "unicorn/prefer-includes": "off"
61
+ "unicorn/prefer-includes": "off",
62
+ "@typescript-eslint/member-ordering": "off",
63
+ "no-redeclare": "off",
64
+ "unicorn/string-content": "off",
65
+ "unicorn/better-regex": "off"
61
66
  }
62
67
  }
63
68
  }
package/readme.md CHANGED
@@ -9,11 +9,10 @@
9
9
 
10
10
  > Terminal string styling done right
11
11
 
12
- [![Build Status](https://travis-ci.org/chalk/chalk.svg?branch=master)](https://travis-ci.org/chalk/chalk) [![Coverage Status](https://coveralls.io/repos/github/chalk/chalk/badge.svg?branch=master)](https://coveralls.io/github/chalk/chalk?branch=master) [![npm dependents](https://badgen.net/npm/dependents/chalk)](https://www.npmjs.com/package/chalk?activeTab=dependents) [![Downloads](https://badgen.net/npm/dt/chalk)](https://www.npmjs.com/package/chalk) [![](https://img.shields.io/badge/unicorn-approved-ff69b4.svg)](https://www.youtube.com/watch?v=9auOCbH5Ns4) [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/xojs/xo) ![TypeScript-ready](https://img.shields.io/npm/types/chalk.svg)
12
+ [![Build Status](https://travis-ci.org/chalk/chalk.svg?branch=master)](https://travis-ci.org/chalk/chalk) [![Coverage Status](https://coveralls.io/repos/github/chalk/chalk/badge.svg?branch=master)](https://coveralls.io/github/chalk/chalk?branch=master) [![npm dependents](https://badgen.net/npm/dependents/chalk)](https://www.npmjs.com/package/chalk?activeTab=dependents) [![Downloads](https://badgen.net/npm/dt/chalk)](https://www.npmjs.com/package/chalk) [![](https://img.shields.io/badge/unicorn-approved-ff69b4.svg)](https://www.youtube.com/watch?v=9auOCbH5Ns4) [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/xojs/xo) ![TypeScript-ready](https://img.shields.io/npm/types/chalk.svg) [![run on repl.it](http://repl.it/badge/github/chalk/chalk)](https://repl.it/github/chalk/chalk)
13
13
 
14
14
  <img src="https://cdn.jsdelivr.net/gh/chalk/ansi-styles@8261697c95bf34b6c7767e2cbe9941a851d59385/screenshot.svg" width="900">
15
15
 
16
-
17
16
  ## Highlights
18
17
 
19
18
  - Expressive API
@@ -24,8 +23,7 @@
24
23
  - Doesn't extend `String.prototype`
25
24
  - Clean and focused
26
25
  - Actively maintained
27
- - [Used by ~46,000 packages](https://www.npmjs.com/browse/depended/chalk) as of October 1, 2019
28
-
26
+ - [Used by ~50,000 packages](https://www.npmjs.com/browse/depended/chalk) as of January 1, 2020
29
27
 
30
28
  ## Install
31
29
 
@@ -33,7 +31,6 @@
33
31
  $ npm install chalk
34
32
  ```
35
33
 
36
-
37
34
  ## Usage
38
35
 
39
36
  ```js
@@ -107,7 +104,6 @@ console.log(chalk.green('Hello %s'), name);
107
104
  //=> 'Hello Sindre'
108
105
  ```
109
106
 
110
-
111
107
  ## API
112
108
 
113
109
  ### chalk.`<style>[.<style>...](string, [string...])`
@@ -149,7 +145,6 @@ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=
149
145
 
150
146
  `chalk.stderr` contains a separate instance configured with color support detected for `stderr` stream instead of `stdout`. Override rules from `chalk.supportsColor` apply to this too. `chalk.stderr.supportsColor` is exposed for convenience.
151
147
 
152
-
153
148
  ## Styles
154
149
 
155
150
  ### Modifiers
@@ -202,7 +197,6 @@ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=
202
197
  - `bgCyanBright`
203
198
  - `bgWhiteBright`
204
199
 
205
-
206
200
  ## Tagged template literal
207
201
 
208
202
  Chalk can be used as a [tagged template literal](http://exploringjs.com/es6/ch_template-literals.html#_tagged-template-literals).
@@ -232,7 +226,6 @@ Note that function styles (`rgb()`, `hsl()`, `keyword()`, etc.) may not contain
232
226
 
233
227
  All interpolated values (`` chalk`${foo}` ``) are converted to strings via the `.toString()` method. All curly braces (`{` and `}`) in interpolated value strings are escaped.
234
228
 
235
-
236
229
  ## 256 and Truecolor color support
237
230
 
238
231
  Chalk supports 256 colors and [Truecolor](https://gist.github.com/XVilka/8346728) (16 million colors) on supported terminal apps.
@@ -262,24 +255,20 @@ The following color models can be used:
262
255
  - [`ansi`](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) - Example: `chalk.ansi(31).bgAnsi(93)('red on yellowBright')`
263
256
  - [`ansi256`](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) - Example: `chalk.bgAnsi256(194)('Honeydew, more or less')`
264
257
 
265
-
266
258
  ## Windows
267
259
 
268
260
  If you're on Windows, do yourself a favor and use [Windows Terminal](https://github.com/microsoft/terminal) instead of `cmd.exe`.
269
261
 
270
-
271
262
  ## Origin story
272
263
 
273
264
  [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.
274
265
 
275
-
276
266
  ## chalk for enterprise
277
267
 
278
268
  Available as part of the Tidelift Subscription.
279
269
 
280
270
  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)
281
271
 
282
-
283
272
  ## Related
284
273
 
285
274
  - [chalk-cli](https://github.com/chalk/chalk-cli) - CLI for this module
@@ -297,7 +286,6 @@ The maintainers of chalk and thousands of other packages are working with Tideli
297
286
  - [chalk-pipe](https://github.com/LitoMore/chalk-pipe) - Create chalk style schemes with simpler style strings
298
287
  - [terminal-link](https://github.com/sindresorhus/terminal-link) - Create clickable links in the terminal
299
288
 
300
-
301
289
  ## Maintainers
302
290
 
303
291
  - [Sindre Sorhus](https://github.com/sindresorhus)
package/source/index.js CHANGED
@@ -17,7 +17,7 @@ const levelMapping = [
17
17
  const styles = Object.create(null);
18
18
 
19
19
  const applyOptions = (object, options = {}) => {
20
- if (options.level > 3 || options.level < 0) {
20
+ if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
21
21
  throw new Error('The `level` option should be an integer from 0 to 3');
22
22
  }
23
23
 
@@ -28,6 +28,7 @@ const applyOptions = (object, options = {}) => {
28
28
 
29
29
  class ChalkClass {
30
30
  constructor(options) {
31
+ // eslint-disable-next-line no-constructor-return
31
32
  return chalkFactory(options);
32
33
  }
33
34
  }
@@ -139,9 +140,9 @@ const createBuilder = (self, _styler, _isEmpty) => {
139
140
  return applyStyle(builder, (arguments_.length === 1) ? ('' + arguments_[0]) : arguments_.join(' '));
140
141
  };
141
142
 
142
- // `__proto__` is used because we must return a function, but there is
143
+ // We alter the prototype because we must return a function, but there is
143
144
  // no way to create a function with a different prototype
144
- builder.__proto__ = proto; // eslint-disable-line no-proto
145
+ Object.setPrototypeOf(builder, proto);
145
146
 
146
147
  builder._generator = self;
147
148
  builder._styler = _styler;
@@ -218,16 +219,4 @@ chalk.supportsColor = stdoutColor;
218
219
  chalk.stderr = Chalk({level: stderrColor ? stderrColor.level : 0}); // eslint-disable-line new-cap
219
220
  chalk.stderr.supportsColor = stderrColor;
220
221
 
221
- // For TypeScript
222
- chalk.Level = {
223
- None: 0,
224
- Basic: 1,
225
- Ansi256: 2,
226
- TrueColor: 3,
227
- 0: 'None',
228
- 1: 'Basic',
229
- 2: 'Ansi256',
230
- 3: 'TrueColor'
231
- };
232
-
233
222
  module.exports = chalk;
@@ -2,7 +2,7 @@
2
2
  const TEMPLATE_REGEX = /(?:\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|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(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|([^\\])/gi;
5
+ const ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|{[a-f\d]{1,6}})|x[a-f\d]{2}|.)|([^\\])/gi;
6
6
 
7
7
  const ESCAPES = new Map([
8
8
  ['n', '\n'],
@@ -126,8 +126,8 @@ module.exports = (chalk, temporary) => {
126
126
  chunks.push(chunk.join(''));
127
127
 
128
128
  if (styles.length > 0) {
129
- const errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
130
- throw new Error(errMsg);
129
+ const errMessage = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
130
+ throw new Error(errMessage);
131
131
  }
132
132
 
133
133
  return chunks.join('');