@cjser/supports-color 10.2.2-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.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {default} from './index.js';
package/browser.js ADDED
@@ -0,0 +1,35 @@
1
+ /* eslint-env browser */
2
+ /* eslint-disable n/no-unsupported-features/node-builtins */
3
+
4
+ const level = (() => {
5
+ if (!('navigator' in globalThis)) {
6
+ return 0;
7
+ }
8
+
9
+ if (globalThis.navigator.userAgentData) {
10
+ const brand = navigator.userAgentData.brands.find(({brand}) => brand === 'Chromium');
11
+ if (brand?.version > 93) {
12
+ return 3;
13
+ }
14
+ }
15
+
16
+ if (/\b(Chrome|Chromium)\//.test(globalThis.navigator.userAgent)) {
17
+ return 1;
18
+ }
19
+
20
+ return 0;
21
+ })();
22
+
23
+ const colorSupport = level !== 0 && {
24
+ level,
25
+ hasBasic: true,
26
+ has256: level >= 2,
27
+ has16m: level >= 3,
28
+ };
29
+
30
+ const supportsColor = {
31
+ stdout: colorSupport,
32
+ stderr: colorSupport,
33
+ };
34
+
35
+ export default supportsColor;
@@ -0,0 +1,50 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // packages/@cjser/supports-color/browser.js
20
+ var browser_exports = {};
21
+ __export(browser_exports, {
22
+ default: () => browser_default
23
+ });
24
+ module.exports = __toCommonJS(browser_exports);
25
+ var level = (() => {
26
+ if (!("navigator" in globalThis)) {
27
+ return 0;
28
+ }
29
+ if (globalThis.navigator.userAgentData) {
30
+ const brand = navigator.userAgentData.brands.find(({ brand: brand2 }) => brand2 === "Chromium");
31
+ if ((brand == null ? void 0 : brand.version) > 93) {
32
+ return 3;
33
+ }
34
+ }
35
+ if (/\b(Chrome|Chromium)\//.test(globalThis.navigator.userAgent)) {
36
+ return 1;
37
+ }
38
+ return 0;
39
+ })();
40
+ var colorSupport = level !== 0 && {
41
+ level,
42
+ hasBasic: true,
43
+ has256: level >= 2,
44
+ has16m: level >= 3
45
+ };
46
+ var supportsColor = {
47
+ stdout: colorSupport,
48
+ stderr: colorSupport
49
+ };
50
+ var browser_default = supportsColor;
package/index.d.ts ADDED
@@ -0,0 +1,55 @@
1
+ import type {WriteStream} from 'node:tty';
2
+
3
+ export type Options = {
4
+ /**
5
+ Whether `process.argv` should be sniffed for `--color` and `--no-color` flags.
6
+
7
+ @default true
8
+ */
9
+ readonly sniffFlags?: boolean;
10
+ };
11
+
12
+ /**
13
+ Levels:
14
+ - `0` - All colors disabled.
15
+ - `1` - Basic 16 colors support.
16
+ - `2` - ANSI 256 colors support.
17
+ - `3` - Truecolor 16 million colors support.
18
+ */
19
+ export type ColorSupportLevel = 0 | 1 | 2 | 3;
20
+
21
+ /**
22
+ Detect whether the terminal supports color.
23
+ */
24
+ export type ColorSupport = {
25
+ /**
26
+ The color level.
27
+ */
28
+ level: ColorSupportLevel;
29
+
30
+ /**
31
+ Whether basic 16 colors are supported.
32
+ */
33
+ hasBasic: boolean;
34
+
35
+ /**
36
+ Whether ANSI 256 colors are supported.
37
+ */
38
+ has256: boolean;
39
+
40
+ /**
41
+ Whether Truecolor 16 million colors are supported.
42
+ */
43
+ has16m: boolean;
44
+ };
45
+
46
+ export type ColorInfo = ColorSupport | false;
47
+
48
+ export function createSupportsColor(stream?: WriteStream, options?: Options): ColorInfo;
49
+
50
+ declare const supportsColor: {
51
+ stdout: ColorInfo;
52
+ stderr: ColorInfo;
53
+ };
54
+
55
+ export default supportsColor;
package/index.js ADDED
@@ -0,0 +1,202 @@
1
+ import process from 'node:process';
2
+ import os from 'node:os';
3
+ import tty from 'node:tty';
4
+
5
+ // From: https://github.com/sindresorhus/has-flag/blob/main/index.js
6
+ /// function hasFlag(flag, argv = globalThis.Deno?.args ?? process.argv) {
7
+ function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process.argv) {
8
+ const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
9
+ const position = argv.indexOf(prefix + flag);
10
+ const terminatorPosition = argv.indexOf('--');
11
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
12
+ }
13
+
14
+ const {env} = process;
15
+
16
+ let flagForceColor;
17
+ if (
18
+ hasFlag('no-color')
19
+ || hasFlag('no-colors')
20
+ || hasFlag('color=false')
21
+ || hasFlag('color=never')
22
+ ) {
23
+ flagForceColor = 0;
24
+ } else if (
25
+ hasFlag('color')
26
+ || hasFlag('colors')
27
+ || hasFlag('color=true')
28
+ || hasFlag('color=always')
29
+ ) {
30
+ flagForceColor = 1;
31
+ }
32
+
33
+ function envForceColor() {
34
+ if (!('FORCE_COLOR' in env)) {
35
+ return;
36
+ }
37
+
38
+ if (env.FORCE_COLOR === 'true') {
39
+ return 1;
40
+ }
41
+
42
+ if (env.FORCE_COLOR === 'false') {
43
+ return 0;
44
+ }
45
+
46
+ if (env.FORCE_COLOR.length === 0) {
47
+ return 1;
48
+ }
49
+
50
+ const level = Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
51
+
52
+ if (![0, 1, 2, 3].includes(level)) {
53
+ return;
54
+ }
55
+
56
+ return level;
57
+ }
58
+
59
+ function translateLevel(level) {
60
+ if (level === 0) {
61
+ return false;
62
+ }
63
+
64
+ return {
65
+ level,
66
+ hasBasic: true,
67
+ has256: level >= 2,
68
+ has16m: level >= 3,
69
+ };
70
+ }
71
+
72
+ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
73
+ const noFlagForceColor = envForceColor();
74
+ if (noFlagForceColor !== undefined) {
75
+ flagForceColor = noFlagForceColor;
76
+ }
77
+
78
+ const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
79
+
80
+ if (forceColor === 0) {
81
+ return 0;
82
+ }
83
+
84
+ if (sniffFlags) {
85
+ if (hasFlag('color=16m')
86
+ || hasFlag('color=full')
87
+ || hasFlag('color=truecolor')) {
88
+ return 3;
89
+ }
90
+
91
+ if (hasFlag('color=256')) {
92
+ return 2;
93
+ }
94
+ }
95
+
96
+ // Check for Azure DevOps pipelines.
97
+ // Has to be above the `!streamIsTTY` check.
98
+ if ('TF_BUILD' in env && 'AGENT_NAME' in env) {
99
+ return 1;
100
+ }
101
+
102
+ if (haveStream && !streamIsTTY && forceColor === undefined) {
103
+ return 0;
104
+ }
105
+
106
+ const min = forceColor || 0;
107
+
108
+ if (env.TERM === 'dumb') {
109
+ return min;
110
+ }
111
+
112
+ if (process.platform === 'win32') {
113
+ // Windows 10 build 10586 is the first Windows release that supports 256 colors.
114
+ // Windows 10 build 14931 is the first release that supports 16m/TrueColor.
115
+ const osRelease = os.release().split('.');
116
+ if (
117
+ Number(osRelease[0]) >= 10
118
+ && Number(osRelease[2]) >= 10_586
119
+ ) {
120
+ return Number(osRelease[2]) >= 14_931 ? 3 : 2;
121
+ }
122
+
123
+ return 1;
124
+ }
125
+
126
+ if ('CI' in env) {
127
+ if (['GITHUB_ACTIONS', 'GITEA_ACTIONS', 'CIRCLECI'].some(key => key in env)) {
128
+ return 3;
129
+ }
130
+
131
+ if (['TRAVIS', 'APPVEYOR', 'GITLAB_CI', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
132
+ return 1;
133
+ }
134
+
135
+ return min;
136
+ }
137
+
138
+ if ('TEAMCITY_VERSION' in env) {
139
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
140
+ }
141
+
142
+ if (env.COLORTERM === 'truecolor') {
143
+ return 3;
144
+ }
145
+
146
+ if (env.TERM === 'xterm-kitty') {
147
+ return 3;
148
+ }
149
+
150
+ if (env.TERM === 'xterm-ghostty') {
151
+ return 3;
152
+ }
153
+
154
+ if (env.TERM === 'wezterm') {
155
+ return 3;
156
+ }
157
+
158
+ if ('TERM_PROGRAM' in env) {
159
+ const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
160
+
161
+ switch (env.TERM_PROGRAM) {
162
+ case 'iTerm.app': {
163
+ return version >= 3 ? 3 : 2;
164
+ }
165
+
166
+ case 'Apple_Terminal': {
167
+ return 2;
168
+ }
169
+ // No default
170
+ }
171
+ }
172
+
173
+ if (/-256(color)?$/i.test(env.TERM)) {
174
+ return 2;
175
+ }
176
+
177
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
178
+ return 1;
179
+ }
180
+
181
+ if ('COLORTERM' in env) {
182
+ return 1;
183
+ }
184
+
185
+ return min;
186
+ }
187
+
188
+ export function createSupportsColor(stream, options = {}) {
189
+ const level = _supportsColor(stream, {
190
+ streamIsTTY: stream && stream.isTTY,
191
+ ...options,
192
+ });
193
+
194
+ return translateLevel(level);
195
+ }
196
+
197
+ const supportsColor = {
198
+ stdout: createSupportsColor({isTTY: tty.isatty(1)}),
199
+ stderr: createSupportsColor({isTTY: tty.isatty(2)}),
200
+ };
201
+
202
+ export default supportsColor;
package/license ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+
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
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,94 @@
1
+ {
2
+ "name": "@cjser/supports-color",
3
+ "version": "10.2.2-cjser.2",
4
+ "description": "Detect whether a terminal supports color",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://code.moenext.com/3rdeye/cjser.git"
9
+ },
10
+ "funding": "https://github.com/chalk/supports-color?sponsor=1",
11
+ "author": {
12
+ "name": "Sindre Sorhus",
13
+ "email": "sindresorhus@gmail.com",
14
+ "url": "https://sindresorhus.com"
15
+ },
16
+ "type": "module",
17
+ "exports": {
18
+ "types": "./index.d.ts",
19
+ "require": "./dist-cjser/index.cjs",
20
+ "node": "./index.js",
21
+ "default": "./browser.js"
22
+ },
23
+ "sideEffects": false,
24
+ "engines": {
25
+ "node": ">=18"
26
+ },
27
+ "scripts": {
28
+ "test": "xo && ava && tsd"
29
+ },
30
+ "files": [
31
+ "index.js",
32
+ "index.d.ts",
33
+ "browser.js",
34
+ "browser.d.ts",
35
+ "dist-cjser"
36
+ ],
37
+ "keywords": [
38
+ "color",
39
+ "colour",
40
+ "colors",
41
+ "terminal",
42
+ "console",
43
+ "cli",
44
+ "ansi",
45
+ "styles",
46
+ "tty",
47
+ "rgb",
48
+ "256",
49
+ "shell",
50
+ "xterm",
51
+ "command-line",
52
+ "support",
53
+ "supports",
54
+ "capability",
55
+ "detect",
56
+ "truecolor",
57
+ "16m"
58
+ ],
59
+ "devDependencies": {
60
+ "@types/node": "^22.10.2",
61
+ "ava": "^6.2.0",
62
+ "tsd": "^0.31.2",
63
+ "xo": "^0.60.0"
64
+ },
65
+ "ava": {
66
+ "serial": true,
67
+ "workerThreads": false
68
+ },
69
+ "types": "./index.d.ts",
70
+ "main": "./dist-cjser/index.cjs",
71
+ "cjser": {
72
+ "sourceVersion": "10.2.2",
73
+ "cjserVersion": 2,
74
+ "original": {
75
+ "name": "supports-color",
76
+ "version": "10.2.2",
77
+ "exports": {
78
+ "types": "./index.d.ts",
79
+ "node": "./index.js",
80
+ "default": "./browser.js"
81
+ },
82
+ "repository": "chalk/supports-color",
83
+ "files": [
84
+ "index.js",
85
+ "index.d.ts",
86
+ "browser.js",
87
+ "browser.d.ts"
88
+ ],
89
+ "scripts": {
90
+ "test": "xo && ava && tsd"
91
+ }
92
+ }
93
+ }
94
+ }
package/readme.md ADDED
@@ -0,0 +1,80 @@
1
+ # supports-color
2
+
3
+ > Detect whether a terminal supports color
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install supports-color
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ import supportsColor from 'supports-color';
15
+
16
+ if (supportsColor.stdout) {
17
+ console.log('Terminal stdout supports color');
18
+ }
19
+
20
+ if (supportsColor.stdout.has256) {
21
+ console.log('Terminal stdout supports 256 colors');
22
+ }
23
+
24
+ if (supportsColor.stderr.has16m) {
25
+ console.log('Terminal stderr supports 16 million colors (truecolor)');
26
+ }
27
+ ```
28
+
29
+ ## API
30
+
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.
32
+
33
+ The `stdout`/`stderr` objects specifies a level of support for color through a `.level` property and a corresponding flag:
34
+
35
+ - `.level = 1` and `.hasBasic = true`: Basic color support (16 colors)
36
+ - `.level = 2` and `.has256 = true`: 256 color support
37
+ - `.level = 3` and `.has16m = true`: Truecolor support (16 million colors)
38
+
39
+ ### Custom instance
40
+
41
+ The package also exposes the named export `createSupportColor` function that takes an arbitrary write stream (for example, `process.stdout`) and an optional options object to (re-)evaluate color support for an arbitrary stream.
42
+
43
+ ```js
44
+ import {createSupportsColor} from 'supports-color';
45
+
46
+ const stdoutSupportsColor = createSupportsColor(process.stdout);
47
+
48
+ if (stdoutSupportsColor) {
49
+ console.log('Terminal stdout supports color');
50
+ }
51
+
52
+ // `stdoutSupportsColor` is the same as `supportsColor.stdout`
53
+ ```
54
+
55
+ The options object supports a single boolean property `sniffFlags`. By default it is `true`, which instructs the detection 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.
56
+
57
+ ## Info
58
+
59
+ It obeys the `--color` and `--no-color` CLI flags.
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.
62
+
63
+ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
64
+
65
+ ## Related
66
+
67
+ - [supports-color-cli](https://github.com/chalk/supports-color-cli) - CLI for this module
68
+ - [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
69
+ - [is-unicode-supported](https://github.com/sindresorhus/is-unicode-supported) - Detect whether the terminal supports Unicode
70
+ - [is-interactive](https://github.com/sindresorhus/is-interactive) - Check if stdout or stderr is interactive
71
+
72
+ ## Maintainers
73
+
74
+ - [Sindre Sorhus](https://github.com/sindresorhus)
75
+ - [Josh Junon](https://github.com/qix-)
76
+
77
+ ## cjser
78
+
79
+ This package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.
80
+ Original repository: https://github.com/chalk/supports-color