@visulima/string 3.0.0-alpha.11 → 3.0.0-alpha.12

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.
Files changed (114) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/LICENSE.md +68 -3
  3. package/dist/align-text.d.ts +35 -0
  4. package/dist/align-text.js +2 -34
  5. package/dist/case/camel-case.d.ts +17 -2
  6. package/dist/case/camel-case.js +1 -55
  7. package/dist/case/capital-case.d.ts +14 -2
  8. package/dist/case/capital-case.js +1 -47
  9. package/dist/case/constant-case.d.ts +14 -2
  10. package/dist/case/constant-case.js +1 -7
  11. package/dist/case/dot-case.d.ts +14 -2
  12. package/dist/case/dot-case.js +1 -7
  13. package/dist/case/flat-case.d.ts +12 -2
  14. package/dist/case/flat-case.js +1 -7
  15. package/dist/case/flip-case.d.ts +16 -2
  16. package/dist/case/flip-case.js +1 -82
  17. package/dist/case/identify-case.d.ts +15 -2
  18. package/dist/case/identify-case.js +1 -66
  19. package/dist/case/index.d.ts +8 -2
  20. package/dist/case/index.js +1 -20
  21. package/dist/case/kebab-case.d.ts +25 -2
  22. package/dist/case/kebab-case.js +1 -55
  23. package/dist/case/lower-first.d.ts +13 -2
  24. package/dist/case/lower-first.js +1 -9
  25. package/dist/case/no-case.d.ts +14 -2
  26. package/dist/case/no-case.js +1 -7
  27. package/dist/case/pascal-case.d.ts +17 -2
  28. package/dist/case/pascal-case.js +1 -48
  29. package/dist/case/pascal-snake-case.d.ts +14 -2
  30. package/dist/case/pascal-snake-case.js +1 -28
  31. package/dist/case/path-case.d.ts +14 -2
  32. package/dist/case/path-case.js +1 -7
  33. package/dist/case/sentence-case.d.ts +14 -2
  34. package/dist/case/sentence-case.js +1 -54
  35. package/dist/case/snake-case.d.ts +14 -2
  36. package/dist/case/snake-case.js +1 -7
  37. package/dist/case/split-by-case.d.ts +29 -2
  38. package/dist/case/split-by-case.js +1 -763
  39. package/dist/case/title-case.d.ts +12 -2
  40. package/dist/case/title-case.js +1 -40
  41. package/dist/case/train-case.d.ts +14 -2
  42. package/dist/case/train-case.js +1 -40
  43. package/dist/case/upper-first.d.ts +13 -2
  44. package/dist/case/upper-first.js +1 -9
  45. package/dist/closest-string.d.ts +32 -0
  46. package/dist/closest-string.js +1 -22
  47. package/dist/compare-similarity.d.ts +38 -1
  48. package/dist/compare-similarity.js +1 -12
  49. package/dist/get-string-truncated-width.d.ts +151 -0
  50. package/dist/get-string-truncated-width.js +1 -332
  51. package/dist/get-string-width.d.ts +58 -0
  52. package/dist/get-string-width.js +1 -5
  53. package/dist/index.d.ts +194 -9
  54. package/dist/index.js +1 -44
  55. package/dist/native-string-types.d.ts +239 -0
  56. package/dist/outdent.d.ts +74 -0
  57. package/dist/outdent.js +1 -109
  58. package/dist/packem_shared/LRUCache-Bjo6gsbC.js +1 -0
  59. package/dist/packem_shared/closest-uarbVSbs.js +1 -0
  60. package/dist/packem_shared/closestN-Vd5oNJy_.js +1 -0
  61. package/dist/packem_shared/constants-DmzZF6_u.js +1 -0
  62. package/dist/packem_shared/countOccurrences-DIHSCdcG.js +1 -0
  63. package/dist/packem_shared/direction-dtczwUOE.js +1 -0
  64. package/dist/packem_shared/eastAsianWidthType-lcBsj7vg.js +1 -0
  65. package/dist/packem_shared/excerpt-DhV2yoHG.js +54 -0
  66. package/dist/packem_shared/generate-cache-key-DPByFaMH.js +1 -0
  67. package/dist/packem_shared/indent-CDlPQmpe.js +1 -0
  68. package/dist/packem_shared/isFullwidthCodePoint-Dmsf2-5L.js +1 -0
  69. package/dist/packem_shared/joinSegments-D27SxoCV.js +1 -0
  70. package/dist/packem_shared/lookup-ChWuUpyb.js +1 -0
  71. package/dist/packem_shared/normalize-german-eszett-AKfdw2MZ.js +1 -0
  72. package/dist/packem_shared/redent-BECVOaZp.js +1 -0
  73. package/dist/packem_shared/replaceString-aq-C7Wor.js +1 -0
  74. package/dist/packem_shared/stripIndent-Dt8hSxVM.js +1 -0
  75. package/dist/packem_shared/transliterate-D1p1yYE7.js +5 -0
  76. package/dist/packem_shared/types.d-FOLSY2Tc.d.ts +392 -0
  77. package/dist/packem_shared/types.d-NJ4vcG-A.d.ts +346 -0
  78. package/dist/slice.d.ts +42 -0
  79. package/dist/slice.js +1 -415
  80. package/dist/slugify.d.ts +10 -1
  81. package/dist/slugify.js +1 -46
  82. package/dist/test/utils.d.ts +17 -0
  83. package/dist/test/utils.js +13 -88
  84. package/dist/test/vitest.d.ts +3 -0
  85. package/dist/test/vitest.js +1 -5
  86. package/dist/truncate.d.ts +43 -0
  87. package/dist/truncate.js +1 -112
  88. package/dist/utilities.d.ts +28 -1
  89. package/dist/utilities.js +1 -52
  90. package/dist/word-similarity-sort.d.ts +34 -0
  91. package/dist/word-similarity-sort.js +1 -22
  92. package/dist/word-wrap.d.ts +44 -0
  93. package/dist/word-wrap.js +8 -639
  94. package/package.json +46 -46
  95. package/dist/packem_shared/LRUCache-3r3SovvR.js +0 -46
  96. package/dist/packem_shared/closest-IHuSvnSn.js +0 -139
  97. package/dist/packem_shared/closestN-DUsjgiXb.js +0 -25
  98. package/dist/packem_shared/constants-BsZS5f0z.js +0 -95
  99. package/dist/packem_shared/countOccurrences-CS9XprQN.js +0 -22
  100. package/dist/packem_shared/direction-C9gfWWTK.js +0 -16
  101. package/dist/packem_shared/eastAsianWidthType-SD3YniiT.js +0 -20
  102. package/dist/packem_shared/excerpt-COsVNttN.js +0 -1502
  103. package/dist/packem_shared/generate-cache-key-DdayDfjV.js +0 -6
  104. package/dist/packem_shared/indent-D3DSCa6s.js +0 -33
  105. package/dist/packem_shared/isFullwidthCodePoint-IFXZxNjq.js +0 -10
  106. package/dist/packem_shared/joinSegments-CvxSgKz0.js +0 -44
  107. package/dist/packem_shared/lookup-BE8lEqy4.js +0 -104
  108. package/dist/packem_shared/normalize-german-eszett-4p3yKEzn.js +0 -8
  109. package/dist/packem_shared/redent-DSb1IJWn.js +0 -8
  110. package/dist/packem_shared/replaceString-Ce8X2ZQ-.js +0 -192
  111. package/dist/packem_shared/stripIndent-D_TRjxZ_.js +0 -20
  112. package/dist/packem_shared/transliterate-CKt9VK7D.js +0 -47756
  113. package/dist/packem_shared/types.d-BVNv675q.d.ts +0 -61
  114. package/dist/packem_shared/types.d-DfgbcNKh.d.ts +0 -57
