@cjser/supports-color 10.2.2-cjser.2 → 11.0.0-cjser.2

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,19 +1,17 @@
1
- /* eslint-env browser */
2
- /* eslint-disable n/no-unsupported-features/node-builtins */
3
-
4
1
  const level = (() => {
5
2
  if (!('navigator' in globalThis)) {
6
3
  return 0;
7
4
  }
8
5
 
9
- if (globalThis.navigator.userAgentData) {
6
+ if (navigator.userAgentData) {
10
7
  const brand = navigator.userAgentData.brands.find(({brand}) => brand === 'Chromium');
11
8
  if (brand?.version > 93) {
12
9
  return 3;
13
10
  }
14
11
  }
15
12
 
16
- if (/\b(Chrome|Chromium)\//.test(globalThis.navigator.userAgent)) {
13
+ // eslint-disable-next-line require-unicode-regexp -- This entry point supports browsers without Unicode Sets.
14
+ if (/\b(?:Chrome|Chromium)\//.test(navigator.userAgent)) {
17
15
  return 1;
18
16
  }
19
17
 
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // packages/@cjser/supports-color/browser.js
19
+ // packages/@cjser/supports-color.tmp-26-1785083390585/browser.js
20
20
  var browser_exports = {};
21
21
  __export(browser_exports, {
22
22
  default: () => browser_default
@@ -26,13 +26,13 @@ var level = (() => {
26
26
  if (!("navigator" in globalThis)) {
27
27
  return 0;
28
28
  }
29
- if (globalThis.navigator.userAgentData) {
29
+ if (navigator.userAgentData) {
30
30
  const brand = navigator.userAgentData.brands.find(({ brand: brand2 }) => brand2 === "Chromium");
31
31
  if ((brand == null ? void 0 : brand.version) > 93) {
32
32
  return 3;
33
33
  }
34
34
  }
35
- if (/\b(Chrome|Chromium)\//.test(globalThis.navigator.userAgent)) {
35
+ if (/\b(?:Chrome|Chromium)\//.test(navigator.userAgent)) {
36
36
  return 1;
37
37
  }
38
38
  return 0;
package/index.js CHANGED
@@ -47,7 +47,11 @@ function envForceColor() {
47
47
  return 1;
48
48
  }
49
49
 
50
- const level = Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
50
+ if (!/^\d+$/v.test(env.FORCE_COLOR)) {
51
+ return;
52
+ }
53
+
54
+ const level = Math.min(Number(env.FORCE_COLOR), 3);
51
55
 
52
56
  if (![0, 1, 2, 3].includes(level)) {
53
57
  return;
@@ -69,6 +73,7 @@ function translateLevel(level) {
69
73
  };
70
74
  }
71
75
 
76
+ // eslint-disable-next-line complexity -- Color support detection necessarily handles multiple environments.
72
77
  function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
73
78
  const noFlagForceColor = envForceColor();
74
79
  if (noFlagForceColor !== undefined) {
@@ -93,6 +98,11 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
93
98
  }
94
99
  }
95
100
 
101
+ // A numeric `FORCE_COLOR` requests an exact level, while `FORCE_COLOR=true` and `FORCE_COLOR=` only enable color and let the level be detected.
102
+ if (forceColor !== undefined && /^\d+$/v.test(env.FORCE_COLOR)) {
103
+ return forceColor;
104
+ }
105
+
96
106
  // Check for Azure DevOps pipelines.
97
107
  // Has to be above the `!streamIsTTY` check.
98
108
  if ('TF_BUILD' in env && 'AGENT_NAME' in env) {
@@ -124,11 +134,11 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
124
134
  }
125
135
 
126
136
  if ('CI' in env) {
127
- if (['GITHUB_ACTIONS', 'GITEA_ACTIONS', 'CIRCLECI'].some(key => key in env)) {
137
+ if (['GITHUB_ACTIONS', 'GITEA_ACTIONS', 'CIRCLECI'].some(key => Object.hasOwn(env, key))) {
128
138
  return 3;
129
139
  }
130
140
 
131
- if (['TRAVIS', 'APPVEYOR', 'GITLAB_CI', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
141
+ if (['TRAVIS', 'APPVEYOR', 'GITLAB_CI', 'BUILDKITE', 'DRONE'].some(sign => Object.hasOwn(env, sign)) || env.CI_NAME === 'codeship') {
132
142
  return 1;
133
143
  }
134
144
 
@@ -136,7 +146,7 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
136
146
  }
137
147
 
138
148
  if ('TEAMCITY_VERSION' in env) {
139
- return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
149
+ return /^(?:9\.0*[1-9]\d*\.|\d{2,}\.)/v.test(env.TEAMCITY_VERSION) ? 1 : 0;
140
150
  }
141
151
 
142
152
  if (env.COLORTERM === 'truecolor') {
@@ -156,7 +166,7 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
156
166
  }
157
167
 
158
168
  if ('TERM_PROGRAM' in env) {
159
- const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
169
+ const version = Number((env.TERM_PROGRAM_VERSION || '').split('.', 1)[0]);
160
170
 
161
171
  switch (env.TERM_PROGRAM) {
162
172
  case 'iTerm.app': {
@@ -170,11 +180,11 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
170
180
  }
171
181
  }
172
182
 
173
- if (/-256(color)?$/i.test(env.TERM)) {
183
+ if (/-256(?:color)?$/iv.test(env.TERM)) {
174
184
  return 2;
175
185
  }
176
186
 
177
- if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
187
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/iv.test(env.TERM)) {
178
188
  return 1;
179
189
  }
180
190
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cjser/supports-color",
3
- "version": "10.2.2-cjser.2",
3
+ "version": "11.0.0-cjser.2",
4
4
  "description": "Detect whether a terminal supports color",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "sideEffects": false,
24
24
  "engines": {
25
- "node": ">=18"
25
+ "node": ">=22"
26
26
  },
27
27
  "scripts": {
28
28
  "test": "xo && ava && tsd"
@@ -57,10 +57,10 @@
57
57
  "16m"
58
58
  ],
59
59
  "devDependencies": {
60
- "@types/node": "^22.10.2",
61
- "ava": "^6.2.0",
62
- "tsd": "^0.31.2",
63
- "xo": "^0.60.0"
60
+ "@types/node": "^26.1.1",
61
+ "ava": "^8.0.1",
62
+ "tsd": "^0.33.0",
63
+ "xo": "^4.0.0"
64
64
  },
65
65
  "ava": {
66
66
  "serial": true,
@@ -69,11 +69,11 @@
69
69
  "types": "./index.d.ts",
70
70
  "main": "./dist-cjser/index.cjs",
71
71
  "cjser": {
72
- "sourceVersion": "10.2.2",
72
+ "sourceVersion": "11.0.0",
73
73
  "cjserVersion": 2,
74
74
  "original": {
75
75
  "name": "supports-color",
76
- "version": "10.2.2",
76
+ "version": "11.0.0",
77
77
  "exports": {
78
78
  "types": "./index.d.ts",
79
79
  "node": "./index.js",
package/readme.md CHANGED
@@ -58,13 +58,15 @@ The options object supports a single boolean property `sniffFlags`. By default i
58
58
 
59
59
  It obeys the `--color` and `--no-color` CLI flags.
60
60
 
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.
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. A numeric `FORCE_COLOR` overrides the detected color support and sets the level directly, meaning the terminal cannot raise it to a higher level. Use `FORCE_COLOR=true` to instead only enable color and let the level be detected.
62
62
 
63
- Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
63
+ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively. These take precedence over a non-zero numeric `FORCE_COLOR`.
64
64
 
65
65
  ## Related
66
66
 
67
67
  - [supports-color-cli](https://github.com/chalk/supports-color-cli) - CLI for this module
68
+ - [supports-hyperlinks](https://github.com/chalk/supports-hyperlinks) - Detect whether a terminal supports hyperlinks
69
+ - [supports-terminal-graphics](https://github.com/sindresorhus/supports-terminal-graphics) - Detect which terminal graphics protocols are supported
68
70
  - [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
69
71
  - [is-unicode-supported](https://github.com/sindresorhus/is-unicode-supported) - Detect whether the terminal supports Unicode
70
72
  - [is-interactive](https://github.com/sindresorhus/is-interactive) - Check if stdout or stderr is interactive