supports-color 7.1.0 → 8.1.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/browser.js CHANGED
@@ -1,5 +1,24 @@
1
+ /* eslint-env browser */
1
2
  'use strict';
3
+
4
+ function getChromeVersion() {
5
+ const matches = /(Chrome|Chromium)\/(?<chromeVersion>\d+)\./.exec(navigator.userAgent);
6
+
7
+ if (!matches) {
8
+ return;
9
+ }
10
+
11
+ return Number.parseInt(matches.groups.chromeVersion, 10);
12
+ }
13
+
14
+ const colorSupport = getChromeVersion() >= 69 ? {
15
+ level: 1,
16
+ hasBasic: true,
17
+ has256: false,
18
+ has16m: false
19
+ } : false;
20
+
2
21
  module.exports = {
3
- stdout: false,
4
- stderr: false
22
+ stdout: colorSupport,
23
+ stderr: colorSupport
5
24
  };
package/index.js CHANGED
@@ -5,26 +5,30 @@ const hasFlag = require('has-flag');
5
5
 
6
6
  const {env} = process;
7
7
 
8
- let forceColor;
8
+ let flagForceColor;
9
9
  if (hasFlag('no-color') ||
10
10
  hasFlag('no-colors') ||
11
11
  hasFlag('color=false') ||
12
12
  hasFlag('color=never')) {
13
- forceColor = 0;
13
+ flagForceColor = 0;
14
14
  } else if (hasFlag('color') ||
15
15
  hasFlag('colors') ||
16
16
  hasFlag('color=true') ||
17
17
  hasFlag('color=always')) {
18
- forceColor = 1;
18
+ flagForceColor = 1;
19
19
  }
20
20
 