@@ -1,332 +1 @@
1
- import { eastAsianWidthType } from './packem_shared/eastAsianWidthType-SD3YniiT.js';
2
- import { g as RE_ANSI, h as RE_CONTROL, i as RE_EMOJI } from './packem_shared/constants-BsZS5f0z.js';
3
-
4
- const charWidthCache = /* @__PURE__ */ new Map();
5
- const RE_LATIN_CHARS = /(?:[\u0020-\u007E\u00A0-\u00FF](?!\uFE0F)){1,1000}/y;
6
- const getCharType = (codePoint) => {
7
- if (codePoint >= 32 && codePoint <= 126) {
8
- return "latin";
9
- }
10
- if (codePoint === 8203 || codePoint === 8204 || codePoint === 8205 || codePoint === 8288) {
11
- return "zero";
12
- }
13
- if (codePoint <= 31 || codePoint >= 127 && codePoint <= 159) {
14
- return "control";
15
- }
16
- if (codePoint >= 160 && codePoint <= 255) {
17
- return "latin";
18
- }
19
- if (codePoint >= 9472 && codePoint <= 9599) {
20
- return "latin";
21
- }
22
- if (codePoint >= 4352 && codePoint <= 4607 || codePoint >= 11904 && codePoint <= 40959 || codePoint >= 44032 && codePoint <= 55215 || codePoint >= 63744 && codePoint <= 64255 || codePoint >= 65280 && codePoint <= 65519 && !(codePoint >= 65377 && codePoint <= 65439) || codePoint >= 12352 && codePoint <= 12543) {
23
- return "wide";
24
- }
25
- if (codePoint === 8230) {
26
- return "latin";
27
- }
28
- return "other";
29
- };
30
- const getCachedCharWidth = (codePoint, config) => {
31
- const highBits = Math.floor(codePoint / 65536);
32
- const lowBits = codePoint % 65536;
33
- let lowMap = charWidthCache.get(highBits);
34
- if (!lowMap) {
35
- lowMap = /* @__PURE__ */ new Map();
36
- charWidthCache.set(highBits, lowMap);
37
- }
38
- if (lowMap.has(lowBits)) {
39
- return lowMap.get(lowBits);
40
- }
41
- let width;
42
- if (getCharType(codePoint) === "latin") {
43
- width = config.width.regular;
44
- } else if (getCharType(codePoint) === "control") {
45
- width = config.width.control;
46
- } else if (getCharType(codePoint) === "wide") {
47
- width = config.width.wide;
48
- } else {
49
- const eaw = eastAsianWidthType(codePoint);
50
- switch (eaw) {
51
- case "ambiguous": {
52
- width = config.width.ambiguousIsNarrow ? config.width.regular : config.width.wide;
53
- break;
54
- }
55
- case "fullwidth": {
56
- width = config.width.fullWidth;
57
- break;
58
- }
59
- case "wide": {
60
- width = config.width.wide;
61
- break;
62
- }
63
- default: {
64
- width = config.width.regular;
65
- }
66
- }
67
- }
68
- lowMap.set(lowBits, width);
69
- return width;
70
- };
71
- const isCombiningCharacter = (codePoint) => {
72
- if (codePoint >= 768 && codePoint <= 879 || codePoint >= 6832 && codePoint <= 6911 || codePoint >= 7616 && codePoint <= 7679 || codePoint >= 8400 && codePoint <= 8447 || codePoint >= 65056 && codePoint <= 65071) {
73
- return true;
74
- }
75
- if (codePoint >= 917760 && codePoint <= 917999 || codePoint >= 65024 && codePoint <= 65039) {
76
- return true;
77
- }
78
- if (codePoint >= 3633 && codePoint <= 3642 || codePoint >= 3655 && codePoint <= 3662 || codePoint >= 3761 && codePoint <= 3769 || codePoint >= 3771 && codePoint <= 3772 || codePoint >= 3784 && codePoint <= 3789) {
79
- return true;
80
- }
81
- if (codePoint >= 2304 && codePoint <= 2307 || codePoint >= 2362 && codePoint <= 2383 || codePoint >= 2385 && codePoint <= 2391 || codePoint >= 2402 && codePoint <= 2403 || codePoint >= 2433 && codePoint <= 2435 || codePoint >= 2492 && codePoint <= 2500 || codePoint >= 2509 && codePoint <= 2509 || codePoint >= 2561 && codePoint <= 2563 || codePoint >= 2620 && codePoint <= 2637) {
82
- return true;
83
- }
84
- if (codePoint >= 1611 && codePoint <= 1631 || codePoint >= 1648 && codePoint <= 1648 || codePoint >= 1750 && codePoint <= 1773 || codePoint >= 2276 && codePoint <= 2302) {
85
- return true;
86
- }
87
- if (codePoint >= 1425 && codePoint <= 1469 || codePoint >= 1471 && codePoint <= 1471 || codePoint >= 1473 && codePoint <= 1474 || codePoint >= 1476 && codePoint <= 1477 || codePoint >= 1479 && codePoint <= 1479) {
88
- return true;
89
- }
90
- if (codePoint >= 3893 && codePoint <= 3893 || codePoint >= 3895 && codePoint <= 3895 || codePoint >= 3897 && codePoint <= 3897 || codePoint >= 3953 && codePoint <= 3966 || codePoint >= 3968 && codePoint <= 3972 || codePoint >= 3974 && codePoint <= 3975) {
91
- return true;
92
- }
93
- return codePoint >= 768 && codePoint <= 777 || codePoint >= 803 && codePoint <= 803;
94
- };
95
- const getStringTruncatedWidth = (input, options = {}) => {
96
- if (!input || input.length === 0) {
97
- return { ellipsed: false, index: 0, truncated: false, width: 0 };
98
- }
99
- const config = {
100
- truncation: {
101
- countAnsiEscapeCodes: options.countAnsiEscapeCodes ?? false,
102
- ellipsis: options.ellipsis ?? "",
103
- ellipsisWidth: options.ellipsisWidth ?? (options.ellipsis ? getStringTruncatedWidth(options.ellipsis, {
104
- ...options,
105
- ellipsis: "",
106
- ellipsisWidth: 0,
107
- limit: Number.POSITIVE_INFINITY
108
- }).width : 0),
109
- limit: options.limit ?? Number.POSITIVE_INFINITY
110
- },
111
- width: {
112
- ambiguousIsNarrow: options.ambiguousIsNarrow ?? false,
113
- ansi: options.ansiWidth ?? 0,
114
- control: options.controlWidth ?? 0,
115
- emoji: options.emojiWidth ?? 2,
116
- fullWidth: options.fullWidth ?? 2,
117
- halfWidth: options.halfWidth ?? 1,
118
- regular: options.regularWidth ?? 1,
119
- tab: options.tabWidth ?? 8,
120
- wide: options.wideWidth ?? 2
121
- }
122
- };
123
- const truncationLimit = Math.max(0, config.truncation.limit - config.truncation.ellipsisWidth);
124
- const { length } = input;
125
- const useCaching = length > 1e4;
126
- let index = 0;
127
- let width = 0;
128
- let truncationIndex = length;
129
- let truncationEnabled = false;
130
- const hasAnsi = input.includes("\x1B") || input.includes("›");
131
- while (index < length) {
132
- if (hasAnsi && (input[index] === "\x1B" || input[index] === "›")) {
133
- if (input.startsWith("\x1B]8;;", index)) {
134
- const BELL = "\x07";
135
- const OSC8_CLOSER = `\x1B]8;;${BELL}`;
136
- const OSC8_CLOSER_LEN = OSC8_CLOSER.length;
137
- const endOfParametersIndex = input.indexOf(BELL, index + 5);
138
- if (endOfParametersIndex === -1) ; else {
139
- const startOfCloserIndex = input.indexOf(OSC8_CLOSER, endOfParametersIndex + 1);
140
- if (startOfCloserIndex === -1) ; else {
141
- const endOfSequenceIndex = startOfCloserIndex + OSC8_CLOSER_LEN;
142
- const linkText = input.slice(endOfParametersIndex + 1, startOfCloserIndex);
143
- const strippedLinkText = linkText.replace(RE_ANSI, "");
144
- const linkTextWidthResult = getStringTruncatedWidth(strippedLinkText, {
145
- ambiguousIsNarrow: config.width.ambiguousIsNarrow,
146
- ansiWidth: config.width.ansi,
147
- controlWidth: config.width.control,
148
- countAnsiEscapeCodes: false,
149
- // Never count ANSI in link text width
150
- ellipsis: config.truncation.ellipsis,
151
- ellipsisWidth: config.truncation.ellipsisWidth,
152
- emojiWidth: config.width.emoji,
153
- fullWidth: config.width.fullWidth,
154
- halfWidth: config.width.halfWidth,
155
- limit: Math.max(0, truncationLimit - width),
156
- regularWidth: config.width.regular,
157
- tabWidth: config.width.tab,
158
- wideWidth: config.width.wide
159
- });
160
- const textWidth = linkTextWidthResult.width;
161
- if (linkTextWidthResult.truncated) {
162
- truncationEnabled = true;
163
- truncationIndex = Math.min(truncationIndex, index);
164
- } else if (width + textWidth > truncationLimit) {
165
- truncationIndex = Math.min(truncationIndex, index);
166
- truncationEnabled = true;
167
- if (width + textWidth > config.truncation.limit) {
168
- break;
169
- }
170
- }
171
- width += textWidth;
172
- index = endOfSequenceIndex;
173
- if (truncationEnabled && width >= config.truncation.limit) {
174
- break;
175
- }
176
- continue;
177
- }
178
- }
179
- }
180
- RE_ANSI.lastIndex = index;
181
- if (RE_ANSI.test(input)) {
182
- const ansiLength = RE_ANSI.lastIndex - index;
183
- const ansiWidth = config.truncation.countAnsiEscapeCodes ? ansiLength : config.width.ansi;
184
- if (width + ansiWidth > truncationLimit) {
185
- truncationIndex = Math.min(truncationIndex, index);
186
- if (width + ansiWidth > config.truncation.limit) {
187
- truncationEnabled = true;
188
- break;
189
- }
190
- }
191
- width += ansiWidth;
192
- index = RE_ANSI.lastIndex;
193
- continue;
194
- }
195
- }
196
- const charCode = input.codePointAt(index);
197
- if (charCode === 8203 || charCode === 65279 || charCode >= 8288 && charCode <= 8292) {
198
- index += 1;
199
- continue;
200
- }
201
- if (charCode === 9) {
202
- if (width + config.width.tab > truncationLimit) {
203
- truncationIndex = Math.min(truncationIndex, index);
204
- if (width + config.width.tab > config.truncation.limit) {
205
- truncationEnabled = true;
206
- break;
207
- }
208
- }
209
- width += config.width.tab;
210
- index += 1;
211
- continue;
212
- }
213
- RE_LATIN_CHARS.lastIndex = index;
214
- if (RE_LATIN_CHARS.test(input)) {
215
- const latinLength = RE_LATIN_CHARS.lastIndex - index;
216
- const latinWidth = latinLength * config.width.regular;
217
- if (width + latinWidth > truncationLimit) {
218
- const charsToLimit = Math.floor((truncationLimit - width) / config.width.regular);
219
- truncationIndex = Math.min(truncationIndex, index + charsToLimit);
220
- if (width + latinWidth > config.truncation.limit) {
221
- truncationEnabled = true;
222
- break;
223
- }
224
- }
225
- width += latinWidth;
226
- index = RE_LATIN_CHARS.lastIndex;
227
- continue;
228
- }
229
- if (charCode <= 31 || charCode >= 127 && charCode <= 159) {
230
- RE_CONTROL.lastIndex = index;
231
- if (RE_CONTROL.test(input)) {
232
- const controlLength = RE_CONTROL.lastIndex - index;
233
- const controlWidth = controlLength * config.width.control;
234
- if (width + controlWidth > truncationLimit) {
235
- truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / config.width.control));
236
- if (width + controlWidth > config.truncation.limit) {
237
- truncationEnabled = true;
238
- break;
239
- }
240
- }
241
- width += controlWidth;
242
- index = RE_CONTROL.lastIndex;
243
- continue;
244
- }
245
- }
246
- RE_EMOJI.lastIndex = index;
247
- if (RE_EMOJI.test(input)) {
248
- if (width + config.width.emoji > truncationLimit) {
249
- truncationIndex = Math.min(truncationIndex, index);
250
- if (width + config.width.emoji > config.truncation.limit) {
251
- truncationEnabled = true;
252
- break;
253
- }
254
- }
255
- width += config.width.emoji;
256
- index = RE_EMOJI.lastIndex;
257
- continue;
258
- }
259
- const codePoint = input.codePointAt(index) ?? 0;
260
- if (isCombiningCharacter(codePoint)) {
261
- index += codePoint > 65535 ? 2 : 1;
262
- continue;
263
- }
264
- let charWidth;
265
- if (useCaching) {
266
- charWidth = getCachedCharWidth(codePoint, config);
267
- } else {
268
- const charType = getCharType(codePoint);
269
- switch (charType) {
270
- case "control": {
271
- charWidth = config.width.control;
272
- break;
273
- }
274
- case "latin": {
275
- charWidth = config.width.regular;
276
- break;
277
- }
278
- case "wide": {
279
- charWidth = config.width.wide;
280
- break;
281
- }
282
- case "zero": {
283
- charWidth = 0;
284
- break;
285
- }
286
- default: {
287
- const eaw = eastAsianWidthType(codePoint);
288
- switch (eaw) {
289
- case "ambiguous": {
290
- charWidth = config.width.ambiguousIsNarrow ? config.width.regular : config.width.wide;
291
- break;
292
- }
293
- case "fullwidth": {
294
- charWidth = config.width.fullWidth;
295
- break;
296
- }
297
- case "wide": {
298
- charWidth = config.width.wide;
299
- break;
300
- }
301
- default: {
302
- charWidth = config.width.regular;
303
- }
304
- }
305
- }
306
- }
307
- }
308
- if (width + charWidth > truncationLimit) {
309
- truncationIndex = Math.min(truncationIndex, index);
310
- if (width + charWidth > config.truncation.limit) {
311
- truncationEnabled = true;
312
- break;
313
- }
314
- }
315
- width += charWidth;
316
- index += codePoint > 65535 ? 2 : 1;
317
- }
318
- let finalWidth = width;
319
- let ellipsed = false;
320
- if (truncationEnabled && config.truncation.limit >= config.truncation.ellipsisWidth) {
321
- finalWidth = config.truncation.limit;
322
- ellipsed = true;
323
- }
324
- return {
325
- ellipsed,
326
- index: truncationEnabled ? truncationIndex : length,
327
- truncated: truncationEnabled,
328
- width: finalWidth
329
- };
330
- };
331
-
332
- export { getStringTruncatedWidth };
1
+ var y=Object.defineProperty;var A=(i,t)=>y(i,"name",{value:t,configurable:!0});import{eastAsianWidthType as O}from"./packem_shared/eastAsianWidthType-lcBsj7vg.js";import{g as m,h as b,i as M}from"./packem_shared/constants-DmzZF6_u.js";var B=Object.defineProperty,I=A((i,t)=>B(i,"name",{value:t,configurable:!0}),"d");const T=new Map,g=/(?:[\u0020-\u007E\u00A0-\u00FF](?!\uFE0F)){1,1000}/y,W=I(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","getCharType"),P=I((i,t)=>{const e=Math.floor(i/65536),r=i%65536;let h=T.get(e);if(h||(h=new Map,T.set(e,h)),h.has(r))return h.get(r);let u;if(W(i)==="latin")u=t.width.regular;else if(W(i)==="control")u=t.width.control;else if(W(i)==="wide")u=t.width.wide;else switch(O(i)){case"ambiguous":{u=t.width.ambiguousIsNarrow?t.width.regular:t.width.wide;break}case"fullwidth":{u=t.width.fullWidth;break}case"wide":{u=t.width.wide;break}default:u=t.width.regular}return h.set(r,u),u},"getCachedCharWidth"),R=I(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,"isCombiningCharacter"),j=I((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?j(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}},r=Math.max(0,e.truncation.limit-e.truncation.ellipsisWidth),{length:h}=i,u=h>1e4;let a=0,n=0,l=h,s=!1;const F=i.includes("\x1B")||i.includes("›");for(;a<h;){if(F&&(i[a]==="\x1B"||i[a]==="›")){if(i.startsWith("\x1B]8;;",a)){const o="\x1B]8;;\x07",w=o.length,p=i.indexOf("\x07",a+5);if(p!==-1){const x=i.indexOf(o,p+1);if(x!==-1){const S=x+w,_=i.slice(p+1,x).replace(m,""),C=j(_,{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,r-n),regularWidth:e.width.regular,tabWidth:e.width.tab,wideWidth:e.width.wide}),k=C.width;if(C.truncated)s=!0,l=Math.min(l,a);else if(n+k>r&&(l=Math.min(l,a),s=!0,n+k>e.truncation.limit))break;if(n+=k,a=S,s&&n>=e.truncation.limit)break;continue}}}if(m.lastIndex=a,m.test(i)){const o=m.lastIndex-a,w=e.truncation.countAnsiEscapeCodes?o:e.width.ansi;if(n+w>r&&(l=Math.min(l,a),n+w>e.truncation.limit)){s=!0;break}n+=w,a=m.lastIndex;continue}}const c=i.codePointAt(a);if(c===8203||c===65279||c>=8288&&c<=8292){a+=1;continue}if(c===9){if(n+e.width.tab>r&&(l=Math.min(l,a),n+e.width.tab>e.truncation.limit)){s=!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>r){const w=Math.floor((r-n)/e.width.regular);if(l=Math.min(l,a+w),n+o>e.truncation.limit){s=!0;break}}n+=o,a=g.lastIndex;continue}if((c<=31||c>=127&&c<=159)&&(b.lastIndex=a,b.test(i))){const o=(b.lastIndex-a)*e.width.control;if(n+o>r&&(l=Math.min(l,a+Math.floor((r-n)/e.width.control)),n+o>e.truncation.limit)){s=!0;break}n+=o,a=b.lastIndex;continue}if(M.lastIndex=a,M.test(i)){if(n+e.width.emoji>r&&(l=Math.min(l,a),n+e.width.emoji>e.truncation.limit)){s=!0;break}n+=e.width.emoji,a=M.lastIndex;continue}const f=i.codePointAt(a)??0;if(R(f)){a+=f>65535?2:1;continue}let d;if(u)d=P(f,e);else switch(W(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(O(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>r&&(l=Math.min(l,a),n+d>e.truncation.limit)){s=!0;break}n+=d,a+=f>65535?2:1}let N=n,E=!1;return s&&e.truncation.limit>=e.truncation.ellipsisWidth&&(N=e.truncation.limit,E=!0),{ellipsed:E,index:s?l:h,truncated:s,width:N}},"getStringTruncatedWidth");export{j as getStringTruncatedWidth};
@@ -1,4 +1,62 @@
1
1
  import { StringTruncatedWidthOptions } from "./get-string-truncated-width.js";
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
+ */
2
25
  type StringWidthOptions = Omit<StringTruncatedWidthOptions, "ellipsis" | "ellipsisWidth" | "limit">;
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
+ */
3
61
  declare const getStringWidth: (input: string, options?: StringWidthOptions) => number;
