@jsenv/humanize 1.5.0 → 1.5.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.
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { createSupportsColor, isUnicodeSupported,
|
|
1
|
+
import { createSupportsColor, isUnicodeSupported, emojiRegex, eastAsianWidth } from "./jsenv_humanize_node_modules.js";
|
|
2
|
+
import stripAnsi from "strip-ansi";
|
|
2
3
|
import { stripVTControlCharacters } from "node:util";
|
|
4
|
+
import ansiEscapes from "ansi-escapes";
|
|
3
5
|
import "node:process";
|
|
4
6
|
import "node:os";
|
|
5
7
|
import "node:tty";
|
|
@@ -1747,7 +1749,7 @@ const createDynamicLog = ({
|
|
|
1747
1749
|
if (visualLineCount > rows) {
|
|
1748
1750
|
if (clearTerminalAllowed) {
|
|
1749
1751
|
clearAttemptResult = true;
|
|
1750
|
-
return clearTerminal;
|
|
1752
|
+
return ansiEscapes.clearTerminal;
|
|
1751
1753
|
}
|
|
1752
1754
|
// the whole log cannot be cleared because it's vertically to long
|
|
1753
1755
|
// (longer than terminal height)
|
|
@@ -1760,7 +1762,7 @@ const createDynamicLog = ({
|
|
|
1760
1762
|
}
|
|
1761
1763
|
|
|
1762
1764
|
clearAttemptResult = true;
|
|
1763
|
-
return eraseLines(visualLineCount);
|
|
1765
|
+
return ansiEscapes.eraseLines(visualLineCount);
|
|
1764
1766
|
};
|
|
1765
1767
|
|
|
1766
1768
|
const update = (string) => {
|
|
@@ -211,30 +211,6 @@ function isUnicodeSupported() {
|
|
|
211
211
|
|| env.TERMINAL_EMULATOR === 'JetBrains-JediTerm';
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
function ansiRegex({onlyFirst = false} = {}) {
|
|
215
|
-
// Valid string terminator sequences are BEL, ESC\, and 0x9c
|
|
216
|
-
const ST = '(?:\\u0007|\\u001B\\u005C|\\u009C)';
|
|
217
|
-
const pattern = [
|
|
218
|
-
`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?${ST})`,
|
|
219
|
-
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))',
|
|
220
|
-
].join('|');
|
|
221
|
-
|
|
222
|
-
return new RegExp(pattern, onlyFirst ? undefined : 'g');
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
const regex = ansiRegex();
|
|
226
|
-
|
|
227
|
-
function stripAnsi(string) {
|
|
228
|
-
if (typeof string !== 'string') {
|
|
229
|
-
throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// Even though the regex is global, we don't need to reset the `.lastIndex`
|
|
233
|
-
// because unlike `.exec()` and `.test()`, `.replace()` does it automatically
|
|
234
|
-
// and doing it manually has a performance penalty.
|
|
235
|
-
return string.replace(regex, '');
|
|
236
|
-
}
|
|
237
|
-
|
|
238
214
|
const r = String.raw;
|
|
239
215
|
const seq = r`(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})`;
|
|
240
216
|
const sTags = r`\u{E0061}-\u{E007A}`;
|
|
@@ -625,85 +601,4 @@ function eastAsianWidth(codePoint, {ambiguousAsWide = false} = {}) {
|
|
|
625
601
|
return 1;
|
|
626
602
|
}
|
|
627
603
|
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
const isBrowser = globalThis.window?.document !== undefined;
|
|
631
|
-
|
|
632
|
-
globalThis.process?.versions?.node !== undefined;
|
|
633
|
-
|
|
634
|
-
globalThis.process?.versions?.bun !== undefined;
|
|
635
|
-
|
|
636
|
-
globalThis.Deno?.version?.deno !== undefined;
|
|
637
|
-
|
|
638
|
-
globalThis.process?.versions?.electron !== undefined;
|
|
639
|
-
|
|
640
|
-
globalThis.navigator?.userAgent?.includes('jsdom') === true;
|
|
641
|
-
|
|
642
|
-
typeof WorkerGlobalScope !== 'undefined' && globalThis instanceof WorkerGlobalScope;
|
|
643
|
-
|
|
644
|
-
typeof DedicatedWorkerGlobalScope !== 'undefined' && globalThis instanceof DedicatedWorkerGlobalScope;
|
|
645
|
-
|
|
646
|
-
typeof SharedWorkerGlobalScope !== 'undefined' && globalThis instanceof SharedWorkerGlobalScope;
|
|
647
|
-
|
|
648
|
-
typeof ServiceWorkerGlobalScope !== 'undefined' && globalThis instanceof ServiceWorkerGlobalScope;
|
|
649
|
-
|
|
650
|
-
// Note: I'm intentionally not DRYing up the other variables to keep them "lazy".
|
|
651
|
-
const platform = globalThis.navigator?.userAgentData?.platform;
|
|
652
|
-
|
|
653
|
-
platform === 'macOS'
|
|
654
|
-
|| globalThis.navigator?.platform === 'MacIntel' // Even on Apple silicon Macs.
|
|
655
|
-
|| globalThis.navigator?.userAgent?.includes(' Mac ') === true
|
|
656
|
-
|| globalThis.process?.platform === 'darwin';
|
|
657
|
-
|
|
658
|
-
platform === 'Windows'
|
|
659
|
-
|| globalThis.navigator?.platform === 'Win32'
|
|
660
|
-
|| globalThis.process?.platform === 'win32';
|
|
661
|
-
|
|
662
|
-
platform === 'Linux'
|
|
663
|
-
|| globalThis.navigator?.platform?.startsWith('Linux') === true
|
|
664
|
-
|| globalThis.navigator?.userAgent?.includes(' Linux ') === true
|
|
665
|
-
|| globalThis.process?.platform === 'linux';
|
|
666
|
-
|
|
667
|
-
platform === 'Android'
|
|
668
|
-
|| globalThis.navigator?.platform === 'Android'
|
|
669
|
-
|| globalThis.navigator?.userAgent?.includes(' Android ') === true
|
|
670
|
-
|| globalThis.process?.platform === 'android';
|
|
671
|
-
|
|
672
|
-
const ESC = '\u001B[';
|
|
673
|
-
|
|
674
|
-
!isBrowser && process.env.TERM_PROGRAM === 'Apple_Terminal';
|
|
675
|
-
const isWindows = !isBrowser && process.platform === 'win32';
|
|
676
|
-
|
|
677
|
-
isBrowser ? () => {
|
|
678
|
-
throw new Error('`process.cwd()` only works in Node.js, not the browser.');
|
|
679
|
-
} : process.cwd;
|
|
680
|
-
|
|
681
|
-
const cursorUp = (count = 1) => ESC + count + 'A';
|
|
682
|
-
|
|
683
|
-
const cursorLeft = ESC + 'G';
|
|
684
|
-
|
|
685
|
-
const eraseLines = count => {
|
|
686
|
-
let clear = '';
|
|
687
|
-
|
|
688
|
-
for (let i = 0; i < count; i++) {
|
|
689
|
-
clear += eraseLine + (i < count - 1 ? cursorUp() : '');
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
if (count) {
|
|
693
|
-
clear += cursorLeft;
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
return clear;
|
|
697
|
-
};
|
|
698
|
-
const eraseLine = ESC + '2K';
|
|
699
|
-
const eraseScreen = ESC + '2J';
|
|
700
|
-
|
|
701
|
-
const clearTerminal = isWindows
|
|
702
|
-
? `${eraseScreen}${ESC}0f`
|
|
703
|
-
// 1. Erases the screen (Only done in case `2` is not supported)
|
|
704
|
-
// 2. Erases the whole screen including scrollback buffer
|
|
705
|
-
// 3. Moves cursor to the top-left position
|
|
706
|
-
// More info: https://www.real-world-systems.com/docs/ANSIcode.html
|
|
707
|
-
: `${eraseScreen}${ESC}3J${ESC}H`;
|
|
708
|
-
|
|
709
|
-
export { clearTerminal, createSupportsColor, eastAsianWidth, emojiRegex, eraseLines, isUnicodeSupported, stripAnsi };
|
|
604
|
+
export { createSupportsColor, eastAsianWidth, emojiRegex, isUnicodeSupported };
|