supports-color 5.3.0 → 6.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.
Files changed (3) hide show
  1. package/index.js +20 -17
  2. package/package.json +51 -51
  3. package/readme.md +20 -1
package/index.js CHANGED
@@ -2,21 +2,28 @@
2
2
  const os = require('os');
3
3
  const hasFlag = require('has-flag');
4
4
 
5
- const env = process.env;
5
+ const {env} = process;
6
6
 
7
7
  let forceColor;
8
8
  if (hasFlag('no-color') ||
9
9
  hasFlag('no-colors') ||
10
- hasFlag('color=false')) {
11
- forceColor = false;
10
+ hasFlag('color=false') ||
11
+ hasFlag('color=never')) {
12
+ forceColor = 0;
12
13
  } else if (hasFlag('color') ||
13
14
  hasFlag('colors') ||
14
15
  hasFlag('color=true') ||
15
16
  hasFlag('color=always')) {
16
- forceColor = true;
17
+ forceColor = 1;
17
18
  }
18
19
  if ('FORCE_COLOR' in env) {
19
- forceColor = env.FORCE_COLOR.length === 0 || parseInt(env.FORCE_COLOR, 10) !== 0;
20
+ if (env.FORCE_COLOR === true || env.FORCE_COLOR === 'true') {
21
+ forceColor = 1;
22
+ } else if (env.FORCE_COLOR === false || env.FORCE_COLOR === 'false') {
23
+ forceColor = 0;
24
+ } else {
25
+ forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
26
+ }
20
27
  }
21
28
 
22
29
  function translateLevel(level) {
@@ -33,7 +40,7 @@ function translateLevel(level) {
33
40
  }
34
41
 
35
42
  function supportsColor(stream) {
36
- if (forceColor === false) {
43
+ if (forceColor === 0) {
37
44
  return 0;
38
45
  }
39
46
 
@@ -47,15 +54,15 @@ function supportsColor(stream) {
47
54
  return 2;
48
55
  }
49
56
 
50
- if (stream && !stream.isTTY && forceColor !== true) {
51
- // VS code debugger doesn't have isTTY set
52
- if (env.VSCODE_PID) {
53
- return 1;
54
- }
57
+ if (stream && !stream.isTTY && forceColor === undefined) {
55
58
  return 0;
56
59
  }
57
60
 
58
- const min = forceColor ? 1 : 0;
61
+ const min = forceColor || 0;
62
+
63
+ if (env.TERM === 'dumb') {
64
+ return min;
65
+ }
59
66
 
60
67
  if (process.platform === 'win32') {
61
68
  // Node.js 7.5.0 is the first version of Node.js to include a patch to
@@ -108,7 +115,7 @@ function supportsColor(stream) {
108
115
  return 2;
109
116
  }
110
117
 
111
- if (/^screen|^xterm|^vt100|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
118
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
112
119
  return 1;
113
120
  }
114
121
 
@@ -116,10 +123,6 @@ function supportsColor(stream) {
116
123
  return 1;
117
124
  }
118
125
 
119
- if (env.TERM === 'dumb') {
120
- return min;
121
- }
122
-
123
126
  return min;
124
127
  }
125
128
 
package/package.json CHANGED
@@ -1,53 +1,53 @@
1
1
  {
2
- "name": "supports-color",
3
- "version": "5.3.0",
4
- "description": "Detect whether a terminal supports color",
5
- "license": "MIT",
6
- "repository": "chalk/supports-color",
7
- "author": {
8
- "name": "Sindre Sorhus",
9
- "email": "sindresorhus@gmail.com",
10
- "url": "sindresorhus.com"
11
- },
12
- "engines": {
13
- "node": ">=4"
14
- },
15
- "scripts": {
16
- "test": "xo && ava"
17
- },
18
- "files": [
19
- "index.js",
20
- "browser.js"
21
- ],
22
- "keywords": [
23
- "color",
24
- "colour",
25
- "colors",
26
- "terminal",
27
- "console",
28
- "cli",
29
- "ansi",
30
- "styles",
31
- "tty",
32
- "rgb",
33
- "256",
34
- "shell",
35
- "xterm",
36
- "command-line",
37
- "support",
38
- "supports",
39
- "capability",
40
- "detect",
41
- "truecolor",
42
- "16m"
43
- ],
44
- "dependencies": {
45
- "has-flag": "^3.0.0"
46
- },
47
- "devDependencies": {
48
- "ava": "*",
49
- "import-fresh": "^2.0.0",
50
- "xo": "*"
51
- },
52
- "browser": "browser.js"
2
+ "name": "supports-color",
3
+ "version": "6.1.0",
4
+ "description": "Detect whether a terminal supports color",
5
+ "license": "MIT",
6
+ "repository": "chalk/supports-color",
7
+ "author": {
8
+ "name": "Sindre Sorhus",
9
+ "email": "sindresorhus@gmail.com",
10
+ "url": "sindresorhus.com"
11
+ },
12
+ "engines": {
13
+ "node": ">=6"
14
+ },
15
+ "scripts": {
16
+ "test": "xo && ava"
17
+ },
18
+ "files": [
19
+ "index.js",
20
+ "browser.js"
21
+ ],
22
+ "keywords": [
23
+ "color",
24
+ "colour",
25
+ "colors",
26
+ "terminal",
27
+ "console",
28
+ "cli",
29
+ "ansi",
30
+ "styles",
31
+ "tty",
32
+ "rgb",
33
+ "256",
34
+ "shell",
35
+ "xterm",
36
+ "command-line",
37
+ "support",
38
+ "supports",
39
+ "capability",
40
+ "detect",
41
+ "truecolor",
42
+ "16m"
43
+ ],
44
+ "dependencies": {
45
+ "has-flag": "^3.0.0"
46
+ },
47
+ "devDependencies": {
48
+ "ava": "^0.25.0",
49
+ "import-fresh": "^2.0.0",
50
+ "xo": "^0.23.0"
51
+ },
52
+ "browser": "browser.js"
53
53
  }
package/readme.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  > Detect whether a terminal supports color
4
4
 
5
+ ---
6
+
7
+ <div align="center">
8
+ <b>
9
+ <a href="https://tidelift.com/subscription/pkg/npm-supports-color?utm_source=npm-supports-color&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
10
+ </b>
11
+ <br>
12
+ <sub>
13
+ Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
14
+ </sub>
15
+ </div>
16
+
17
+ ---
18
+
5
19
 
6
20
  ## Install
7
21
 
@@ -44,11 +58,16 @@ The `stdout`/`stderr` objects specifies a level of support for color through a `
44
58
 
45
59
  It obeys the `--color` and `--no-color` CLI flags.
46
60
 
47
- Can be overridden by the user with the flags `--color` and `--no-color`. For situations where using `--color` is not possible, add the environment variable `FORCE_COLOR=1` to forcefully enable color or `FORCE_COLOR=0` to forcefully disable. The use of `FORCE_COLOR` overrides all other color support checks.
61
+ For situations where using `--color` is not possible, use the environment variable `FORCE_COLOR=1` (level 1), `FORCE_COLOR=2` (level 2), or `FORCE_COLOR=3` (level 3) to forcefully enable color, or `FORCE_COLOR=0` to forcefully disable. The use of `FORCE_COLOR` overrides all other color support checks.
48
62
 
49
63
  Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
50
64
 
51
65
 
66
+ ## Security
67
+
68
+ To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
69
+
70
+
52
71
  ## Related
53
72
 
54
73
  - [supports-color-cli](https://github.com/chalk/supports-color-cli) - CLI for this module