4
62
  export { StringWidthOptions, getStringWidth };
@@ -1,5 +1 @@
1
- import { getStringTruncatedWidth } from './get-string-truncated-width.js';
2
-
3
- const getStringWidth = (input, options = {}) => getStringTruncatedWidth(input, { ...options, ellipsis: "", ellipsisWidth: 0, limit: Number.POSITIVE_INFINITY }).width;
4
-
5
- export { getStringWidth };
1
+ var r=Object.defineProperty;var e=(t,i)=>r(t,"name",{value:i,configurable:!0});import{getStringTruncatedWidth as n}from"./get-string-truncated-width.js";var d=Object.defineProperty,g=e((t,i)=>d(t,"name",{value:i,configurable:!0}),"r");const o=g((t,i={})=>n(t,{...i,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width,"getStringWidth");export{o as getStringWidth};
package/dist/index.d.ts CHANGED
@@ -17,35 +17,220 @@ 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 a as CamelCase, type b as CapitalCase, type C as CaseOptions, type c as ConstantCase, type D as DotCase, type F as FlatCase, type d as FlipCase, type I as IdentifyCase, type K as KebabCase, type L as LocaleOptions, type e as LowerFirst, type N as NoCase, type P as PascalCase, type f as PascalSnakeCase, type g as PathCase, type S as SentenceCase, type h as SnakeCase, type i as SplitByCase, type T as TitleCase, type j as TrainCase, type U as UpperFirst } from "./packem_shared/types.d-DfgbcNKh.js";
20
+ export { type a as CamelCase, type b as CapitalCase, type C as CaseOptions, type c as ConstantCase, type D as DotCase, type F as FlatCase, type d as FlipCase, type I as IdentifyCase, type K as KebabCase, type L as LocaleOptions, type e as LowerFirst, type N as NoCase, type P as PascalCase, type f as PascalSnakeCase, type g as PathCase, type S as SentenceCase, type h as SnakeCase, type i as SplitByCase, type T as TitleCase, type j as TrainCase, type U as UpperFirst } from "./packem_shared/types.d-FOLSY2Tc.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";
24
24
  export { type CompareSimilarityOptions, compareSimilarity } from "./compare-similarity.js";
25
- export { type Options as EastAsianWidthOptions, type WidthType as EastAsianWidthType, eastAsianWidth, eastAsianWidthType } from 'get-east-asian-width';
26
25
  import { TruncateOptions } from "./truncate.js";
27
26
  export { truncate } from "./truncate.js";
28
27
  export { type StringTruncatedWidthOptions, type StringTruncatedWidthResult, getStringTruncatedWidth } from "./get-string-truncated-width.js";
29
28
  export { type StringWidthOptions, getStringWidth } from "./get-string-width.js";
30
- export { type Options as IndentOptions, default as indent } from 'indent-string';
31
- export { default as redent } from 'redent';
32
- export { dedent, default as stripIndent } from 'strip-indent';
33
29
  export { type Outdent, type Options as OutdentOptions, outdent } from "./outdent.js";
34
- import { O as OptionReplaceArray, a as IntervalArray, b as OptionsTransliterate } from "./packem_shared/types.d-BVNv675q.js";
35
- export { type A as All, type c as Any, type C as CharAt, type d as Charmap, type e as Concat, type E as EndsWith, type f as Includes, type g as Interval, type h as IsBooleanLiteral, type i as IsNumberLiteral, type I as IsStringLiteral, type j as IsStringLiteralArray, type J as Join, type L as Length, type M as Math, type N as NodeLocale, type k as OptionReplaceCombined, type l as OptionReplaceObject, type P as PadEnd, type m as PadStart, type R as Repeat, type n as Replace, type o as ReplaceAll, type p as Reverse, type q as Slice, type S as SlugifyOptions, type r as Split, type s as StartsWith, type T as ToLowerCase, type t as ToUpperCase, type u as Trim, type v as TrimEnd, type w as TrimStart } from "./packem_shared/types.d-BVNv675q.js";
30
+ import { O as OptionReplaceArray, a as IntervalArray, b as OptionsTransliterate } from "./packem_shared/types.d-NJ4vcG-A.js";
31
+ export { type A as All, type c as Any, type C as CharAt, type d as Charmap, type e as Concat, type E as EndsWith, type f as Includes, type g as Interval, type h as IsBooleanLiteral, type i as IsNumberLiteral, type I as IsStringLiteral, type j as IsStringLiteralArray, type J as Join, type L as Length, type M as Math, type N as NodeLocale, type k as OptionReplaceCombined, type l as OptionReplaceObject, type P as PadEnd, type m as PadStart, type R as Repeat, type n as Replace, type o as ReplaceAll, type p as Reverse, type q as Slice, type S as SlugifyOptions, type r as Split, type s as StartsWith, type T as ToLowerCase, type t as ToUpperCase, type u as Trim, type v as TrimEnd, type w as TrimStart } from "./packem_shared/types.d-NJ4vcG-A.js";
36
32
  export { type SliceOptions, slice } from "./slice.js";
37
33
  export { default as slugify } from "./slugify.js";
38
34
  export { escapeRegExp, findStringOccurrences, hasChinese, hasPunctuationOrSpace, inRange } from "./utilities.js";
39
35
  export { type WordSimilaritySortOptions, wordSimilaritySort } from "./word-similarity-sort.js";
40
36
  export { type WordWrapOptions, WrapMode, wordWrap } from "./word-wrap.js";
41
- export { closest, distance } from 'fastest-levenshtein';
42
37
  import "./packem_shared/lru-cache.d-BsP6kbVJ.js";
38
+ /**
39
+ * Get the count of `substring` in `value`.
40
+ * @param value Content to search in. Will be coerced to string.
41
+ * @param substring Substring to look for, typically one character.
42
+ * @returns Count of `substring`s in `value`.
43
+ * @throws {TypeError} When substring is not a string or is empty.
44
+ */
43
45
  declare const countOccurrences: (value: unknown, substring: string) => number;
46
+ /**
47
+ * Detect the direction of text: left-to-right, right-to-left, or neutral.
48
+ * @param value The string to analyze.
49
+ * @returns The text direction: 'rtl' for right-to-left, 'ltr' for left-to-right, or 'neutral' for neutral.
50
+ */
44
51
  declare const direction: (value?: string) => "rtl" | "ltr" | "neutral";
52
+ type WidthType = 'fullwidth' | 'halfwidth' | 'wide' | 'narrow' | 'neutral' | 'ambiguous';
53
+ type Options$1 = {
54
+ /**
55
+ Whether to treat an `'ambiguous'` character as wide.
56
+ @default true
57
+ @example
58
+ ```
59
+ import {eastAsianWidth} from 'get-east-asian-width';
60
+ const codePoint = '⛣'.codePointAt(0);
61
+ console.log(eastAsianWidth(codePoint));
62
+ //=> 1
63
+ console.log(eastAsianWidth(codePoint, {ambiguousAsWide: true}));
64
+ //=> 2
65
+ ```
66
+ > Ambiguous characters behave like wide or narrow characters depending on the context (language tag, script identification, associated font, source of data, or explicit markup; all can provide the context). __If the context cannot be established reliably, they should be treated as narrow characters by default.__
67
+ > - http://www.unicode.org/reports/tr11/
68
+ */
69
+ readonly ambiguousAsWide?: boolean;
70
+ };
71
+ /**
72
+ Returns the width as a number for the given code point.
73
+
74
+ @param codePoint - A Unicode code point.
75
+
76
+ @example
77
+ ```
78
+ import {eastAsianWidth} from 'get-east-asian-width';
79
+
80
+ const codePoint = '字'.codePointAt(0);
81
+
82
+ console.log(eastAsianWidth(codePoint));
83
+ //=> 2
84
+ ```
85
+ */
86
+ declare function eastAsianWidth(codePoint: number, options?: Options$1): 1 | 2;
87
+ /**
88
+ Returns the type of “East Asian Width” for the given code point.
89
+
90
+ @param codePoint - A Unicode code point.
91
+
92
+ @example
93
+ ```
94
+ import {eastAsianWidthType} from 'get-east-asian-width';
95
+
96
+ const codePoint = '字'.codePointAt(0);
97
+
98
+ console.log(eastAsianWidthType(codePoint));
99
+ //=> 'wide'
100
+ ```
101
+ */
102
+ declare function eastAsianWidthType(codePoint: number): WidthType;
103
+ /**
104
+ * Truncates a sentence to be under the given character limit and strips HTML tags from it.
105
+ * This function first removes all HTML tags and decodes HTML entities, then truncates
106
+ * the resulting plain text to the specified character limit using the truncate function.
107
+ * @example
108
+ * ```typescript
109
+ * excerpt('<p>Hello <strong>world</strong>!</p>', 10);
110
+ * // => 'Hello worl…'
111
+ *
112
+ * excerpt('<div>This is a <em>long</em> text</div>', 20, { ellipsis: '...' });
113
+ * // => 'This is a long text'
114
+ * ```
115
+ * @param html The HTML string to truncate
116
+ * @param limit Maximum character limit for the truncated string
117
+ * @param options Configuration options for truncation
118
+ * @returns The truncated plain text string with HTML tags removed
119
+ */
45
120
  declare const excerpt: (html: string, limit: number, options?: ExcerptOptions) => string;
121
+ /**
122
+ * Options for the excerpt function
123
+ */
46
124
  type ExcerptOptions = Omit<TruncateOptions, "position">;
125
+ interface Options {
126
+ /**
127
+ The string to use for the indent.
128
+ @default ' '
129
+ */
130
+ readonly indent?: string;
131
+
132
+ /**
133
+ Also indent empty lines.
134
+ @default false
135
+ */
136
+ readonly includeEmptyLines?: boolean;
137
+ }
138
+ /**
139
+ Indent each line in a string.
140
+
141
+ @param string - The string to indent.
142
+ @param count - How many times you want `options.indent` repeated. Default: `1`.
143
+
144
+ @example
145
+ ```
146
+ import indentString from 'indent-string';
147
+
148
+ indentString('Unicorns\nRainbows', 4);
149
+ //=> ' Unicorns\n Rainbows'
150
+
151
+ indentString('Unicorns\nRainbows', 4, {indent: '♥'});
152
+ //=> '♥♥♥♥Unicorns\n♥♥♥♥Rainbows'
153
+ ```
154
+ */
155
+ declare function indentString(string: string, count?: number, options?: Options): string;
156
+ /**
157
+ [Strip redundant indentation](https://github.com/sindresorhus/strip-indent) and [indent the string](https://github.com/sindresorhus/indent-string).
158
+
159
+ @param string - The string to normalize indentation.
160
+ @param count - How many times you want `options.indent` repeated. Default: `0`.
161
+
162
+ @example
163
+ ```
164
+ import redent from 'redent';
165
+
166
+ redent('\n foo\n bar\n', 1);
167
+ //=> '\n foo\n bar\n'
168
+ ```
169
+ */
170
+ declare function redent(string: string, count?: number, options?: Options): string;
171
+ /**
172
+ Strip leading whitespace from each line in a string.
173
+
174
+ The line with the least number of leading whitespace, ignoring empty lines, determines the number to remove.
175
+
176
+ @example
177
+ ```
178
+ import stripIndent from 'strip-indent';
179
+
180
+ const string = '\tunicorn\n\t\tcake';
181
+ // unicorn
182
+ // cake
183
+
184
+ stripIndent(string);
185
+ //unicorn
186
+ // cake
187
+ ```
188
+ */
189
+ declare function stripIndent(string: string): string;
190
+ /**
191
+ Strip leading whitespace from each line in a string and remove surrounding blank lines.
192
+
193
+ The line with the least number of leading whitespace, ignoring empty lines, determines the number to remove.
194
+ Leading and trailing lines that contain only whitespace are removed.
195
+
196
+ Useful for template literals and multi-line strings where you want clean boundaries.
197
+
198
+ @example
199
+ ```
200
+ import {dedent} from 'strip-indent';
201
+
202
+ dedent(`
203
+ unicorn
204
+ cake
205
+ `);
206
+ //unicorn
207
+ // cake
208
+ ```
209
+ */
210
+ declare function dedent(string: string): string;
211
+ /**
212
+ * Check if the given code point is a fullwidth character.
213
+ * @param codePoint The code point to check.
214
+ * @returns Whether the code point is a fullwidth character.
215
+ */
47
216
  declare const isFullwidthCodePoint: (codePoint: number) => boolean;
217
+ declare const distance: (a: string, b: string) => number;
218
+ declare const closest: (str: string, arr: readonly string[]) => string;
48
219
  declare const closestN: (string_: string, array: ReadonlyArray<string>, n: number) => (string | undefined)[];
220
+ /**
221
+ * Performs multiple string or RegExp replacements using a refined pre-processing approach.
222
+ * @param source The string to search and replace in.
223
+ * @param searches An array of search/replace pairs.
224
+ * @param ignoreRanges An array of ignored ranges.
225
+ * @returns The string with replacements applied.
226
+ */
49
227
  declare const replaceString: (source: string, searches: OptionReplaceArray, ignoreRanges: IntervalArray) => string;
228
+ /**
229
+ * Main transliterate function.
230
+ * Replaces characters in a string based on a charmap and options.
231
+ * @param source The string which is being transliterated.
232
+ * @param options Options object.
233
+ * @returns The transliterated string.
234
+ */
50
235
  declare const transliterate: (source: string, options?: OptionsTransliterate) => string;
51
- export { type ExcerptOptions, type IntervalArray, type OptionReplaceArray, type OptionsTransliterate, type TruncateOptions, closestN, countOccurrences, direction, excerpt, isFullwidthCodePoint, replaceString, transliterate };
236
+ export { type Options$1 as EastAsianWidthOptions, type WidthType as EastAsianWidthType, type ExcerptOptions, type Options as IndentOptions, type IntervalArray, type OptionReplaceArray, type OptionsTransliterate, type TruncateOptions, closest, closestN, countOccurrences, dedent, direction, distance, eastAsianWidth, eastAsianWidthType, excerpt, indentString as indent, isFullwidthCodePoint, redent, replaceString, stripIndent, transliterate };