@visulima/string 3.0.0 → 3.1.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.
- package/CHANGELOG.md +7 -0
- package/dist/align-text.d.ts +29 -29
- package/dist/case/camel-case.d.ts +16 -16
- package/dist/case/camel-case.js +1 -1
- package/dist/case/capital-case.d.ts +13 -13
- package/dist/case/capital-case.js +1 -1
- package/dist/case/constant-case.d.ts +13 -13
- package/dist/case/dot-case.d.ts +13 -13
- package/dist/case/flat-case.d.ts +11 -11
- package/dist/case/flip-case.d.ts +14 -14
- package/dist/case/flip-case.js +1 -1
- package/dist/case/identify-case.d.ts +14 -14
- package/dist/case/index.d.ts +7 -7
- package/dist/case/kebab-case.d.ts +22 -22
- package/dist/case/kebab-case.js +1 -1
- package/dist/case/lower-first.d.ts +12 -12
- package/dist/case/no-case.d.ts +13 -13
- package/dist/case/pascal-case.d.ts +16 -16
- package/dist/case/pascal-case.js +1 -1
- package/dist/case/pascal-snake-case.d.ts +13 -13
- package/dist/case/pascal-snake-case.js +1 -1
- package/dist/case/path-case.d.ts +13 -13
- package/dist/case/sentence-case.d.ts +13 -13
- package/dist/case/sentence-case.js +1 -1
- package/dist/case/snake-case.d.ts +13 -13
- package/dist/case/split-by-case.d.ts +20 -20
- package/dist/case/split-by-case.js +1 -1
- package/dist/case/title-case.d.ts +11 -11
- package/dist/case/title-case.js +1 -1
- package/dist/case/train-case.d.ts +13 -13
- package/dist/case/train-case.js +1 -1
- package/dist/case/upper-first.d.ts +12 -12
- package/dist/closest-string.d.ts +28 -28
- package/dist/compare-similarity.d.ts +33 -33
- package/dist/count-occurrences.d.ts +6 -6
- package/dist/direction.d.ts +4 -4
- package/dist/east-asian-width.d.ts +20 -14
- package/dist/excerpt.d.ts +18 -18
- package/dist/get-string-truncated-width.d.ts +131 -131
- package/dist/get-string-truncated-width.js +1 -1
- package/dist/get-string-width.d.ts +56 -56
- package/dist/indent.d.ts +8 -7
- package/dist/index.d.ts +2 -2
- package/dist/is-fullwidth-code-point.d.ts +4 -4
- package/dist/levenshtein.d.ts +19 -19
- package/dist/native-string-types.d.ts +212 -228
- package/dist/outdent.d.ts +64 -64
- package/dist/packem_shared/generate-cache-key-B_0X7MKm.js +1 -0
- package/dist/packem_shared/strip-vt-control-characters-BW1RglLp.js +1 -0
- package/dist/packem_shared/types.d-CMNqA5bi.d.ts +402 -0
- package/dist/packem_shared/types.d-LgsTR37y.d.ts +360 -0
- package/dist/replace-string.d.ts +7 -7
- package/dist/slice.d.ts +38 -38
- package/dist/slice.js +1 -1
- package/dist/slugify.d.ts +9 -9
- package/dist/test/utils.d.ts +14 -14
- package/dist/test/utils.js +11 -11
- package/dist/test/vitest.d.ts +2 -2
- package/dist/transliterate.d.ts +7 -7
- package/dist/transliterate.js +2 -2
- package/dist/truncate.d.ts +37 -37
- package/dist/utilities.d.ts +23 -23
- package/dist/word-similarity-sort.d.ts +32 -32
- package/dist/word-wrap.d.ts +33 -33
- package/dist/word-wrap.js +7 -7
- package/package.json +1 -1
- package/dist/packem_shared/generate-cache-key-BqU1Cqwm.js +0 -1
- package/dist/packem_shared/types.d-CmNvyl4l.d.ts +0 -360
- package/dist/packem_shared/types.d-fhe030jX.d.ts +0 -402
|
@@ -1,174 +1,174 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Configuration options for string width calculation and truncation.
|
|
3
|
-
* @example
|
|
4
|
-
* ```typescript
|
|
5
|
-
* // Basic usage with defaults
|
|
6
|
-
* const options: StringTruncatedWidthOptions = {};
|
|
7
|
-
*
|
|
8
|
-
* // Custom character widths
|
|
9
|
-
* const options: StringTruncatedWidthOptions = {
|
|
10
|
-
* regularWidth: 2,
|
|
11
|
-
* emojiWidth: 3,
|
|
12
|
-
* tabWidth: 4
|
|
13
|
-
* };
|
|
14
|
-
*
|
|
15
|
-
* // Truncation settings
|
|
16
|
-
* const options: StringTruncatedWidthOptions = {
|
|
17
|
-
* limit: 10,
|
|
18
|
-
* ellipsis: '...',
|
|
19
|
-
* ellipsisWidth: 3
|
|
20
|
-
* };
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
2
|
+
* Configuration options for string width calculation and truncation.
|
|
3
|
+
* @example
|
|
4
|
+
* ```typescript
|
|
5
|
+
* // Basic usage with defaults
|
|
6
|
+
* const options: StringTruncatedWidthOptions = {};
|
|
7
|
+
*
|
|
8
|
+
* // Custom character widths
|
|
9
|
+
* const options: StringTruncatedWidthOptions = {
|
|
10
|
+
* regularWidth: 2,
|
|
11
|
+
* emojiWidth: 3,
|
|
12
|
+
* tabWidth: 4
|
|
13
|
+
* };
|
|
14
|
+
*
|
|
15
|
+
* // Truncation settings
|
|
16
|
+
* const options: StringTruncatedWidthOptions = {
|
|
17
|
+
* limit: 10,
|
|
18
|
+
* ellipsis: '...',
|
|
19
|
+
* ellipsisWidth: 3
|
|
20
|
+
* };
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
23
|
interface StringTruncatedWidthOptions {
|
|
24
24
|
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
* Count [ambiguous width characters](https://www.unicode.org/reports/tr11/#Ambiguous) as having narrow width (count of 1 (regular)) instead of wide width (count of 2 (wide)).
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
28
|
ambiguousIsNarrow?: boolean;
|
|
29
29
|
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
* Width of ANSI escape sequences
|
|
31
|
+
* @default 0
|
|
32
|
+
*/
|
|
33
33
|
ansiWidth?: number;
|
|
34
34
|
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
* Width of control characters
|
|
36
|
+
* @default 0
|
|
37
|
+
*/
|
|
38
38
|
controlWidth?: number;
|
|
39
39
|
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
* Whether to count ANSI escape codes in width calculation
|
|
41
|
+
* @default false
|
|
42
|
+
*/
|
|
43
43
|
countAnsiEscapeCodes?: boolean;
|
|
44
44
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
* Text appended to the string when it is truncated
|
|
46
|
+
* @default ''
|
|
47
|
+
*/
|
|
48
48
|
ellipsis?: string;
|
|
49
49
|
/**
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
* Width of the ellipsis string
|
|
51
|
+
* If not provided, it will be calculated using getStringTruncatedWidth
|
|
52
|
+
*/
|
|
53
53
|
ellipsisWidth?: number;
|
|
54
54
|
/**
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
* Width of emoji characters
|
|
56
|
+
* @default 2
|
|
57
|
+
*/
|
|
58
58
|
emojiWidth?: number;
|
|
59
59
|
/**
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
* Width of full-width characters
|
|
61
|
+
* @default 2
|
|
62
|
+
*/
|
|
63
63
|
fullWidth?: number;
|
|
64
64
|
/**
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
* Width of half-width characters
|
|
66
|
+
* @default 1
|
|
67
|
+
*/
|
|
68
68
|
halfWidth?: number;
|
|
69
69
|
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
* Maximum width limit for the string
|
|
71
|
+
* @default Infinity
|
|
72
|
+
*/
|
|
73
73
|
limit?: number;
|
|
74
74
|
/**
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
* Width of regular characters
|
|
76
|
+
* @default 1
|
|
77
|
+
*/
|
|
78
78
|
regularWidth?: number;
|
|
79
79
|
/**
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
* Width of tab characters
|
|
81
|
+
* @default 8
|
|
82
|
+
*/
|
|
83
83
|
tabWidth?: number;
|
|
84
84
|
/**
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
* Width of wide characters
|
|
86
|
+
* @default 2
|
|
87
|
+
*/
|
|
88
88
|
wideWidth?: number;
|
|
89
89
|
}
|
|
90
90
|
/**
|
|
91
|
-
* Result object returned by getStringTruncatedWidth containing width calculation and the truncation details.
|
|
92
|
-
* @example
|
|
93
|
-
* ```typescript
|
|
94
|
-
* // No truncation
|
|
95
|
-
* const result: StringTruncatedWidthResult = {
|
|
96
|
-
* width: 5, // Total visual width
|
|
97
|
-
* truncated: false, // String was not truncated
|
|
98
|
-
* ellipsed: false, // No ellipsis added
|
|
99
|
-
* index: 5, // Full string length
|
|
100
|
-
* };
|
|
101
|
-
*
|
|
102
|
-
* // With truncation
|
|
103
|
-
* const result: StringTruncatedWidthResult = {
|
|
104
|
-
* width: 8, // Width including ellipsis
|
|
105
|
-
* truncated: true, // String was truncated
|
|
106
|
-
* ellipsed: true, // Ellipsis was added
|
|
107
|
-
* index: 5, // Truncation point
|
|
108
|
-
* };
|
|
109
|
-
* ```
|
|
110
|
-
*/
|
|
91
|
+
* Result object returned by getStringTruncatedWidth containing width calculation and the truncation details.
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* // No truncation
|
|
95
|
+
* const result: StringTruncatedWidthResult = {
|
|
96
|
+
* width: 5, // Total visual width
|
|
97
|
+
* truncated: false, // String was not truncated
|
|
98
|
+
* ellipsed: false, // No ellipsis added
|
|
99
|
+
* index: 5, // Full string length
|
|
100
|
+
* };
|
|
101
|
+
*
|
|
102
|
+
* // With truncation
|
|
103
|
+
* const result: StringTruncatedWidthResult = {
|
|
104
|
+
* width: 8, // Width including ellipsis
|
|
105
|
+
* truncated: true, // String was truncated
|
|
106
|
+
* ellipsed: true, // Ellipsis was added
|
|
107
|
+
* index: 5, // Truncation point
|
|
108
|
+
* };
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
111
|
interface StringTruncatedWidthResult {
|
|
112
112
|
/**
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
* Whether an ellipsis was added
|
|
114
|
+
*/
|
|
115
115
|
ellipsed: boolean;
|
|
116
116
|
/**
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
* The index at which truncation occurred (if any)
|
|
118
|
+
*/
|
|
119
119
|
index: number;
|
|
120
120
|
/**
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
* Whether the string was truncated
|
|
122
|
+
*/
|
|
123
123
|
truncated: boolean;
|
|
124
124
|
/**
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
* The calculated width of the string
|
|
126
|
+
*/
|
|
127
127
|
width: number;
|
|
128
128
|
}
|
|
129
129
|
/**
|
|
130
|
-
* Calculate the visual width of a string with optional truncation, handling various Unicode character types.
|
|
131
|
-
* @example
|
|
132
|
-
* ```typescript
|
|
133
|
-
* // Basic width calculation
|
|
134
|
-
* getStringTruncatedWidth('hello');
|
|
135
|
-
* // => { width: 5, truncated: false, ellipsed: false, index: 5 }
|
|
136
|
-
*
|
|
137
|
-
* // With truncation
|
|
138
|
-
* getStringTruncatedWidth('hello world', {
|
|
139
|
-
* limit: 8,
|
|
140
|
-
* ellipsis: '...'
|
|
141
|
-
* });
|
|
142
|
-
* // => { width: 8, truncated: true, ellipsed: true, index: 5 }
|
|
143
|
-
*
|
|
144
|
-
* // With custom character widths
|
|
145
|
-
* getStringTruncatedWidth('あいう', {
|
|
146
|
-
* fullWidth: 2,
|
|
147
|
-
* ambiguousIsNarrow: true
|
|
148
|
-
* });
|
|
149
|
-
* // => { width: 6, truncated: false, ellipsed: false, index: 3 }
|
|
150
|
-
*
|
|
151
|
-
* // With combining characters
|
|
152
|
-
* getStringTruncatedWidth('e\u0301'); // Latin e with acute
|
|
153
|
-
* // => { width: 1, truncated: false, ellipsed: false, index: 2 }
|
|
154
|
-
*
|
|
155
|
-
* getStringTruncatedWidth('ก\u0e31'); // Thai character with vowel mark
|
|
156
|
-
* // => { width: 1, truncated: false, ellipsed: false, index: 2 }
|
|
157
|
-
* ```
|
|
158
|
-
*
|
|
159
|
-
* Features:
|
|
160
|
-
* - Full Unicode support including combining marks from various scripts
|
|
161
|
-
* - Accurate width calculation for emoji sequences
|
|
162
|
-
* - ANSI escape code handling
|
|
163
|
-
* - Customizable character widths
|
|
164
|
-
* - Optional string truncation with ellipsis
|
|
165
|
-
* @param input The string to calculate the width for
|
|
166
|
-
* @param options Configuration options for width calculation and truncation
|
|
167
|
-
* @returns Result object containing:
|
|
168
|
-
* - width: The calculated visual width of the string
|
|
169
|
-
* - truncated: Whether the string was truncated
|
|
170
|
-
* - ellipsed: Whether an ellipsis was added
|
|
171
|
-
* - index: The index at which truncation occurred (if any)
|
|
172
|
-
*/
|
|
130
|
+
* Calculate the visual width of a string with optional truncation, handling various Unicode character types.
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* // Basic width calculation
|
|
134
|
+
* getStringTruncatedWidth('hello');
|
|
135
|
+
* // => { width: 5, truncated: false, ellipsed: false, index: 5 }
|
|
136
|
+
*
|
|
137
|
+
* // With truncation
|
|
138
|
+
* getStringTruncatedWidth('hello world', {
|
|
139
|
+
* limit: 8,
|
|
140
|
+
* ellipsis: '...'
|
|
141
|
+
* });
|
|
142
|
+
* // => { width: 8, truncated: true, ellipsed: true, index: 5 }
|
|
143
|
+
*
|
|
144
|
+
* // With custom character widths
|
|
145
|
+
* getStringTruncatedWidth('あいう', {
|
|
146
|
+
* fullWidth: 2,
|
|
147
|
+
* ambiguousIsNarrow: true
|
|
148
|
+
* });
|
|
149
|
+
* // => { width: 6, truncated: false, ellipsed: false, index: 3 }
|
|
150
|
+
*
|
|
151
|
+
* // With combining characters
|
|
152
|
+
* getStringTruncatedWidth('e\u0301'); // Latin e with acute
|
|
153
|
+
* // => { width: 1, truncated: false, ellipsed: false, index: 2 }
|
|
154
|
+
*
|
|
155
|
+
* getStringTruncatedWidth('ก\u0e31'); // Thai character with vowel mark
|
|
156
|
+
* // => { width: 1, truncated: false, ellipsed: false, index: 2 }
|
|
157
|
+
* ```
|
|
158
|
+
*
|
|
159
|
+
* Features:
|
|
160
|
+
* - Full Unicode support including combining marks from various scripts
|
|
161
|
+
* - Accurate width calculation for emoji sequences
|
|
162
|
+
* - ANSI escape code handling
|
|
163
|
+
* - Customizable character widths
|
|
164
|
+
* - Optional string truncation with ellipsis
|
|
165
|
+
* @param input The string to calculate the width for
|
|
166
|
+
* @param options Configuration options for width calculation and truncation
|
|
167
|
+
* @returns Result object containing:
|
|
168
|
+
* - width: The calculated visual width of the string
|
|
169
|
+
* - truncated: Whether the string was truncated
|
|
170
|
+
* - ellipsed: Whether an ellipsis was added
|
|
171
|
+
* - index: The index at which truncation occurred (if any)
|
|
172
|
+
*/
|
|
173
173
|
declare const getStringTruncatedWidth: (input: string, options?: StringTruncatedWidthOptions) => StringTruncatedWidthResult;
|
|
174
174
|
export { StringTruncatedWidthOptions, StringTruncatedWidthResult, getStringTruncatedWidth };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{eastAsianWidthType as j}from"./packem_shared/eastAsianWidth-DJV8Kqd-.js";import{R as
|
|
1
|
+
import{eastAsianWidthType as j}from"./packem_shared/eastAsianWidth-DJV8Kqd-.js";import{R as O,a as m,b as _}from"./packem_shared/constants-aPzGW29R.js";const E=new Map,y=i=>[i.ambiguousIsNarrow?1:0,i.control,i.fullWidth,i.regular,i.wide].join("|"),z=i=>{const t=y(i.width);let e=E.get(t);return e||(e=new Map,E.set(t,e)),e},b=new RegExp(O.source,"y"),x=new RegExp(_.source,"uy"),g=/(?:[\u0020-\u007E\u00A0-\u00FF](?!\uFE0F)){1,1000}/y,R=i=>i>=32&&i<=126?"latin":i===8203||i===8204||i===8205||i===8288?"zero":i<=31||i>=127&&i<=159?"control":i>=160&&i<=255||i>=9472&&i<=9599?"latin":i>=4352&&i<=4607||i>=11904&&i<=40959||i>=44032&&i<=55215||i>=63744&&i<=64255||i>=65280&&i<=65519&&!(i>=65377&&i<=65439)||i>=12352&&i<=12543?"wide":i===8230?"latin":"other",B=(i,t)=>{const e=z(t),s=Math.floor(i/65536),u=i%65536;let c=e.get(s);if(c||(c=new Map,e.set(s,c)),c.has(u))return c.get(u);let a;switch(R(i)){case"control":{a=t.width.control;break}case"latin":{a=t.width.regular;break}case"wide":{a=t.width.wide;break}case"zero":{a=0;break}default:switch(j(i)){case"ambiguous":{a=t.width.ambiguousIsNarrow?t.width.regular:t.width.wide;break}case"fullwidth":{a=t.width.fullWidth;break}case"wide":{a=t.width.wide;break}default:a=t.width.regular}}return c.set(u,a),a},P=i=>i>=768&&i<=879||i>=6832&&i<=6911||i>=7616&&i<=7679||i>=8400&&i<=8447||i>=65056&&i<=65071||i>=917760&&i<=917999||i>=65024&&i<=65039||i>=3633&&i<=3642||i>=3655&&i<=3662||i>=3761&&i<=3769||i>=3771&&i<=3772||i>=3784&&i<=3789||i>=2304&&i<=2307||i>=2362&&i<=2383||i>=2385&&i<=2391||i>=2402&&i<=2403||i>=2433&&i<=2435||i>=2492&&i<=2500||i>=2509&&i<=2509||i>=2561&&i<=2563||i>=2620&&i<=2637||i>=1611&&i<=1631||i>=1648&&i<=1648||i>=1750&&i<=1773||i>=2276&&i<=2302||i>=1425&&i<=1469||i>=1471&&i<=1471||i>=1473&&i<=1474||i>=1476&&i<=1477||i>=1479&&i<=1479||i>=3893&&i<=3893||i>=3895&&i<=3895||i>=3897&&i<=3897||i>=3953&&i<=3966||i>=3968&&i<=3972||i>=3974&&i<=3975?!0:i>=768&&i<=777||i>=803&&i<=803,A=(i,t={})=>{if(!i||i.length===0)return{ellipsed:!1,index:0,truncated:!1,width:0};const e={truncation:{countAnsiEscapeCodes:t.countAnsiEscapeCodes??!1,ellipsis:t.ellipsis??"",ellipsisWidth:t.ellipsisWidth??(t.ellipsis?A(t.ellipsis,{...t,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width:0),limit:t.limit??Number.POSITIVE_INFINITY},width:{ambiguousIsNarrow:t.ambiguousIsNarrow??!1,ansi:t.ansiWidth??0,control:t.controlWidth??0,emoji:t.emojiWidth??2,fullWidth:t.fullWidth??2,halfWidth:t.halfWidth??1,regular:t.regularWidth??1,tab:t.tabWidth??8,wide:t.wideWidth??2}},s=Math.max(0,e.truncation.limit-e.truncation.ellipsisWidth),{length:u}=i,c=u>1e4;let a=0,n=0,l=u,r=!1;const T=i.includes("\x1B")||i.includes("");for(;a<u;){if(T&&(i[a]==="\x1B"||i[a]==="")){if(i.startsWith("\x1B]8;;",a)){const o="\x1B]8;;\x07",h=o.length,W=i.indexOf("\x07",a+5);if(W!==-1){const p=i.indexOf(o,W+1);if(p!==-1){const F=p+h,C=i.slice(W+1,p).replace(O,""),N=A(C,{ambiguousIsNarrow:e.width.ambiguousIsNarrow,ansiWidth:e.width.ansi,controlWidth:e.width.control,countAnsiEscapeCodes:!1,ellipsis:e.truncation.ellipsis,ellipsisWidth:e.truncation.ellipsisWidth,emojiWidth:e.width.emoji,fullWidth:e.width.fullWidth,halfWidth:e.width.halfWidth,limit:Math.max(0,s-n),regularWidth:e.width.regular,tabWidth:e.width.tab,wideWidth:e.width.wide}),I=N.width;if(N.truncated)r=!0,l=Math.min(l,a);else if(n+I>s&&(l=Math.min(l,a),r=!0,n+I>e.truncation.limit))break;if(n+=I,a=F,r&&n>=e.truncation.limit)break;continue}}}if(b.lastIndex=a,b.test(i)){const o=b.lastIndex-a,h=e.truncation.countAnsiEscapeCodes?o:e.width.ansi;if(n+h>s&&(l=Math.min(l,a),n+h>e.truncation.limit)){r=!0;break}n+=h,a=b.lastIndex;continue}}const w=i.codePointAt(a);if(w===8203||w===65279||w>=8288&&w<=8292){a+=1;continue}if(w===9){if(n+e.width.tab>s&&(l=Math.min(l,a),n+e.width.tab>e.truncation.limit)){r=!0;break}n+=e.width.tab,a+=1;continue}if(g.lastIndex=a,g.test(i)){const o=(g.lastIndex-a)*e.width.regular;if(n+o>s){const h=e.width.regular>0?Math.floor((s-n)/e.width.regular):0;if(l=Math.min(l,a+h),n+o>e.truncation.limit){r=!0;break}}n+=o,a=g.lastIndex;continue}if((w<=31||w>=127&&w<=159)&&(m.lastIndex=a,m.test(i))){const o=(m.lastIndex-a)*e.width.control;if(n+o>s){const h=e.width.control>0?Math.floor((s-n)/e.width.control):0;if(l=Math.min(l,a+h),n+o>e.truncation.limit){r=!0;break}}n+=o,a=m.lastIndex;continue}if(x.lastIndex=a,x.test(i)){if(n+e.width.emoji>s&&(l=Math.min(l,a),n+e.width.emoji>e.truncation.limit)){r=!0;break}n+=e.width.emoji,a=x.lastIndex;continue}const f=i.codePointAt(a)??0;if(P(f)){a+=f>65535?2:1;continue}let d;if(c)d=B(f,e);else switch(R(f)){case"control":{d=e.width.control;break}case"latin":{d=e.width.regular;break}case"wide":{d=e.width.wide;break}case"zero":{d=0;break}default:switch(j(f)){case"ambiguous":{d=e.width.ambiguousIsNarrow?e.width.regular:e.width.wide;break}case"fullwidth":{d=e.width.fullWidth;break}case"wide":{d=e.width.wide;break}default:d=e.width.regular}}if(n+d>s&&(l=Math.min(l,a),n+d>e.truncation.limit)){r=!0;break}n+=d,a+=f>65535?2:1}let k=n,M=!1;return r&&e.truncation.limit>=e.truncation.ellipsisWidth&&(k=e.truncation.limit,M=!0),{ellipsed:M,index:r?l:u,truncated:r,width:k}};export{A as getStringTruncatedWidth};
|
|
@@ -1,62 +1,62 @@
|
|
|
1
1
|
import { StringTruncatedWidthOptions } from "./get-string-truncated-width.js";
|
|
2
2
|
/**
|
|
3
|
-
* Configuration options for string width calculation without truncation support.
|
|
4
|
-
* This type excludes truncation-related options from StringTruncatedWidthOptions.
|
|
5
|
-
* @example
|
|
6
|
-
* ```typescript
|
|
7
|
-
* // Basic usage with defaults
|
|
8
|
-
* const options: StringWidthOptions = {};
|
|
9
|
-
*
|
|
10
|
-
* // Custom character widths
|
|
11
|
-
* const options: StringWidthOptions = {
|
|
12
|
-
* regularWidth: 2,
|
|
13
|
-
* emojiWidth: 3,
|
|
14
|
-
* tabWidth: 4
|
|
15
|
-
* };
|
|
16
|
-
*
|
|
17
|
-
* // Unicode handling options
|
|
18
|
-
* const options: StringWidthOptions = {
|
|
19
|
-
* ambiguousIsNarrow: true,
|
|
20
|
-
* fullWidth: 2,
|
|
21
|
-
* wideWidth: 2
|
|
22
|
-
* };
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
3
|
+
* Configuration options for string width calculation without truncation support.
|
|
4
|
+
* This type excludes truncation-related options from StringTruncatedWidthOptions.
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* // Basic usage with defaults
|
|
8
|
+
* const options: StringWidthOptions = {};
|
|
9
|
+
*
|
|
10
|
+
* // Custom character widths
|
|
11
|
+
* const options: StringWidthOptions = {
|
|
12
|
+
* regularWidth: 2,
|
|
13
|
+
* emojiWidth: 3,
|
|
14
|
+
* tabWidth: 4
|
|
15
|
+
* };
|
|
16
|
+
*
|
|
17
|
+
* // Unicode handling options
|
|
18
|
+
* const options: StringWidthOptions = {
|
|
19
|
+
* ambiguousIsNarrow: true,
|
|
20
|
+
* fullWidth: 2,
|
|
21
|
+
* wideWidth: 2
|
|
22
|
+
* };
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
25
|
type StringWidthOptions = Omit<StringTruncatedWidthOptions, "ellipsis" | "ellipsisWidth" | "limit">;
|
|
26
26
|
/**
|
|
27
|
-
* Calculate the visual width of a string, taking into account Unicode characters, emojis, and ANSI escape codes.
|
|
28
|
-
* @example
|
|
29
|
-
* ```typescript
|
|
30
|
-
* // Basic usage
|
|
31
|
-
* getStringWidth('hello');
|
|
32
|
-
* // => 5
|
|
33
|
-
*
|
|
34
|
-
* getStringWidth('👋 hello');
|
|
35
|
-
* // => 7
|
|
36
|
-
*
|
|
37
|
-
* // With custom character widths
|
|
38
|
-
* getStringWidth('hello', { regularWidth: 2 });
|
|
39
|
-
* // => 10
|
|
40
|
-
*
|
|
41
|
-
* getStringWidth('あいう', { ambiguousIsNarrow: true });
|
|
42
|
-
* // => 3
|
|
43
|
-
*
|
|
44
|
-
* // With combining characters
|
|
45
|
-
* getStringWidth('e\u0301'); // Latin e with acute
|
|
46
|
-
* // => 1
|
|
47
|
-
*
|
|
48
|
-
* getStringWidth('\u0e01\u0e31'); // Thai character with vowel mark
|
|
49
|
-
* // => 1
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* Features:
|
|
53
|
-
* - Full Unicode support including combining marks
|
|
54
|
-
* - Accurate width calculation for emoji sequences
|
|
55
|
-
* - ANSI escape code handling
|
|
56
|
-
* - Customizable character widths
|
|
57
|
-
* @param input The string to calculate the width for
|
|
58
|
-
* @param options Configuration options for width calculation
|
|
59
|
-
* @returns The calculated visual width of the string
|
|
60
|
-
*/
|
|
27
|
+
* Calculate the visual width of a string, taking into account Unicode characters, emojis, and ANSI escape codes.
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* // Basic usage
|
|
31
|
+
* getStringWidth('hello');
|
|
32
|
+
* // => 5
|
|
33
|
+
*
|
|
34
|
+
* getStringWidth('👋 hello');
|
|
35
|
+
* // => 7
|
|
36
|
+
*
|
|
37
|
+
* // With custom character widths
|
|
38
|
+
* getStringWidth('hello', { regularWidth: 2 });
|
|
39
|
+
* // => 10
|
|
40
|
+
*
|
|
41
|
+
* getStringWidth('あいう', { ambiguousIsNarrow: true });
|
|
42
|
+
* // => 3
|
|
43
|
+
*
|
|
44
|
+
* // With combining characters
|
|
45
|
+
* getStringWidth('e\u0301'); // Latin e with acute
|
|
46
|
+
* // => 1
|
|
47
|
+
*
|
|
48
|
+
* getStringWidth('\u0e01\u0e31'); // Thai character with vowel mark
|
|
49
|
+
* // => 1
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* Features:
|
|
53
|
+
* - Full Unicode support including combining marks
|
|
54
|
+
* - Accurate width calculation for emoji sequences
|
|
55
|
+
* - ANSI escape code handling
|
|
56
|
+
* - Customizable character widths
|
|
57
|
+
* @param input The string to calculate the width for
|
|
58
|
+
* @param options Configuration options for width calculation
|
|
59
|
+
* @returns The calculated visual width of the string
|
|
60
|
+
*/
|
|
61
61
|
declare const getStringWidth: (input: string, options?: StringWidthOptions) => number;
|
|
62
62
|
export { StringWidthOptions, getStringWidth };
|
package/dist/indent.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
interface Options {
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
@default ' '
|
|
5
|
-
*/
|
|
6
|
-
readonly indent?: string;
|
|
3
|
+
The string to use for the indent.
|
|
7
4
|
|
|
5
|
+
@default ' '
|
|
6
|
+
*/
|
|
7
|
+
readonly indent?: string;
|
|
8
8
|
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
Also indent empty lines.
|
|
10
|
+
|
|
11
|
+
@default false
|
|
12
|
+
*/
|
|
12
13
|
readonly includeEmptyLines?: boolean;
|
|
13
14
|
}
|
|
14
15
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export { default as snakeCase } from "./case/snake-case.js";
|
|
|
17
17
|
export { type SplitOptions, splitByCase } from "./case/split-by-case.js";
|
|
18
18
|
export { default as titleCase } from "./case/title-case.js";
|
|
19
19
|
export { default as trainCase } from "./case/train-case.js";
|
|
20
|
-
export type { C as CamelCase, a as CapitalCase, b as CaseOptions, c as ConstantCase, D as DotCase, F as FlatCase, d as FlipCase, I as IdentifyCase, K as KebabCase, L as LocaleOptions, e as LowerFirst, N as NoCase, P as PascalCase, f as PascalSnakeCase, g as PathCase, S as SentenceCase, h as SnakeCase, i as SplitByCase, T as TitleCase, j as TrainCase, U as UpperFirst } from "./packem_shared/types.d-
|
|
20
|
+
export type { C as CamelCase, a as CapitalCase, b as CaseOptions, c as ConstantCase, D as DotCase, F as FlatCase, d as FlipCase, I as IdentifyCase, K as KebabCase, L as LocaleOptions, e as LowerFirst, N as NoCase, P as PascalCase, f as PascalSnakeCase, g as PathCase, S as SentenceCase, h as SnakeCase, i as SplitByCase, T as TitleCase, j as TrainCase, U as UpperFirst } from "./packem_shared/types.d-CMNqA5bi.js";
|
|
21
21
|
export { default as upperFirst } from "./case/upper-first.js";
|
|
22
22
|
export { joinSegments } from "./case/index.js";
|
|
23
23
|
export { type ClosestStringOptions, closestString } from "./closest-string.js";
|
|
@@ -37,7 +37,7 @@ export { type SliceOptions, slice } from "./slice.js";
|
|
|
37
37
|
export { default as slugify } from "./slugify.js";
|
|
38
38
|
export { default as transliterate } from "./transliterate.js";
|
|
39
39
|
export { type TruncateOptions, truncate } from "./truncate.js";
|
|
40
|
-
export type { A as All, a as Any, C as CharAt, b as Charmap, c as Concat, E as EndsWith, I as Includes, d as Interval, e as IntervalArray, f as IsBooleanLiteral, g as IsNumberLiteral, h as IsStringLiteral, i as IsStringLiteralArray, J as Join, L as Length, M as Math, N as NodeLocale, O as OptionReplaceArray, j as OptionReplaceCombined, k as OptionReplaceObject, l as OptionsTransliterate, P as PadEnd, m as PadStart, R as Repeat, n as Replace, o as ReplaceAll, p as Reverse, S as Slice, q as SlugifyOptions, r as Split, s as StartsWith, T as ToLowerCase, t as ToUpperCase, u as Trim, v as TrimEnd, w as TrimStart } from "./packem_shared/types.d-
|
|
40
|
+
export type { A as All, a as Any, C as CharAt, b as Charmap, c as Concat, E as EndsWith, I as Includes, d as Interval, e as IntervalArray, f as IsBooleanLiteral, g as IsNumberLiteral, h as IsStringLiteral, i as IsStringLiteralArray, J as Join, L as Length, M as Math, N as NodeLocale, O as OptionReplaceArray, j as OptionReplaceCombined, k as OptionReplaceObject, l as OptionsTransliterate, P as PadEnd, m as PadStart, R as Repeat, n as Replace, o as ReplaceAll, p as Reverse, S as Slice, q as SlugifyOptions, r as Split, s as StartsWith, T as ToLowerCase, t as ToUpperCase, u as Trim, v as TrimEnd, w as TrimStart } from "./packem_shared/types.d-LgsTR37y.js";
|
|
41
41
|
export { escapeRegExp, findStringOccurrences, hasChinese, hasPunctuationOrSpace, inRange } from "./utilities.js";
|
|
42
42
|
export { type WordSimilaritySortOptions, wordSimilaritySort } from "./word-similarity-sort.js";
|
|
43
43
|
export { type WordWrapOptions, WrapMode, wordWrap } from "./word-wrap.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Check if the given code point is a fullwidth character.
|
|
3
|
-
* @param codePoint The code point to check.
|
|
4
|
-
* @returns Whether the code point is a fullwidth character.
|
|
5
|
-
*/
|
|
2
|
+
* Check if the given code point is a fullwidth character.
|
|
3
|
+
* @param codePoint The code point to check.
|
|
4
|
+
* @returns Whether the code point is a fullwidth character.
|
|
5
|
+
*/
|
|
6
6
|
declare const isFullwidthCodePoint: (codePoint: number) => boolean;
|
|
7
7
|
export { isFullwidthCodePoint as default };
|
package/dist/levenshtein.d.ts
CHANGED
|
@@ -2,24 +2,24 @@ declare const distance: (a: string, b: string) => number;
|
|
|
2
2
|
declare const closest: (str: string, arr: readonly string[]) => string;
|
|
3
3
|
declare const closestN: (string_: string, array: ReadonlyArray<string>, n: number) => (string | undefined)[];
|
|
4
4
|
/**
|
|
5
|
-
* Computes a normalized similarity score between two strings in the range `[0, 1]`,
|
|
6
|
-
* where `1` means the strings are identical and `0` means maximally different.
|
|
7
|
-
*
|
|
8
|
-
* The score is derived from the Levenshtein edit distance, normalized by the
|
|
9
|
-
* length of the longer string: `1 - distance(a, b) / max(a.length, b.length)`.
|
|
10
|
-
* Two empty strings are considered identical (`1`).
|
|
11
|
-
*
|
|
12
|
-
* This is convenient for threshold-based "did you mean?" UX, complementing the
|
|
13
|
-
* raw {@link distance} and the sort-based helpers.
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* similarity("kitten", "sitting"); // => ~0.571
|
|
17
|
-
* similarity("foo", "foo"); // => 1
|
|
18
|
-
* similarity("", ""); // => 1
|
|
19
|
-
* ```
|
|
20
|
-
* @param a The first string.
|
|
21
|
-
* @param b The second string.
|
|
22
|
-
* @returns A similarity score between 0 and 1 (inclusive).
|
|
23
|
-
*/
|
|
5
|
+
* Computes a normalized similarity score between two strings in the range `[0, 1]`,
|
|
6
|
+
* where `1` means the strings are identical and `0` means maximally different.
|
|
7
|
+
*
|
|
8
|
+
* The score is derived from the Levenshtein edit distance, normalized by the
|
|
9
|
+
* length of the longer string: `1 - distance(a, b) / max(a.length, b.length)`.
|
|
10
|
+
* Two empty strings are considered identical (`1`).
|
|
11
|
+
*
|
|
12
|
+
* This is convenient for threshold-based "did you mean?" UX, complementing the
|
|
13
|
+
* raw {@link distance} and the sort-based helpers.
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* similarity("kitten", "sitting"); // => ~0.571
|
|
17
|
+
* similarity("foo", "foo"); // => 1
|
|
18
|
+
* similarity("", ""); // => 1
|
|
19
|
+
* ```
|
|
20
|
+
* @param a The first string.
|
|
21
|
+
* @param b The second string.
|
|
22
|
+
* @returns A similarity score between 0 and 1 (inclusive).
|
|
23
|
+
*/
|
|
24
24
|
declare const similarity: (a: string, b: string) => number;
|
|
25
25
|
export { closest, closestN, distance, similarity };
|