console-toolkit 1.2.0 → 1.2.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/README.md +6 -4
- package/package.json +7 -4
- package/src/strings/split.js +28 -15
package/README.md
CHANGED
|
@@ -89,7 +89,9 @@ BSD 3-Clause License
|
|
|
89
89
|
|
|
90
90
|
## Release history
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
* 1.2.2 *Updated deps.*
|
|
93
|
+
* 1.2.1 *Added support for `Bun.stringWidth()`.*
|
|
94
|
+
* 1.2.0 *Refactored `strings`.*
|
|
95
|
+
* 1.1.1 *Minor bugfixes in `Table`, some improvements, updated deps.*
|
|
96
|
+
* 1.1.0 *Minor improvements, enhanced `Writer` and `Updater`.*
|
|
97
|
+
* 1.0.0 *Initial release.*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "console-toolkit",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "Toolkit to produce a fancy console output (boxes, tables, charts, colors).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -18,7 +18,10 @@
|
|
|
18
18
|
"./style": "./src/style.js"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
|
-
"test": "tape6 --flags FO"
|
|
21
|
+
"test": "tape6 --flags FO",
|
|
22
|
+
"test:bun": "tape6-bun --flags FO",
|
|
23
|
+
"test:deno-original": "tape6-deno --flags FO",
|
|
24
|
+
"test:deno": "deno run -A `tape6-runner main` --flags FO"
|
|
22
25
|
},
|
|
23
26
|
"github": "http://github.com/uhop/console-toolkit",
|
|
24
27
|
"repository": {
|
|
@@ -58,8 +61,8 @@
|
|
|
58
61
|
]
|
|
59
62
|
},
|
|
60
63
|
"devDependencies": {
|
|
61
|
-
"emoji-regex": "^10.
|
|
64
|
+
"emoji-regex": "^10.4.0",
|
|
62
65
|
"get-east-asian-width": "^1.2.0",
|
|
63
|
-
"tape-six": "^0.
|
|
66
|
+
"tape-six": "^0.12.2"
|
|
64
67
|
}
|
|
65
68
|
}
|
package/src/strings/split.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
// Loosely adapted
|
|
1
|
+
// Loosely adapted from https://www.npmjs.com/package/string-width by
|
|
2
2
|
// [Sindre Sorhus](https://www.npmjs.com/~sindresorhus) under the MIT license.
|
|
3
3
|
|
|
4
|
-
let emojiRegex = null
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
try {
|
|
13
|
-
|
|
14
|
-
} catch (error) {
|
|
15
|
-
|
|
4
|
+
let emojiRegex = null,
|
|
5
|
+
eastAsianWidth = null;
|
|
6
|
+
if (!globalThis.Bun) {
|
|
7
|
+
try {
|
|
8
|
+
emojiRegex = (await import('emoji-regex')).default();
|
|
9
|
+
} catch (error) {
|
|
10
|
+
// squelch
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
eastAsianWidth = (await import('get-east-asian-width')).eastAsianWidth;
|
|
14
|
+
} catch (error) {
|
|
15
|
+
// squelch
|
|
16
|
+
}
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
const segmenter = new Intl.Segmenter();
|
|
@@ -22,7 +23,8 @@ export const split = (s, options = {}) => {
|
|
|
22
23
|
if (!s) return {graphemes: [], width: 0};
|
|
23
24
|
|
|
24
25
|
const {ignoreControlSymbols = false, ambiguousAsWide = false} = options,
|
|
25
|
-
eastAsianWidthOptions = {ambiguousAsWide}
|
|
26
|
+
eastAsianWidthOptions = {ambiguousAsWide},
|
|
27
|
+
bunStringWidthOptions = {ambiguousAsNarrow: !ambiguousAsWide};
|
|
26
28
|
|
|
27
29
|
const graphemes = [];
|
|
28
30
|
let width = 0;
|
|
@@ -41,6 +43,12 @@ export const split = (s, options = {}) => {
|
|
|
41
43
|
if (graphemes.length) graphemes[graphemes.length - 1].symbol += segment;
|
|
42
44
|
continue;
|
|
43
45
|
}
|
|
46
|
+
if (globalThis.Bun) {
|
|
47
|
+
const w = Bun.stringWidth(segment, bunStringWidthOptions);
|
|
48
|
+
graphemes.push({symbol: segment, width: w});
|
|
49
|
+
width += w;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
44
52
|
if (emojiRegex && ((emojiRegex.lastIndex = 0), emojiRegex.test(segment))) {
|
|
45
53
|
graphemes.push({symbol: segment, width: 2});
|
|
46
54
|
width += 2;
|
|
@@ -63,7 +71,8 @@ export const size = (s, options = {}) => {
|
|
|
63
71
|
if (!s) return 0;
|
|
64
72
|
|
|
65
73
|
const {ignoreControlSymbols = false, ambiguousAsWide = false} = options,
|
|
66
|
-
eastAsianWidthOptions = {ambiguousAsWide}
|
|
74
|
+
eastAsianWidthOptions = {ambiguousAsWide},
|
|
75
|
+
bunStringWidthOptions = {ambiguousAsNarrow: !ambiguousAsWide};
|
|
67
76
|
|
|
68
77
|
let width = 0;
|
|
69
78
|
for (const {segment} of segmenter.segment(s)) {
|
|
@@ -80,6 +89,10 @@ export const size = (s, options = {}) => {
|
|
|
80
89
|
) {
|
|
81
90
|
continue;
|
|
82
91
|
}
|
|
92
|
+
if (globalThis.Bun) {
|
|
93
|
+
width += Bun.stringWidth(segment, bunStringWidthOptions);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
83
96
|
if (emojiRegex && ((emojiRegex.lastIndex = 0), emojiRegex.test(segment))) {
|
|
84
97
|
width += 2;
|
|
85
98
|
continue;
|