@jsenv/core 40.3.3 → 40.5.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.
@@ -0,0 +1,685 @@
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 ('TERM_PROGRAM' in env) {
151
+ const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
152
+
153
+ switch (env.TERM_PROGRAM) {
154
+ case 'iTerm.app': {
155
+ return version >= 3 ? 3 : 2;
156
+ }
157
+
158
+ case 'Apple_Terminal': {
159
+ return 2;
160
+ }
161
+ // No default
162
+ }
163
+ }
164
+
165
+ if (/-256(color)?$/i.test(env.TERM)) {
166
+ return 2;
167
+ }
168
+
169
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
170
+ return 1;
171
+ }
172
+
173
+ if ('COLORTERM' in env) {
174
+ return 1;
175
+ }
176
+
177
+ return min;
178
+ }
179
+
180
+ function createSupportsColor(stream, options = {}) {
181
+ const level = _supportsColor(stream, {
182
+ streamIsTTY: stream && stream.isTTY,
183
+ ...options,
184
+ });
185
+
186
+ return translateLevel(level);
187
+ }
188
+
189
+ ({
190
+ stdout: createSupportsColor({isTTY: tty.isatty(1)}),
191
+ stderr: createSupportsColor({isTTY: tty.isatty(2)}),
192
+ });
193
+
194
+ function isUnicodeSupported() {
195
+ const {env} = process;
196
+ const {TERM, TERM_PROGRAM} = env;
197
+
198
+ if (process.platform !== 'win32') {
199
+ return TERM !== 'linux'; // Linux console (kernel)
200
+ }
201
+
202
+ return Boolean(env.WT_SESSION) // Windows Terminal
203
+ || Boolean(env.TERMINUS_SUBLIME) // Terminus (<0.2.27)
204
+ || env.ConEmuTask === '{cmd::Cmder}' // ConEmu and cmder
205
+ || TERM_PROGRAM === 'Terminus-Sublime'
206
+ || TERM_PROGRAM === 'vscode'
207
+ || TERM === 'xterm-256color'
208
+ || TERM === 'alacritty'
209
+ || TERM === 'rxvt-unicode'
210
+ || TERM === 'rxvt-unicode-256color'
211
+ || env.TERMINAL_EMULATOR === 'JetBrains-JediTerm';
212
+ }
213
+
214
+ const r = String.raw;
215
+ const seq = r`(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})`;
216
+ const sTags = r`\u{E0061}-\u{E007A}`;
217
+ const emojiRegex = () => new RegExp(r`[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[${sTags}]{2}[\u{E0030}-\u{E0039}${sTags}]{1,3}\u{E007F}|${seq}(?:\u200D${seq})*`, 'gu');
218
+
219
+ // Generated code.
220
+
221
+ function isAmbiguous(x) {
222
+ return x === 0xA1
223
+ || x === 0xA4
224
+ || x === 0xA7
225
+ || x === 0xA8
226
+ || x === 0xAA
227
+ || x === 0xAD
228
+ || x === 0xAE
229
+ || x >= 0xB0 && x <= 0xB4
230
+ || x >= 0xB6 && x <= 0xBA
231
+ || x >= 0xBC && x <= 0xBF
232
+ || x === 0xC6
233
+ || x === 0xD0
234
+ || x === 0xD7
235
+ || x === 0xD8
236
+ || x >= 0xDE && x <= 0xE1
237
+ || x === 0xE6
238
+ || x >= 0xE8 && x <= 0xEA
239
+ || x === 0xEC
240
+ || x === 0xED
241
+ || x === 0xF0
242
+ || x === 0xF2
243
+ || x === 0xF3
244
+ || x >= 0xF7 && x <= 0xFA
245
+ || x === 0xFC
246
+ || x === 0xFE
247
+ || x === 0x101
248
+ || x === 0x111
249
+ || x === 0x113
250
+ || x === 0x11B
251
+ || x === 0x126
252
+ || x === 0x127
253
+ || x === 0x12B
254
+ || x >= 0x131 && x <= 0x133
255
+ || x === 0x138
256
+ || x >= 0x13F && x <= 0x142
257
+ || x === 0x144
258
+ || x >= 0x148 && x <= 0x14B
259
+ || x === 0x14D
260
+ || x === 0x152
261
+ || x === 0x153
262
+ || x === 0x166
263
+ || x === 0x167
264
+ || x === 0x16B
265
+ || x === 0x1CE
266
+ || x === 0x1D0
267
+ || x === 0x1D2
268
+ || x === 0x1D4
269
+ || x === 0x1D6
270
+ || x === 0x1D8
271
+ || x === 0x1DA
272
+ || x === 0x1DC
273
+ || x === 0x251
274
+ || x === 0x261
275
+ || x === 0x2C4
276
+ || x === 0x2C7
277
+ || x >= 0x2C9 && x <= 0x2CB
278
+ || x === 0x2CD
279
+ || x === 0x2D0
280
+ || x >= 0x2D8 && x <= 0x2DB
281
+ || x === 0x2DD
282
+ || x === 0x2DF
283
+ || x >= 0x300 && x <= 0x36F
284
+ || x >= 0x391 && x <= 0x3A1
285
+ || x >= 0x3A3 && x <= 0x3A9
286
+ || x >= 0x3B1 && x <= 0x3C1
287
+ || x >= 0x3C3 && x <= 0x3C9
288
+ || x === 0x401
289
+ || x >= 0x410 && x <= 0x44F
290
+ || x === 0x451
291
+ || x === 0x2010
292
+ || x >= 0x2013 && x <= 0x2016
293
+ || x === 0x2018
294
+ || x === 0x2019
295
+ || x === 0x201C
296
+ || x === 0x201D
297
+ || x >= 0x2020 && x <= 0x2022
298
+ || x >= 0x2024 && x <= 0x2027
299
+ || x === 0x2030
300
+ || x === 0x2032
301
+ || x === 0x2033
302
+ || x === 0x2035
303
+ || x === 0x203B
304
+ || x === 0x203E
305
+ || x === 0x2074
306
+ || x === 0x207F
307
+ || x >= 0x2081 && x <= 0x2084
308
+ || x === 0x20AC
309
+ || x === 0x2103
310
+ || x === 0x2105
311
+ || x === 0x2109
312
+ || x === 0x2113
313
+ || x === 0x2116
314
+ || x === 0x2121
315
+ || x === 0x2122
316
+ || x === 0x2126
317
+ || x === 0x212B
318
+ || x === 0x2153
319
+ || x === 0x2154
320
+ || x >= 0x215B && x <= 0x215E
321
+ || x >= 0x2160 && x <= 0x216B
322
+ || x >= 0x2170 && x <= 0x2179
323
+ || x === 0x2189
324
+ || x >= 0x2190 && x <= 0x2199
325
+ || x === 0x21B8
326
+ || x === 0x21B9
327
+ || x === 0x21D2
328
+ || x === 0x21D4
329
+ || x === 0x21E7
330
+ || x === 0x2200
331
+ || x === 0x2202
332
+ || x === 0x2203
333
+ || x === 0x2207
334
+ || x === 0x2208
335
+ || x === 0x220B
336
+ || x === 0x220F
337
+ || x === 0x2211
338
+ || x === 0x2215
339
+ || x === 0x221A
340
+ || x >= 0x221D && x <= 0x2220
341
+ || x === 0x2223
342
+ || x === 0x2225
343
+ || x >= 0x2227 && x <= 0x222C
344
+ || x === 0x222E
345
+ || x >= 0x2234 && x <= 0x2237
346
+ || x === 0x223C
347
+ || x === 0x223D
348
+ || x === 0x2248
349
+ || x === 0x224C
350
+ || x === 0x2252
351
+ || x === 0x2260
352
+ || x === 0x2261
353
+ || x >= 0x2264 && x <= 0x2267
354
+ || x === 0x226A
355
+ || x === 0x226B
356
+ || x === 0x226E
357
+ || x === 0x226F
358
+ || x === 0x2282
359
+ || x === 0x2283
360
+ || x === 0x2286
361
+ || x === 0x2287
362
+ || x === 0x2295
363
+ || x === 0x2299
364
+ || x === 0x22A5
365
+ || x === 0x22BF
366
+ || x === 0x2312
367
+ || x >= 0x2460 && x <= 0x24E9
368
+ || x >= 0x24EB && x <= 0x254B
369
+ || x >= 0x2550 && x <= 0x2573
370
+ || x >= 0x2580 && x <= 0x258F
371
+ || x >= 0x2592 && x <= 0x2595
372
+ || x === 0x25A0
373
+ || x === 0x25A1
374
+ || x >= 0x25A3 && x <= 0x25A9
375
+ || x === 0x25B2
376
+ || x === 0x25B3
377
+ || x === 0x25B6
378
+ || x === 0x25B7
379
+ || x === 0x25BC
380
+ || x === 0x25BD
381
+ || x === 0x25C0
382
+ || x === 0x25C1
383
+ || x >= 0x25C6 && x <= 0x25C8
384
+ || x === 0x25CB
385
+ || x >= 0x25CE && x <= 0x25D1
386
+ || x >= 0x25E2 && x <= 0x25E5
387
+ || x === 0x25EF
388
+ || x === 0x2605
389
+ || x === 0x2606
390
+ || x === 0x2609
391
+ || x === 0x260E
392
+ || x === 0x260F
393
+ || x === 0x261C
394
+ || x === 0x261E
395
+ || x === 0x2640
396
+ || x === 0x2642
397
+ || x === 0x2660
398
+ || x === 0x2661
399
+ || x >= 0x2663 && x <= 0x2665
400
+ || x >= 0x2667 && x <= 0x266A
401
+ || x === 0x266C
402
+ || x === 0x266D
403
+ || x === 0x266F
404
+ || x === 0x269E
405
+ || x === 0x269F
406
+ || x === 0x26BF
407
+ || x >= 0x26C6 && x <= 0x26CD
408
+ || x >= 0x26CF && x <= 0x26D3
409
+ || x >= 0x26D5 && x <= 0x26E1
410
+ || x === 0x26E3
411
+ || x === 0x26E8
412
+ || x === 0x26E9
413
+ || x >= 0x26EB && x <= 0x26F1
414
+ || x === 0x26F4
415
+ || x >= 0x26F6 && x <= 0x26F9
416
+ || x === 0x26FB
417
+ || x === 0x26FC
418
+ || x === 0x26FE
419
+ || x === 0x26FF
420
+ || x === 0x273D
421
+ || x >= 0x2776 && x <= 0x277F
422
+ || x >= 0x2B56 && x <= 0x2B59
423
+ || x >= 0x3248 && x <= 0x324F
424
+ || x >= 0xE000 && x <= 0xF8FF
425
+ || x >= 0xFE00 && x <= 0xFE0F
426
+ || x === 0xFFFD
427
+ || x >= 0x1F100 && x <= 0x1F10A
428
+ || x >= 0x1F110 && x <= 0x1F12D
429
+ || x >= 0x1F130 && x <= 0x1F169
430
+ || x >= 0x1F170 && x <= 0x1F18D
431
+ || x === 0x1F18F
432
+ || x === 0x1F190
433
+ || x >= 0x1F19B && x <= 0x1F1AC
434
+ || x >= 0xE0100 && x <= 0xE01EF
435
+ || x >= 0xF0000 && x <= 0xFFFFD
436
+ || x >= 0x100000 && x <= 0x10FFFD;
437
+ }
438
+
439
+ function isFullWidth(x) {
440
+ return x === 0x3000
441
+ || x >= 0xFF01 && x <= 0xFF60
442
+ || x >= 0xFFE0 && x <= 0xFFE6;
443
+ }
444
+
445
+ function isWide(x) {
446
+ return x >= 0x1100 && x <= 0x115F
447
+ || x === 0x231A
448
+ || x === 0x231B
449
+ || x === 0x2329
450
+ || x === 0x232A
451
+ || x >= 0x23E9 && x <= 0x23EC
452
+ || x === 0x23F0
453
+ || x === 0x23F3
454
+ || x === 0x25FD
455
+ || x === 0x25FE
456
+ || x === 0x2614
457
+ || x === 0x2615
458
+ || x >= 0x2630 && x <= 0x2637
459
+ || x >= 0x2648 && x <= 0x2653
460
+ || x === 0x267F
461
+ || x >= 0x268A && x <= 0x268F
462
+ || x === 0x2693
463
+ || x === 0x26A1
464
+ || x === 0x26AA
465
+ || x === 0x26AB
466
+ || x === 0x26BD
467
+ || x === 0x26BE
468
+ || x === 0x26C4
469
+ || x === 0x26C5
470
+ || x === 0x26CE
471
+ || x === 0x26D4
472
+ || x === 0x26EA
473
+ || x === 0x26F2
474
+ || x === 0x26F3
475
+ || x === 0x26F5
476
+ || x === 0x26FA
477
+ || x === 0x26FD
478
+ || x === 0x2705
479
+ || x === 0x270A
480
+ || x === 0x270B
481
+ || x === 0x2728
482
+ || x === 0x274C
483
+ || x === 0x274E
484
+ || x >= 0x2753 && x <= 0x2755
485
+ || x === 0x2757
486
+ || x >= 0x2795 && x <= 0x2797
487
+ || x === 0x27B0
488
+ || x === 0x27BF
489
+ || x === 0x2B1B
490
+ || x === 0x2B1C
491
+ || x === 0x2B50
492
+ || x === 0x2B55
493
+ || x >= 0x2E80 && x <= 0x2E99
494
+ || x >= 0x2E9B && x <= 0x2EF3
495
+ || x >= 0x2F00 && x <= 0x2FD5
496
+ || x >= 0x2FF0 && x <= 0x2FFF
497
+ || x >= 0x3001 && x <= 0x303E
498
+ || x >= 0x3041 && x <= 0x3096
499
+ || x >= 0x3099 && x <= 0x30FF
500
+ || x >= 0x3105 && x <= 0x312F
501
+ || x >= 0x3131 && x <= 0x318E
502
+ || x >= 0x3190 && x <= 0x31E5
503
+ || x >= 0x31EF && x <= 0x321E
504
+ || x >= 0x3220 && x <= 0x3247
505
+ || x >= 0x3250 && x <= 0xA48C
506
+ || x >= 0xA490 && x <= 0xA4C6
507
+ || x >= 0xA960 && x <= 0xA97C
508
+ || x >= 0xAC00 && x <= 0xD7A3
509
+ || x >= 0xF900 && x <= 0xFAFF
510
+ || x >= 0xFE10 && x <= 0xFE19
511
+ || x >= 0xFE30 && x <= 0xFE52
512
+ || x >= 0xFE54 && x <= 0xFE66
513
+ || x >= 0xFE68 && x <= 0xFE6B
514
+ || x >= 0x16FE0 && x <= 0x16FE4
515
+ || x === 0x16FF0
516
+ || x === 0x16FF1
517
+ || x >= 0x17000 && x <= 0x187F7
518
+ || x >= 0x18800 && x <= 0x18CD5
519
+ || x >= 0x18CFF && x <= 0x18D08
520
+ || x >= 0x1AFF0 && x <= 0x1AFF3
521
+ || x >= 0x1AFF5 && x <= 0x1AFFB
522
+ || x === 0x1AFFD
523
+ || x === 0x1AFFE
524
+ || x >= 0x1B000 && x <= 0x1B122
525
+ || x === 0x1B132
526
+ || x >= 0x1B150 && x <= 0x1B152
527
+ || x === 0x1B155
528
+ || x >= 0x1B164 && x <= 0x1B167
529
+ || x >= 0x1B170 && x <= 0x1B2FB
530
+ || x >= 0x1D300 && x <= 0x1D356
531
+ || x >= 0x1D360 && x <= 0x1D376
532
+ || x === 0x1F004
533
+ || x === 0x1F0CF
534
+ || x === 0x1F18E
535
+ || x >= 0x1F191 && x <= 0x1F19A
536
+ || x >= 0x1F200 && x <= 0x1F202
537
+ || x >= 0x1F210 && x <= 0x1F23B
538
+ || x >= 0x1F240 && x <= 0x1F248
539
+ || x === 0x1F250
540
+ || x === 0x1F251
541
+ || x >= 0x1F260 && x <= 0x1F265
542
+ || x >= 0x1F300 && x <= 0x1F320
543
+ || x >= 0x1F32D && x <= 0x1F335
544
+ || x >= 0x1F337 && x <= 0x1F37C
545
+ || x >= 0x1F37E && x <= 0x1F393
546
+ || x >= 0x1F3A0 && x <= 0x1F3CA
547
+ || x >= 0x1F3CF && x <= 0x1F3D3
548
+ || x >= 0x1F3E0 && x <= 0x1F3F0
549
+ || x === 0x1F3F4
550
+ || x >= 0x1F3F8 && x <= 0x1F43E
551
+ || x === 0x1F440
552
+ || x >= 0x1F442 && x <= 0x1F4FC
553
+ || x >= 0x1F4FF && x <= 0x1F53D
554
+ || x >= 0x1F54B && x <= 0x1F54E
555
+ || x >= 0x1F550 && x <= 0x1F567
556
+ || x === 0x1F57A
557
+ || x === 0x1F595
558
+ || x === 0x1F596
559
+ || x === 0x1F5A4
560
+ || x >= 0x1F5FB && x <= 0x1F64F
561
+ || x >= 0x1F680 && x <= 0x1F6C5
562
+ || x === 0x1F6CC
563
+ || x >= 0x1F6D0 && x <= 0x1F6D2
564
+ || x >= 0x1F6D5 && x <= 0x1F6D7
565
+ || x >= 0x1F6DC && x <= 0x1F6DF
566
+ || x === 0x1F6EB
567
+ || x === 0x1F6EC
568
+ || x >= 0x1F6F4 && x <= 0x1F6FC
569
+ || x >= 0x1F7E0 && x <= 0x1F7EB
570
+ || x === 0x1F7F0
571
+ || x >= 0x1F90C && x <= 0x1F93A
572
+ || x >= 0x1F93C && x <= 0x1F945
573
+ || x >= 0x1F947 && x <= 0x1F9FF
574
+ || x >= 0x1FA70 && x <= 0x1FA7C
575
+ || x >= 0x1FA80 && x <= 0x1FA89
576
+ || x >= 0x1FA8F && x <= 0x1FAC6
577
+ || x >= 0x1FACE && x <= 0x1FADC
578
+ || x >= 0x1FADF && x <= 0x1FAE9
579
+ || x >= 0x1FAF0 && x <= 0x1FAF8
580
+ || x >= 0x20000 && x <= 0x2FFFD
581
+ || x >= 0x30000 && x <= 0x3FFFD;
582
+ }
583
+
584
+ function validate(codePoint) {
585
+ if (!Number.isSafeInteger(codePoint)) {
586
+ throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
587
+ }
588
+ }
589
+
590
+ function eastAsianWidth(codePoint, {ambiguousAsWide = false} = {}) {
591
+ validate(codePoint);
592
+
593
+ if (
594
+ isFullWidth(codePoint)
595
+ || isWide(codePoint)
596
+ || (ambiguousAsWide && isAmbiguous(codePoint))
597
+ ) {
598
+ return 2;
599
+ }
600
+
601
+ return 1;
602
+ }
603
+
604
+ /* globals WorkerGlobalScope, DedicatedWorkerGlobalScope, SharedWorkerGlobalScope, ServiceWorkerGlobalScope */
605
+
606
+ const isBrowser = globalThis.window?.document !== undefined;
607
+
608
+ globalThis.process?.versions?.node !== undefined;
609
+
610
+ globalThis.process?.versions?.bun !== undefined;
611
+
612
+ globalThis.Deno?.version?.deno !== undefined;
613
+
614
+ globalThis.process?.versions?.electron !== undefined;
615
+
616
+ globalThis.navigator?.userAgent?.includes('jsdom') === true;
617
+
618
+ typeof WorkerGlobalScope !== 'undefined' && globalThis instanceof WorkerGlobalScope;
619
+
620
+ typeof DedicatedWorkerGlobalScope !== 'undefined' && globalThis instanceof DedicatedWorkerGlobalScope;
621
+
622
+ typeof SharedWorkerGlobalScope !== 'undefined' && globalThis instanceof SharedWorkerGlobalScope;
623
+
624
+ typeof ServiceWorkerGlobalScope !== 'undefined' && globalThis instanceof ServiceWorkerGlobalScope;
625
+
626
+ // Note: I'm intentionally not DRYing up the other variables to keep them "lazy".
627
+ const platform = globalThis.navigator?.userAgentData?.platform;
628
+
629
+ platform === 'macOS'
630
+ || globalThis.navigator?.platform === 'MacIntel' // Even on Apple silicon Macs.
631
+ || globalThis.navigator?.userAgent?.includes(' Mac ') === true
632
+ || globalThis.process?.platform === 'darwin';
633
+
634
+ platform === 'Windows'
635
+ || globalThis.navigator?.platform === 'Win32'
636
+ || globalThis.process?.platform === 'win32';
637
+
638
+ platform === 'Linux'
639
+ || globalThis.navigator?.platform?.startsWith('Linux') === true
640
+ || globalThis.navigator?.userAgent?.includes(' Linux ') === true
641
+ || globalThis.process?.platform === 'linux';
642
+
643
+ platform === 'Android'
644
+ || globalThis.navigator?.platform === 'Android'
645
+ || globalThis.navigator?.userAgent?.includes(' Android ') === true
646
+ || globalThis.process?.platform === 'android';
647
+
648
+ const ESC = '\u001B[';
649
+
650
+ !isBrowser && process.env.TERM_PROGRAM === 'Apple_Terminal';
651
+ const isWindows = !isBrowser && process.platform === 'win32';
652
+
653
+ isBrowser ? () => {
654
+ throw new Error('`process.cwd()` only works in Node.js, not the browser.');
655
+ } : process.cwd;
656
+
657
+ const cursorUp = (count = 1) => ESC + count + 'A';
658
+
659
+ const cursorLeft = ESC + 'G';
660
+
661
+ const eraseLines = count => {
662
+ let clear = '';
663
+
664
+ for (let i = 0; i < count; i++) {
665
+ clear += eraseLine + (i < count - 1 ? cursorUp() : '');
666
+ }
667
+
668
+ if (count) {
669
+ clear += cursorLeft;
670
+ }
671
+
672
+ return clear;
673
+ };
674
+ const eraseLine = ESC + '2K';
675
+ const eraseScreen = ESC + '2J';
676
+
677
+ const clearTerminal = isWindows
678
+ ? `${eraseScreen}${ESC}0f`
679
+ // 1. Erases the screen (Only done in case `2` is not supported)
680
+ // 2. Erases the whole screen including scrollback buffer
681
+ // 3. Moves cursor to the top-left position
682
+ // More info: https://www.real-world-systems.com/docs/ANSIcode.html
683
+ : `${eraseScreen}${ESC}3J${ESC}H`;
684
+
685
+ export { clearTerminal, createSupportsColor, eastAsianWidth, emojiRegex, eraseLines, isUnicodeSupported };