21
- if ('FORCE_COLOR' in env) {
22
- if (env.FORCE_COLOR === 'true') {
23
- forceColor = 1;
24
- } else if (env.FORCE_COLOR === 'false') {
25
- forceColor = 0;
26
- } else {
27
- forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
21
+ function envForceColor() {
22
+ if ('FORCE_COLOR' in env) {
23
+ if (env.FORCE_COLOR === 'true') {
24
+ return 1;
25
+ }
26
+
27
+ if (env.FORCE_COLOR === 'false') {
28
+ return 0;
29
+ }
30
+
31
+ return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
28
32
  }
29
33
  }
30
34
 
@@ -41,19 +45,28 @@ function translateLevel(level) {
41
45
  };
42
46
  }
43
47
 
44
- function supportsColor(haveStream, streamIsTTY) {
48
+ function supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
49
+ const noFlagForceColor = envForceColor();
50
+ if (noFlagForceColor !== undefined) {
51
+ flagForceColor = noFlagForceColor;
52
+ }
53
+
54
+ const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
55
+
45
56
  if (forceColor === 0) {
46
57
  return 0;
47
58
  }
48
59
 
49
- if (hasFlag('color=16m') ||
50
- hasFlag('color=full') ||
51
- hasFlag('color=truecolor')) {
52
- return 3;
53
- }
60
+ if (sniffFlags) {
61
+ if (hasFlag('color=16m') ||
62
+ hasFlag('color=full') ||
63
+ hasFlag('color=truecolor')) {
64
+ return 3;
65
+ }
54
66
 
55
- if (hasFlag('color=256')) {
56
- return 2;
67
+ if (hasFlag('color=256')) {
68
+ return 2;
69
+ }
57
70
  }
58
71
 
59
72
  if (haveStream && !streamIsTTY && forceColor === undefined) {
@@ -81,7 +94,7 @@ function supportsColor(haveStream, streamIsTTY) {
81
94
  }
82
95
 
83
96
  if ('CI' in env) {
84
- if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
97
+ if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'GITHUB_ACTIONS', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
85
98
  return 1;
86
99
  }
87
100
 
@@ -92,16 +105,12 @@ function supportsColor(haveStream, streamIsTTY) {
92
105
  return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
93
106
  }
94
107
 
95
- if ('GITHUB_ACTIONS' in env) {
96
- return 1;
97
- }
98
-
99
108
  if (env.COLORTERM === 'truecolor') {
100
109
  return 3;
101
110
  }
102
111
 
103
112
  if ('TERM_PROGRAM' in env) {
104
- const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
113
+ const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
105
114
 
106
115
  switch (env.TERM_PROGRAM) {
107
116
  case 'iTerm.app':
@@ -127,13 +136,17 @@ function supportsColor(haveStream, streamIsTTY) {
127
136
  return min;
128
137
  }
129
138
 
130
- function getSupportLevel(stream) {
131
- const level = supportsColor(stream, stream && stream.isTTY);
139
+ function getSupportLevel(stream, options = {}) {
140
+ const level = supportsColor(stream, {
141
+ streamIsTTY: stream && stream.isTTY,
142
+ ...options
143
+ });
144
+
132
145
  return translateLevel(level);
133
146
  }
134
147
 
135
148
  module.exports = {
136
149
  supportsColor: getSupportLevel,
137
- stdout: translateLevel(supportsColor(true, tty.isatty(1))),
138
- stderr: translateLevel(supportsColor(true, tty.isatty(2)))
150
+ stdout: getSupportLevel({isTTY: tty.isatty(1)}),
151
+ stderr: getSupportLevel({isTTY: tty.isatty(2)})
139
152
  };
package/license CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
6
 
package/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "supports-color",
3
- "version": "7.1.0",
3
+ "version": "8.1.1",
4
4
  "description": "Detect whether a terminal supports color",
5
5
  "license": "MIT",
6
6
  "repository": "chalk/supports-color",
7
+ "funding": "https://github.com/chalk/supports-color?sponsor=1",
7
8
  "author": {
8
9
  "name": "Sindre Sorhus",
9
10
  "email": "sindresorhus@gmail.com",
10
- "url": "sindresorhus.com"
11
+ "url": "https://sindresorhus.com"
11
12
  },
12
13
  "engines": {
13
- "node": ">=8"
14
+ "node": ">=10"
14
15
  },
15
16
  "scripts": {
16
17
  "test": "xo && ava"
@@ -19,6 +20,10 @@
19
20
  "index.js",
20
21
  "browser.js"
21
22
  ],
23
+ "exports": {
24
+ "node": "./index.js",
25
+ "default": "./browser.js"
26
+ },
22
27
  "keywords": [
23
28
  "color",
24
29
  "colour",
@@ -45,9 +50,9 @@
45
50
  "has-flag": "^4.0.0"
46
51
  },
47
52
  "devDependencies": {
48
- "ava": "^1.4.1",
49
- "import-fresh": "^3.0.0",
50
- "xo": "^0.24.0"
53
+ "ava": "^2.4.0",
54
+ "import-fresh": "^3.2.2",
55
+ "xo": "^0.35.0"
51
56
  },
52
57
  "browser": "browser.js"
53
58
  }
package/readme.md CHANGED
@@ -1,15 +1,13 @@
1
- # supports-color [![Build Status](https://travis-ci.org/chalk/supports-color.svg?branch=master)](https://travis-ci.org/chalk/supports-color)
1
+ # supports-color
2
2
 
3
3
  > Detect whether a terminal supports color
4
4
 
5
-
6
5
  ## Install
7
6
 
8
7
  ```
9
8
  $ npm install supports-color
10
9
  ```
11
10
 
12
-
13
11
  ## Usage
14
12
 
15
13
  ```js
@@ -28,7 +26,6 @@ if (supportsColor.stderr.has16m) {
28
26
  }
29
27
  ```
30
28
 
31
-
32
29
  ## API
33
30
 
34
31
  Returns an `Object` with a `stdout` and `stderr` property for testing either streams. Each property is an `Object`, or `false` if color is not supported.
@@ -39,6 +36,13 @@ The `stdout`/`stderr` objects specifies a level of support for color through a `
39
36
  - `.level = 2` and `.has256 = true`: 256 color support
40
37
  - `.level = 3` and `.has16m = true`: Truecolor support (16 million colors)
41
38
 
39
+ ### `require('supports-color').supportsColor(stream, options?)`
40
+
41
+ Additionally, `supports-color` exposes the `.supportsColor()` function that takes an arbitrary write stream (e.g. `process.stdout`) and an optional options object to (re-)evaluate color support for an arbitrary stream.
42
+
43
+ For example, `require('supports-color').stdout` is the equivalent of `require('supports-color').supportsColor(process.stdout)`.
44
+
45
+ The options object supports a single boolean property `sniffFlags`. By default it is `true`, which instructs `supportsColor()` to sniff `process.argv` for the multitude of `--color` flags (see _Info_ below). If `false`, then `process.argv` is not considered when determining color support.
42
46
 
43
47
  ## Info
44
48
 
@@ -48,19 +52,16 @@ For situations where using `--color` is not possible, use the environment variab
48
52
 
49
53
  Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
50
54
 
51
-
52
55
  ## Related
53
56
 
54
57
  - [supports-color-cli](https://github.com/chalk/supports-color-cli) - CLI for this module
55
58
  - [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
56
59
 
57
-
58
60
  ## Maintainers
59
61
 
60
62
  - [Sindre Sorhus](https://github.com/sindresorhus)
61
63
  - [Josh Junon](https://github.com/qix-)
62
64
 
63
-
64
65
  ---
65
66
 
66
67
  <div align="center">