@cjser/supports-hyperlinks 4.4.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 ADDED
@@ -0,0 +1,10 @@
1
+ export function createSupportsHyperlinks() {
2
+ return false;
3
+ }
4
+
5
+ const supportsHyperlinks = {
6
+ stdout: createSupportsHyperlinks(),
7
+ stderr: createSupportsHyperlinks(),
8
+ };
9
+
10
+ export default supportsHyperlinks;
@@ -0,0 +1,152 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // packages/@cjser/supports-hyperlinks/index.js
30
+ var index_exports = {};
31
+ __export(index_exports, {
32
+ createSupportsHyperlinks: () => createSupportsHyperlinks,
33
+ default: () => index_default
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+ var import_node_process = __toESM(require("node:process"), 1);
37
+ var import_supports_color = require("@cjser/supports-color");
38
+ var import_has_flag = __toESM(require("@cjser/has-flag"), 1);
39
+ function parseVersion(versionString = "") {
40
+ if (/^\d{3,4}$/.test(versionString)) {
41
+ const match = /(\d{1,2})(\d{2})/.exec(versionString) ?? [];
42
+ return {
43
+ major: 0,
44
+ minor: Number.parseInt(match[1], 10),
45
+ patch: Number.parseInt(match[2], 10)
46
+ };
47
+ }
48
+ const versions = (versionString ?? "").split(".").map((n) => Number.parseInt(n, 10));
49
+ return {
50
+ major: versions[0],
51
+ minor: versions[1],
52
+ patch: versions[2]
53
+ };
54
+ }
55
+ function createSupportsHyperlinks(stream) {
56
+ const {
57
+ CI,
58
+ CURSOR_TRACE_ID,
59
+ FORCE_HYPERLINK,
60
+ NETLIFY,
61
+ TEAMCITY_VERSION,
62
+ TERM_PROGRAM,
63
+ TERM_PROGRAM_VERSION,
64
+ VTE_VERSION,
65
+ TERM
66
+ } = import_node_process.default.env;
67
+ if (FORCE_HYPERLINK) {
68
+ return !(FORCE_HYPERLINK.length > 0 && Number.parseInt(FORCE_HYPERLINK, 10) === 0);
69
+ }
70
+ if ((0, import_has_flag.default)("no-hyperlink") || (0, import_has_flag.default)("no-hyperlinks") || (0, import_has_flag.default)("hyperlink=false") || (0, import_has_flag.default)("hyperlink=never")) {
71
+ return false;
72
+ }
73
+ if ((0, import_has_flag.default)("hyperlink=true") || (0, import_has_flag.default)("hyperlink=always")) {
74
+ return true;
75
+ }
76
+ if (NETLIFY) {
77
+ return true;
78
+ }
79
+ if (!(0, import_supports_color.createSupportsColor)(stream)) {
80
+ return false;
81
+ }
82
+ if (stream && !stream.isTTY) {
83
+ return false;
84
+ }
85
+ if ("WT_SESSION" in import_node_process.default.env) {
86
+ return true;
87
+ }
88
+ if (import_node_process.default.platform === "win32") {
89
+ return false;
90
+ }
91
+ if (CI) {
92
+ return false;
93
+ }
94
+ if (TEAMCITY_VERSION) {
95
+ return false;
96
+ }
97
+ if (TERM_PROGRAM) {
98
+ const version = parseVersion(TERM_PROGRAM_VERSION);
99
+ switch (TERM_PROGRAM) {
100
+ case "iTerm.app": {
101
+ if (version.major === 3) {
102
+ return version.minor >= 1;
103
+ }
104
+ return version.major > 3;
105
+ }
106
+ case "WezTerm": {
107
+ if (/^0-unstable-\d{4}-\d{2}-\d{2}$/.test(TERM_PROGRAM_VERSION)) {
108
+ const date = TERM_PROGRAM_VERSION.slice("0-unstable-".length);
109
+ return date >= "2020-06-20";
110
+ }
111
+ return version.major >= 20200620;
112
+ }
113
+ case "vscode": {
114
+ if (CURSOR_TRACE_ID) {
115
+ return true;
116
+ }
117
+ return version.major > 1 || version.major === 1 && version.minor >= 72;
118
+ }
119
+ case "ghostty": {
120
+ return true;
121
+ }
122
+ case "zed": {
123
+ return true;
124
+ }
125
+ }
126
+ }
127
+ if (VTE_VERSION) {
128
+ if (VTE_VERSION === "0.50.0") {
129
+ return false;
130
+ }
131
+ const version = parseVersion(VTE_VERSION);
132
+ return version.major > 0 || version.minor >= 50;
133
+ }
134
+ switch (TERM) {
135
+ case "alacritty": {
136
+ return true;
137
+ }
138
+ case "xterm-kitty": {
139
+ return true;
140
+ }
141
+ }
142
+ return false;
143
+ }
144
+ var supportsHyperlinks = {
145
+ stdout: createSupportsHyperlinks(import_node_process.default.stdout),
146
+ stderr: createSupportsHyperlinks(import_node_process.default.stderr)
147
+ };
148
+ var index_default = supportsHyperlinks;
149
+ // Annotate the CommonJS export names for ESM import in node:
150
+ 0 && (module.exports = {
151
+ createSupportsHyperlinks
152
+ });
package/index.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ /**
2
+ Creates a supports hyperlinks check for a given stream.
3
+
4
+ @param stream - Optional stream to check for hyperlink support.
5
+ @returns boolean indicating whether hyperlinks are supported.
6
+ */
7
+ export function createSupportsHyperlinks(stream?: {isTTY?: boolean}): boolean;
8
+
9
+ /**
10
+ Object containing hyperlink support status for stdout and stderr.
11
+ */
12
+ type SupportsHyperlinks = {
13
+ /**
14
+ Whether stdout supports hyperlinks.
15
+ */
16
+ stdout: boolean;
17
+ /**
18
+ Whether stderr supports hyperlinks.
19
+ */
20
+ stderr: boolean;
21
+ };
22
+
23
+ declare const supportsHyperlinks: SupportsHyperlinks;
24
+
25
+ export default supportsHyperlinks;
package/index.js ADDED
@@ -0,0 +1,157 @@
1
+ import process from 'node:process';
2
+ import {createSupportsColor} from '@cjser/supports-color';
3
+ import hasFlag from '@cjser/has-flag';
4
+
5
+ function parseVersion(versionString = '') {
6
+ if (/^\d{3,4}$/.test(versionString)) {
7
+ // Env var doesn't always use dots. example: 4601 => 46.1.0
8
+ const match = /(\d{1,2})(\d{2})/.exec(versionString) ?? [];
9
+ return {
10
+ major: 0,
11
+ minor: Number.parseInt(match[1], 10),
12
+ patch: Number.parseInt(match[2], 10),
13
+ };
14
+ }
15
+
16
+ const versions = (versionString ?? '').split('.').map(n => Number.parseInt(n, 10));
17
+ return {
18
+ major: versions[0],
19
+ minor: versions[1],
20
+ patch: versions[2],
21
+ };
22
+ }
23
+
24
+ // eslint-disable-next-line complexity
25
+ export function createSupportsHyperlinks(stream) {
26
+ const {
27
+ CI,
28
+ CURSOR_TRACE_ID,
29
+ FORCE_HYPERLINK,
30
+ NETLIFY,
31
+ TEAMCITY_VERSION,
32
+ TERM_PROGRAM,
33
+ TERM_PROGRAM_VERSION,
34
+ VTE_VERSION,
35
+ TERM,
36
+ } = process.env;
37
+
38
+ if (FORCE_HYPERLINK) {
39
+ return !(FORCE_HYPERLINK.length > 0 && Number.parseInt(FORCE_HYPERLINK, 10) === 0);
40
+ }
41
+
42
+ if (hasFlag('no-hyperlink') || hasFlag('no-hyperlinks') || hasFlag('hyperlink=false') || hasFlag('hyperlink=never')) {
43
+ return false;
44
+ }
45
+
46
+ if (hasFlag('hyperlink=true') || hasFlag('hyperlink=always')) {
47
+ return true;
48
+ }
49
+
50
+ // Netlify does not run a TTY, it does not need `supportsColor` check
51
+ if (NETLIFY) {
52
+ return true;
53
+ }
54
+
55
+ // If they specify no colors, they probably don't want hyperlinks.
56
+ if (!createSupportsColor(stream)) {
57
+ return false;
58
+ }
59
+
60
+ if (stream && !stream.isTTY) {
61
+ return false;
62
+ }
63
+
64
+ // Windows Terminal
65
+ if ('WT_SESSION' in process.env) {
66
+ return true;
67
+ }
68
+
69
+ if (process.platform === 'win32') {
70
+ return false;
71
+ }
72
+
73
+ if (CI) {
74
+ return false;
75
+ }
76
+
77
+ if (TEAMCITY_VERSION) {
78
+ return false;
79
+ }
80
+
81
+ if (TERM_PROGRAM) {
82
+ const version = parseVersion(TERM_PROGRAM_VERSION);
83
+
84
+ switch (TERM_PROGRAM) {
85
+ case 'iTerm.app': {
86
+ if (version.major === 3) {
87
+ return version.minor >= 1;
88
+ }
89
+
90
+ return version.major > 3;
91
+ }
92
+
93
+ case 'WezTerm': {
94
+ // WezTerm packaged by Nix uses their own version scheme.
95
+ if (/^0-unstable-\d{4}-\d{2}-\d{2}$/.test(TERM_PROGRAM_VERSION)) {
96
+ const date = TERM_PROGRAM_VERSION.slice('0-unstable-'.length);
97
+ return date >= '2020-06-20';
98
+ }
99
+
100
+ // This number is a date and reads better grouped as such.
101
+ // eslint-disable-next-line unicorn/numeric-separators-style
102
+ return version.major >= 2020_06_20;
103
+ }
104
+
105
+ case 'vscode': {
106
+ // Cursor forked VS Code and supports hyperlinks in 0.x.x
107
+ if (CURSOR_TRACE_ID) {
108
+ return true;
109
+ }
110
+
111
+ // eslint-disable-next-line @stylistic/no-mixed-operators
112
+ return version.major > 1 || version.major === 1 && version.minor >= 72;
113
+ }
114
+
115
+ case 'ghostty': {
116
+ return true;
117
+ }
118
+
119
+ case 'zed': {
120
+ return true;
121
+ }
122
+
123
+ // No default
124
+ }
125
+ }
126
+
127
+ if (VTE_VERSION) {
128
+ // 0.50.0 was supposed to support hyperlinks, but throws a segfault
129
+ if (VTE_VERSION === '0.50.0') {
130
+ return false;
131
+ }
132
+
133
+ const version = parseVersion(VTE_VERSION);
134
+ return version.major > 0 || version.minor >= 50;
135
+ }
136
+
137
+ switch (TERM) {
138
+ case 'alacritty': {
139
+ // Support added in v0.11 (2022-10-13)
140
+ return true;
141
+ }
142
+
143
+ case 'xterm-kitty': {
144
+ return true;
145
+ }
146
+ // No default
147
+ }
148
+
149
+ return false;
150
+ }
151
+
152
+ const supportsHyperlinks = {
153
+ stdout: createSupportsHyperlinks(process.stdout),
154
+ stderr: createSupportsHyperlinks(process.stderr),
155
+ };
156
+
157
+ export default supportsHyperlinks;
package/license ADDED
@@ -0,0 +1,10 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+ Copyright (c) James Talmage <james@talmage.io> (https://github.com/jamestalmage)
5
+
6
+ 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:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+
10
+ 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,79 @@
1
+ {
2
+ "name": "@cjser/supports-hyperlinks",
3
+ "version": "4.4.0-cjser.2",
4
+ "description": "Detect whether a terminal supports hyperlinks",
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-hyperlinks?sponsor=1",
11
+ "type": "module",
12
+ "exports": {
13
+ "types": "./index.d.ts",
14
+ "require": "./dist-cjser/index.cjs",
15
+ "default": "./index.js"
16
+ },
17
+ "sideEffects": false,
18
+ "engines": {
19
+ "node": ">=20"
20
+ },
21
+ "scripts": {
22
+ "test": "xo && ava && tsc --lib es2022 index.d.ts"
23
+ },
24
+ "files": [
25
+ "index.js",
26
+ "index.d.ts",
27
+ "browser.js",
28
+ "dist-cjser"
29
+ ],
30
+ "browser": "browser.js",
31
+ "keywords": [
32
+ "link",
33
+ "terminal",
34
+ "hyperlink",
35
+ "cli",
36
+ "detect",
37
+ "check",
38
+ "ansi",
39
+ "escapes",
40
+ "console"
41
+ ],
42
+ "dependencies": {
43
+ "@cjser/has-flag": "5.0.1-cjser.2",
44
+ "@cjser/supports-color": "10.2.2-cjser.2"
45
+ },
46
+ "devDependencies": {
47
+ "ava": "^6.4.1",
48
+ "codecov": "^3.8.3",
49
+ "typescript": "^5.9.3",
50
+ "xo": "^1.2.3"
51
+ },
52
+ "types": "./index.d.ts",
53
+ "main": "./dist-cjser/index.cjs",
54
+ "cjser": {
55
+ "sourceVersion": "4.4.0",
56
+ "cjserVersion": 2,
57
+ "original": {
58
+ "name": "supports-hyperlinks",
59
+ "version": "4.4.0",
60
+ "exports": {
61
+ "types": "./index.d.ts",
62
+ "default": "./index.js"
63
+ },
64
+ "repository": "chalk/supports-hyperlinks",
65
+ "dependencies": {
66
+ "has-flag": "^5.0.1",
67
+ "supports-color": "^10.2.2"
68
+ },
69
+ "files": [
70
+ "index.js",
71
+ "index.d.ts",
72
+ "browser.js"
73
+ ],
74
+ "scripts": {
75
+ "test": "xo && ava && tsc --lib es2022 index.d.ts"
76
+ }
77
+ }
78
+ }
79
+ }
package/readme.md ADDED
@@ -0,0 +1,44 @@
1
+ # supports-hyperlinks
2
+
3
+ > Detect whether a terminal supports hyperlinks
4
+
5
+ Terminal emulators are [starting to support hyperlinks](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda). While many terminals have long detected URL's and linkified them, allowing you to Command-Click or Control-Click them to open a browser, you were forced to print the long unsightly URL's on the screen. As of spring 2017 [a few terminals](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda) began supporting HTML like links, where the link text and destination could be specified separately.
6
+
7
+ This module allows you to detect if hyperlinks are supported in the current Terminal.
8
+
9
+ As this is a new development, we anticipate the list of supported terminals to grow rapidly. Please open an issue or submit a PR as new terminals implement support.
10
+
11
+ ## Install
12
+
13
+ ```sh
14
+ npm install supports-hyperlinks
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```js
20
+ import supportsHyperlinks from 'supports-hyperlinks';
21
+
22
+ if (supportsHyperlinks.stdout) {
23
+ console.log('Terminal stdout supports hyperlinks');
24
+ }
25
+
26
+ if (supportsHyperlinks.stderr) {
27
+ console.log('Terminal stderr supports hyperlinks');
28
+ }
29
+ ```
30
+
31
+ ## API
32
+
33
+ Returns an `Object` with a `stdout` and `stderr` property for testing either streams. Each property is a `boolean`, indicating whether or not hyperlinks are supported.
34
+
35
+ ## Info
36
+
37
+ Obeys the `--no-hyperlinks`, `--hyperlink=always`, and `--hyperlink=never` CLI flags.
38
+
39
+ Can be overridden by the user with the flags `--hyperlinks=always` and `--no-hyperlinks`. For situations where using those flags are not possible, add the environment variable `FORCE_HYPERLINK=1` to forcefully enable hyperlinks or `FORCE_HYPERLINK=0` to forcefully disable. The use of `FORCE_HYPERLINK` overrides all other hyperlink support checks.
40
+
41
+ ## cjser
42
+
43
+ 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.
44
+ Original repository: https://github.com/chalk/supports-hyperlinks