@visulima/string 1.2.3 → 1.4.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.
Files changed (102) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +46 -0
  3. package/dist/case/camel-case.cjs +1 -59
  4. package/dist/case/camel-case.mjs +1 -57
  5. package/dist/case/capital-case.cjs +1 -51
  6. package/dist/case/capital-case.mjs +1 -49
  7. package/dist/case/constant-case.cjs +1 -11
  8. package/dist/case/constant-case.mjs +1 -9
  9. package/dist/case/dot-case.cjs +1 -11
  10. package/dist/case/dot-case.mjs +1 -9
  11. package/dist/case/flat-case.cjs +1 -11
  12. package/dist/case/flat-case.mjs +1 -9
  13. package/dist/case/flip-case.cjs +1 -61
  14. package/dist/case/flip-case.mjs +1 -57
  15. package/dist/case/identify-case.cjs +1 -69
  16. package/dist/case/identify-case.mjs +1 -67
  17. package/dist/case/index.cjs +1 -47
  18. package/dist/case/index.mjs +1 -20
  19. package/dist/case/kebab-case.cjs +1 -61
  20. package/dist/case/kebab-case.mjs +1 -57
  21. package/dist/case/lower-first.cjs +1 -13
  22. package/dist/case/lower-first.mjs +1 -11
  23. package/dist/case/no-case.cjs +1 -11
  24. package/dist/case/no-case.mjs +1 -9
  25. package/dist/case/pascal-case.cjs +1 -52
  26. package/dist/case/pascal-case.mjs +1 -50
  27. package/dist/case/pascal-snake-case.cjs +1 -32
  28. package/dist/case/pascal-snake-case.mjs +1 -30
  29. package/dist/case/path-case.cjs +1 -11
  30. package/dist/case/path-case.mjs +1 -9
  31. package/dist/case/sentence-case.cjs +1 -58
  32. package/dist/case/sentence-case.mjs +1 -56
  33. package/dist/case/snake-case.cjs +1 -11
  34. package/dist/case/snake-case.mjs +1 -9
  35. package/dist/case/split-by-case.cjs +1 -641
  36. package/dist/case/split-by-case.mjs +1 -637
  37. package/dist/case/title-case.cjs +1 -47
  38. package/dist/case/title-case.mjs +1 -45
  39. package/dist/case/train-case.cjs +1 -44
  40. package/dist/case/train-case.mjs +1 -42
  41. package/dist/case/upper-first.cjs +1 -13
  42. package/dist/case/upper-first.mjs +1 -11
  43. package/dist/get-string-truncated-width.cjs +1 -422
  44. package/dist/get-string-truncated-width.mjs +1 -418
  45. package/dist/get-string-width.cjs +1 -11
  46. package/dist/get-string-width.mjs +1 -7
  47. package/dist/index.cjs +1 -66
  48. package/dist/index.d.cts +13 -3
  49. package/dist/index.d.mts +13 -3
  50. package/dist/index.d.ts +13 -3
  51. package/dist/index.mjs +1 -29
  52. package/dist/outdent.cjs +1 -125
  53. package/dist/outdent.mjs +1 -121
  54. package/dist/packem_shared/LRUCache-Bjo6gsbC.mjs +1 -0
  55. package/dist/packem_shared/LRUCache-TYqfUYE5.cjs +1 -0
  56. package/dist/packem_shared/WrapMode-BZ3jkEf1.mjs +8 -0
  57. package/dist/packem_shared/WrapMode-DR7vv3px.cjs +8 -0
  58. package/dist/packem_shared/alignText-BCKbnqhC.mjs +2 -0
  59. package/dist/packem_shared/alignText-CLZJuPP6.cjs +2 -0
  60. package/dist/packem_shared/constants-Cd17VNEv.mjs +1 -0
  61. package/dist/packem_shared/constants-D3K8u3G8.cjs +1 -0
  62. package/dist/packem_shared/generate-cache-key-BZf0GiMs.cjs +1 -0
  63. package/dist/packem_shared/generate-cache-key-DPByFaMH.mjs +1 -0
  64. package/dist/packem_shared/joinSegments-CDHNMXsF.cjs +1 -0
  65. package/dist/packem_shared/joinSegments-H7QJ7rwJ.mjs +1 -0
  66. package/dist/packem_shared/normalize-german-eszett-4k1qRtEP.mjs +1 -0
  67. package/dist/packem_shared/normalize-german-eszett-Bop4wOp9.cjs +1 -0
  68. package/dist/packem_shared/replaceString-Ce8TI_-L.cjs +1 -0
  69. package/dist/packem_shared/replaceString-D7R-5VFX.mjs +1 -0
  70. package/dist/packem_shared/slugify-B1vlQQO1.mjs +1 -0
  71. package/dist/packem_shared/slugify-CH3GI7E5.cjs +1 -0
  72. package/dist/packem_shared/transliterate-BXaP38Sh.mjs +5 -0
  73. package/dist/packem_shared/transliterate-CToQ-aeM.cjs +5 -0
  74. package/dist/slice.cjs +1 -419
  75. package/dist/slice.mjs +1 -415
  76. package/dist/test/utils.cjs +13 -74
  77. package/dist/test/utils.mjs +14 -69
  78. package/dist/test/vitest.cjs +1 -11
  79. package/dist/test/vitest.mjs +1 -7
  80. package/dist/truncate.cjs +1 -101
  81. package/dist/truncate.mjs +1 -97
  82. package/dist/utils.cjs +1 -65
  83. package/dist/utils.mjs +1 -56
  84. package/package.json +8 -1
  85. package/dist/packem_shared/LRUCache-Crb-m7cw.cjs +0 -53
  86. package/dist/packem_shared/LRUCache-udNErhWw.mjs +0 -51
  87. package/dist/packem_shared/WrapMode-BCVbMqYK.mjs +0 -545
  88. package/dist/packem_shared/WrapMode-DebG_Nll.cjs +0 -550
  89. package/dist/packem_shared/constants-6-GJ6zA-.cjs +0 -150
  90. package/dist/packem_shared/constants-CKdlkHVU.mjs +0 -99
  91. package/dist/packem_shared/generate-cache-key-D8f1auDB.cjs +0 -10
  92. package/dist/packem_shared/generate-cache-key-YSju5pj2.mjs +0 -8
  93. package/dist/packem_shared/joinSegments-BfSDBmPF.mjs +0 -46
  94. package/dist/packem_shared/joinSegments-HYXurfoq.cjs +0 -48
  95. package/dist/packem_shared/normalize-german-eszett-DJK0S2qj.cjs +0 -11
  96. package/dist/packem_shared/normalize-german-eszett-fpJ4lZL6.mjs +0 -9
  97. package/dist/packem_shared/replaceString-C7Dp5vAg.mjs +0 -200
  98. package/dist/packem_shared/replaceString-iYo1cDfZ.cjs +0 -202
  99. package/dist/packem_shared/slugify-SKjCL8DF.cjs +0 -50
  100. package/dist/packem_shared/slugify-pbxTlzeQ.mjs +0 -48
  101. package/dist/packem_shared/transliterate-4P32b49d.mjs +0 -47780
  102. package/dist/packem_shared/transliterate-CtOTNpLs.cjs +0 -47782
package/dist/slice.mjs CHANGED
@@ -1,415 +1 @@
1
- import { a as RE_VALID_ANSI_PAIRS, b as RE_VALID_HYPERLINKS, c as RE_ANSI } from './packem_shared/constants-CKdlkHVU.mjs';
2
- import { getStringWidth } from './get-string-width.mjs';
3
- import LRUCache from './packem_shared/LRUCache-udNErhWw.mjs';
4
-
5
- var __defProp = Object.defineProperty;
6
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
- const segmentCache = new LRUCache(100);
8
- const defaultSegmenter = new Intl.Segmenter("en", { granularity: "grapheme" });
9
- const ANSI_RESET_CODES = /* @__PURE__ */ new Set([
10
- "0",
11
- // Full reset
12
- "22",
13
- // Bold reset
14
- "23",
15
- // Italic reset
16
- "24",
17
- // Underline reset
18
- "27",
19
- // Inverse reset
20
- "28",
21
- // Hidden reset
22
- "29",
23
- // Strikethrough reset
24
- "39",
25
- // Foreground color reset
26
- "49"
27
- // Background color reset
28
- ]);
29
- const STYLE_CODES = /* @__PURE__ */ new Set([
30
- "1",
31
- // Bold
32
- "3",
33
- // Italic
34
- "4",
35
- // Underline
36
- "7",
37
- // Inverse
38
- "8",
39
- // Hidden
40
- "9"
41
- // Strikethrough
42
- ]);
43
- const FORMAT_RESET_CODES = /* @__PURE__ */ new Map([
44
- ["22", "1"],
45
- // Bold reset
46
- ["23", "3"],
47
- // Italic reset
48
- ["24", "4"],
49
- // Underline reset
50
- ["27", "7"],
51
- // Inverse reset
52
- ["28", "8"],
53
- // Hidden reset
54
- ["29", "9"]
55
- // Strikethrough reset
56
- ]);
57
- const isForegroundColor = /* @__PURE__ */ __name((code) => code >= "30" && code <= "37" || code >= "90" && code <= "97" || code.startsWith("38;"), "isForegroundColor");
58
- const isBackgroundColor = /* @__PURE__ */ __name((code) => code >= "40" && code <= "47" || code >= "100" && code <= "107" || code.startsWith("48;"), "isBackgroundColor");
59
- const FORMAT_STYLES = [
60
- { close: "\x1B[22m", open: "\x1B[1m" },
61
- // Bold
62
- { close: "\x1B[23m", open: "\x1B[3m" },
63
- // Italic
64
- { close: "\x1B[24m", open: "\x1B[4m" },
65
- // Underline
66
- { close: "\x1B[27m", open: "\x1B[7m" },
67
- // Inverse
68
- { close: "\x1B[28m", open: "\x1B[8m" },
69
- // Hidden
70
- { close: "\x1B[29m", open: "\x1B[9m" }
71
- // Strikethrough
72
- ];
73
- const findFirstPositionOfAny = /* @__PURE__ */ __name((input, substrings) => {
74
- let firstPos = -1;
75
- for (const substring of substrings) {
76
- const pos = input.indexOf(substring);
77
- if (pos >= 0 && (firstPos === -1 || pos < firstPos)) {
78
- firstPos = pos;
79
- }
80
- }
81
- return firstPos;
82
- }, "findFirstPositionOfAny");
83
- const processIntoStyledSegments = /* @__PURE__ */ __name((input, options) => {
84
- if (!input.includes("\x1B")) {
85
- return [
86
- {
87
- after: "",
88
- before: "",
89
- content: input,
90
- visibleLength: getStringWidth(input, options.width)
91
- }
92
- ];
93
- }
94
- const cachedResult = segmentCache.get(input);
95
- if (cachedResult) {
96
- return cachedResult;
97
- }
98
- const parts = [];
99
- const matches = [];
100
- let lastIndex = 0;
101
- let match;
102
- RE_ANSI.lastIndex = 0;
103
- while ((match = RE_ANSI.exec(input)) !== null) {
104
- const matchedText = match[0];
105
- parts.push(input.slice(lastIndex, match.index));
106
- matches.push(matchedText);
107
- lastIndex = match.index + matchedText.length;
108
- }
109
- if (lastIndex < input.length) {
110
- parts.push(input.slice(lastIndex));
111
- }
112
- const closingSequences = [];
113
- for (const ansi of matches) {
114
- if (ansi === "\x1B[0m" || ansi === "\x1B]8;;\x07") {
115
- closingSequences.push(ansi);
116
- continue;
117
- }
118
- if (ansi.startsWith("\x1B[") && ansi.endsWith("m")) {
119
- const code = ansi.slice(2, -1);
120
- if (ANSI_RESET_CODES.has(code)) {
121
- closingSequences.push(ansi);
122
- continue;
123
- }
124
- }
125
- }
126
- const activeStylesSet = /* @__PURE__ */ new Set();
127
- const segments = [];
128
- for (const [index, text] of parts.entries()) {
129
- if (index > 0 && matches[index - 1]) {
130
- const ansi = matches[index - 1];
131
- if (ansi === "\x1B[0m") {
132
- activeStylesSet.clear();
133
- } else if (ansi === "\x1B]8;;\x07") {
134
- for (const style of activeStylesSet) {
135
- if (style.startsWith("\x1B]8;;") && !style.endsWith("\x1B]8;;\x07")) {
136
- activeStylesSet.delete(style);
137
- break;
138
- }
139
- }
140
- } else if (ansi.startsWith("\x1B[") && ansi.endsWith("m")) {
141
- const code = ansi.slice(2, -1);
142
- if (code === "39") {
143
- for (const style of activeStylesSet) {
144
- if (style.startsWith("\x1B[") && style.endsWith("m")) {
145
- const styleCode = style.slice(2, -1);
146
- if (isForegroundColor(styleCode)) {
147
- activeStylesSet.delete(style);
148
- break;
149
- }
150
- }
151
- }
152
- } else if (code === "49") {
153
- for (const style of activeStylesSet) {
154
- if (style.startsWith("\x1B[") && style.endsWith("m")) {
155
- const styleCode = style.slice(2, -1);
156
- if (isBackgroundColor(styleCode)) {
157
- activeStylesSet.delete(style);
158
- break;
159
- }
160
- }
161
- }
162
- } else if (FORMAT_RESET_CODES.has(code)) {
163
- const targetCode = FORMAT_RESET_CODES.get(code);
164
- for (const style of activeStylesSet) {
165
- if (style === `\x1B[${targetCode}m`) {
166
- activeStylesSet.delete(style);
167
- break;
168
- }
169
- }
170
- } else {
171
- if (isForegroundColor(code)) {
172
- for (const style of activeStylesSet) {
173
- if (style.startsWith("\x1B[") && style.endsWith("m")) {
174
- const styleCode = style.slice(2, -1);
175
- if (isForegroundColor(styleCode)) {
176
- activeStylesSet.delete(style);
177
- break;
178
- }
179
- }
180
- }
181
- } else if (isBackgroundColor(code)) {
182
- for (const style of activeStylesSet) {
183
- if (style.startsWith("\x1B[") && style.endsWith("m")) {
184
- const styleCode = style.slice(2, -1);
185
- if (isBackgroundColor(styleCode)) {
186
- activeStylesSet.delete(style);
187
- break;
188
- }
189
- }
190
- }
191
- } else if (STYLE_CODES.has(code)) {
192
- const targetStyle = `\x1B[${code}m`;
193
- if (activeStylesSet.has(targetStyle)) {
194
- activeStylesSet.delete(targetStyle);
195
- }
196
- }
197
- activeStylesSet.add(ansi);
198
- }
199
- } else if (ansi.startsWith("\x1B]8;;") && !ansi.endsWith("\x1B]8;;\x07")) {
200
- for (const style of activeStylesSet) {
201
- if (style.startsWith("\x1B]8;;") && !style.endsWith("\x1B]8;;\x07")) {
202
- activeStylesSet.delete(style);
203
- break;
204
- }
205
- }
206
- activeStylesSet.add(ansi);
207
- }
208
- }
209
- if (text === "") {
210
- continue;
211
- }
212
- let closingSequence = "";
213
- if (activeStylesSet.size > 0) {
214
- if (closingSequences.includes("\x1B[0m")) {
215
- closingSequence = "\x1B[0m";
216
- } else {
217
- const closingParts = [];
218
- let needsHyperlinkClose = false;
219
- for (const style of activeStylesSet) {
220
- if (style.startsWith("\x1B]8;;") && !style.endsWith("\x1B]8;;\x07")) {
221
- needsHyperlinkClose = true;
222
- break;
223
- }
224
- }
225
- if (needsHyperlinkClose && closingSequences.includes("\x1B]8;;\x07")) {
226
- closingParts.push("\x1B]8;;\x07");
227
- }
228
- let needsForegroundClose = false;
229
- let needsBackgroundClose = false;
230
- for (const style of activeStylesSet) {
231
- if (style.startsWith("\x1B[") && style.endsWith("m")) {
232
- const styleCode = style.slice(2, -1);
233
- if (isForegroundColor(styleCode)) {
234
- needsForegroundClose = true;
235
- } else if (isBackgroundColor(styleCode)) {
236
- needsBackgroundClose = true;
237
- }
238
- }
239
- }
240
- if (needsForegroundClose && needsBackgroundClose) {
241
- const fgOpenPos = findFirstPositionOfAny(input, [
242
- "\x1B[3",
243
- // Basic colors 30-37
244
- "\x1B[9",
245
- // Bright colors 90-97
246
- "\x1B[38;"
247
- // RGB/256 colors
248
- ]);
249
- const bgOpenPos = findFirstPositionOfAny(input, [
250
- "\x1B[4",
251
- // Basic colors 40-47
252
- "\x1B[10",
253
- // Bright colors 100-107
254
- "\x1B[48;"
255
- // RGB/256 colors
256
- ]);
257
- if (fgOpenPos >= 0 && bgOpenPos >= 0) {
258
- if (fgOpenPos > bgOpenPos) {
259
- closingParts.push("\x1B[39m", "\x1B[49m");
260
- } else {
261
- closingParts.push("\x1B[49m", "\x1B[39m");
262
- }
263
- } else {
264
- closingParts.push("\x1B[39m", "\x1B[49m");
265
- }
266
- } else {
267
- if (needsForegroundClose) {
268
- closingParts.push("\x1B[39m");
269
- }
270
- if (needsBackgroundClose) {
271
- closingParts.push("\x1B[49m");
272
- }
273
- }
274
- if (needsForegroundClose && needsBackgroundClose && input.includes("\x1B[39m") && input.includes("\x1B[49m")) {
275
- if (input.indexOf("\x1B[39m") < input.indexOf("\x1B[49m")) {
276
- closingParts.length -= needsForegroundClose && needsBackgroundClose ? 2 : needsForegroundClose || needsBackgroundClose ? 1 : 0;
277
- closingParts.push("\x1B[39m", "\x1B[49m");
278
- } else if (input.indexOf("\x1B[49m") < input.indexOf("\x1B[39m")) {
279
- closingParts.length -= needsForegroundClose && needsBackgroundClose ? 2 : needsForegroundClose || needsBackgroundClose ? 1 : 0;
280
- closingParts.push("\x1B[49m", "\x1B[39m");
281
- }
282
- }
283
- const activeFormatStyles = FORMAT_STYLES.filter((style) => activeStylesSet.has(style.open)).map((style) => {
284
- return {
285
- position: input.indexOf(style.open),
286
- style
287
- };
288
- }).filter((item) => item.position >= 0).sort((a, b) => b.position - a.position);
289
- for (const item of activeFormatStyles) {
290
- if (closingSequences.includes(item.style.close)) {
291
- closingParts.push(item.style.close);
292
- }
293
- }
294
- closingSequence = closingParts.join("");
295
- }
296
- }
297
- const activeStylesString = [...activeStylesSet].join("");
298
- segments.push({
299
- after: closingSequence,
300
- before: activeStylesString,
301
- content: text,
302
- visibleLength: getStringWidth(text, {
303
- fullWidth: 1,
304
- wideWidth: 1
305
- })
306
- });
307
- }
308
- segmentCache.set(input, segments);
309
- return segments;
310
- }, "processIntoStyledSegments");
311
- const fastSlice = /* @__PURE__ */ __name((inputString, startIndex, endIndex, options) => {
312
- const graphemes = [...options.segmenter.segment(inputString)];
313
- const result = [];
314
- let currentWidth = 0;
315
- let startFound = false;
316
- for (const grapheme of graphemes) {
317
- const graphemeWidth = getStringWidth(grapheme.segment, options.width);
318
- const positionBefore = currentWidth;
319
- const positionAfter = currentWidth + graphemeWidth;
320
- if (!startFound) {
321
- if (positionBefore < startIndex) {
322
- currentWidth = positionAfter;
323
- continue;
324
- } else {
325
- startFound = true;
326
- }
327
- }
328
- if (positionBefore >= endIndex) {
329
- break;
330
- }
331
- if (positionAfter > endIndex) {
332
- break;
333
- }
334
- result.push(grapheme.segment);
335
- currentWidth = positionAfter;
336
- }
337
- return result.join("");
338
- }, "fastSlice");
339
- const slice = /* @__PURE__ */ __name((inputString, startIndex = 0, endIndex = Number.MAX_SAFE_INTEGER, options = {}) => {
340
- const config = {
341
- segmenter: defaultSegmenter,
342
- ...options
343
- };
344
- if (startIndex >= endIndex || inputString === "") {
345
- return "";
346
- }
347
- const inputStringWidth = getStringWidth(inputString, config.width);
348
- if (startIndex === 0 && endIndex >= inputStringWidth) {
349
- return inputString;
350
- }
351
- if (startIndex < 0 || endIndex < 0) {
352
- throw new RangeError("Negative indices aren't supported");
353
- }
354
- if (!inputString.includes("\x1B")) {
355
- if (/^[\u0000-\u007F]*$/.test(inputString)) {
356
- return inputString.slice(startIndex, endIndex);
357
- }
358
- return fastSlice(inputString, startIndex, endIndex, config);
359
- }
360
- RE_VALID_ANSI_PAIRS.lastIndex = 0;
361
- RE_VALID_HYPERLINKS.lastIndex = 0;
362
- if (!RE_VALID_ANSI_PAIRS.test(inputString) && !RE_VALID_HYPERLINKS.test(inputString)) {
363
- return inputString;
364
- }
365
- const segments = processIntoStyledSegments(inputString, config);
366
- if (segments.length === 0) {
367
- return "";
368
- }
369
- let currentPos = 0;
370
- const visibleSegments = [];
371
- for (const [index, segment] of segments.entries()) {
372
- const segmentStart = currentPos;
373
- const segmentEnd = currentPos + segment.visibleLength;
374
- if (segmentEnd > startIndex && segmentStart < endIndex) {
375
- const visibleStart = Math.max(0, startIndex - segmentStart);
376
- const visibleEnd = Math.min(segment.visibleLength, endIndex - segmentStart);
377
- visibleSegments.push({
378
- end: visibleEnd,
379
- index,
380
- segment,
381
- start: visibleStart
382
- });
383
- }
384
- currentPos = segmentEnd;
385
- }
386
- if (visibleSegments.length === 0) {
387
- return "";
388
- }
389
- const resultParts = [];
390
- const firstSegment = visibleSegments[0].segment;
391
- resultParts.push(firstSegment.before);
392
- for (let index = 0; index < visibleSegments.length; index++) {
393
- const { end, segment, start } = visibleSegments[index];
394
- if (start === 0 && end === segment.visibleLength) {
395
- resultParts.push(segment.content);
396
- } else {
397
- const graphemes = [...config.segmenter.segment(segment.content)];
398
- resultParts.push(
399
- graphemes.slice(start, end).map((entry) => entry.segment).join("")
400
- );
401
- }
402
- if (index < visibleSegments.length - 1) {
403
- const nextSegment = visibleSegments[index + 1].segment;
404
- const segmentAfter = segment.after;
405
- const nextBefore = nextSegment.before;
406
- if (segmentAfter !== nextBefore && (segmentAfter || nextBefore)) {
407
- resultParts.push(segmentAfter, nextBefore);
408
- }
409
- }
410
- }
411
- resultParts.push(visibleSegments.at(-1).segment.after);
412
- return resultParts.join("");
413
- }, "slice");
414
-
415
- export { slice };
1
+ var R=Object.defineProperty;var k=(t,l)=>R(t,"name",{value:l,configurable:!0});import{a as v,b as L,c as O}from"./packem_shared/constants-Cd17VNEv.mjs";import{getStringWidth as I}from"./get-string-width.mjs";import N from"./packem_shared/LRUCache-Bjo6gsbC.mjs";var j=Object.defineProperty,b=k((t,l)=>j(t,"name",{value:l,configurable:!0}),"y");const _=new N(100),F=new Intl.Segmenter("en",{granularity:"grapheme"}),M=new Set(["0","22","23","24","27","28","29","39","49"]),P=new Set(["1","3","4","7","8","9"]),y=new Map([["22","1"],["23","3"],["24","4"],["27","7"],["28","8"],["29","9"]]),S=b(t=>t>="30"&&t<="37"||t>="90"&&t<="97"||t.startsWith("38;"),"isForegroundColor"),w=b(t=>t>="40"&&t<="47"||t>="100"&&t<="107"||t.startsWith("48;"),"isBackgroundColor"),V=[{close:"\x1B[22m",open:"\x1B[1m"},{close:"\x1B[23m",open:"\x1B[3m"},{close:"\x1B[24m",open:"\x1B[4m"},{close:"\x1B[27m",open:"\x1B[7m"},{close:"\x1B[28m",open:"\x1B[8m"},{close:"\x1B[29m",open:"\x1B[9m"}],A=b((t,l)=>{let c=-1;for(const d of l){const h=t.indexOf(d);h>=0&&(c===-1||h<c)&&(c=h)}return c},"findFirstPositionOfAny"),$=b((t,l)=>{if(!t.includes("\x1B"))return[{after:"",before:"",content:t,visibleLength:I(t,l.width)}];const c=_.get(t);if(c)return c;const d=[],h=[];let g=0,m;for(O.lastIndex=0;(m=O.exec(t))!==null;){const f=m[0];d.push(t.slice(g,m.index)),h.push(f),g=m.index+f.length}g<t.length&&d.push(t.slice(g));const a=[];for(const f of h){if(f==="\x1B[0m"||f==="\x1B]8;;\x07"){a.push(f);continue}if(f.startsWith("\x1B[")&&f.endsWith("m")){const x=f.slice(2,-1);if(M.has(x)){a.push(f);continue}}}const s=new Set,B=[];for(const[f,x]of d.entries()){if(f>0&&h[f-1]){const n=h[f-1];if(n==="\x1B[0m")s.clear();else if(n==="\x1B]8;;\x07"){for(const i of s)if(i.startsWith("\x1B]8;;")&&!i.endsWith("\x1B]8;;\x07")){s.delete(i);break}}else if(n.startsWith("\x1B[")&&n.endsWith("m")){const i=n.slice(2,-1);if(i==="39"){for(const e of s)if(e.startsWith("\x1B[")&&e.endsWith("m")){const o=e.slice(2,-1);if(S(o)){s.delete(e);break}}}else if(i==="49"){for(const e of s)if(e.startsWith("\x1B[")&&e.endsWith("m")){const o=e.slice(2,-1);if(w(o)){s.delete(e);break}}}else if(y.has(i)){const e=y.get(i);for(const o of s)if(o===`\x1B[${e}m`){s.delete(o);break}}else{if(S(i)){for(const e of s)if(e.startsWith("\x1B[")&&e.endsWith("m")){const o=e.slice(2,-1);if(S(o)){s.delete(e);break}}}else if(w(i)){for(const e of s)if(e.startsWith("\x1B[")&&e.endsWith("m")){const o=e.slice(2,-1);if(w(o)){s.delete(e);break}}}else if(P.has(i)){const e=`\x1B[${i}m`;s.has(e)&&s.delete(e)}s.add(n)}}else if(n.startsWith("\x1B]8;;")&&!n.endsWith("\x1B]8;;\x07")){for(const i of s)if(i.startsWith("\x1B]8;;")&&!i.endsWith("\x1B]8;;\x07")){s.delete(i);break}s.add(n)}}if(x==="")continue;let u="";if(s.size>0)if(a.includes("\x1B[0m"))u="\x1B[0m";else{const n=[];let i=!1;for(const r of s)if(r.startsWith("\x1B]8;;")&&!r.endsWith("\x1B]8;;\x07")){i=!0;break}i&&a.includes("\x1B]8;;\x07")&&n.push("\x1B]8;;\x07");let e=!1,o=!1;for(const r of s)if(r.startsWith("\x1B[")&&r.endsWith("m")){const W=r.slice(2,-1);S(W)?e=!0:w(W)&&(o=!0)}if(e&&o){const r=A(t,["\x1B[3","\x1B[9","\x1B[38;"]),W=A(t,["\x1B[4","\x1B[10","\x1B[48;"]);r>=0&&W>=0?r>W?n.push("\x1B[39m","\x1B[49m"):n.push("\x1B[49m","\x1B[39m"):n.push("\x1B[39m","\x1B[49m")}else e&&n.push("\x1B[39m"),o&&n.push("\x1B[49m");e&&o&&t.includes("\x1B[39m")&&t.includes("\x1B[49m")&&(t.indexOf("\x1B[39m")<t.indexOf("\x1B[49m")?(n.length-=e&&o?2:e||o?1:0,n.push("\x1B[39m","\x1B[49m")):t.indexOf("\x1B[49m")<t.indexOf("\x1B[39m")&&(n.length-=e&&o?2:e||o?1:0,n.push("\x1B[49m","\x1B[39m")));const E=V.filter(r=>s.has(r.open)).map(r=>({position:t.indexOf(r.open),style:r})).filter(r=>r.position>=0).sort((r,W)=>W.position-r.position);for(const r of E)a.includes(r.style.close)&&n.push(r.style.close);u=n.join("")}const p=[...s].join("");B.push({after:u,before:p,content:x,visibleLength:I(x,{fullWidth:1,wideWidth:1})})}return _.set(t,B),B},"processIntoStyledSegments"),C=b((t,l,c,d)=>{const h=[...d.segmenter.segment(t)],g=[];let m=0,a=!1;for(const s of h){const B=I(s.segment,d.width),f=m,x=m+B;if(!a)if(f<l){m=x;continue}else a=!0;if(f>=c||x>c)break;g.push(s.segment),m=x}return g.join("")},"fastSlice"),H=b((t,l=0,c=Number.MAX_SAFE_INTEGER,d={})=>{const h={segmenter:F,...d};if(l>=c||t==="")return"";const g=I(t,h.width);if(l===0&&c>=g)return t;if(l<0||c<0)throw new RangeError("Negative indices aren't supported");if(!t.includes("\x1B"))return/^[\u0000-\u007F]*$/.test(t)?t.slice(l,c):C(t,l,c,h);if(v.lastIndex=0,L.lastIndex=0,!v.test(t)&&!L.test(t))return t;const m=$(t,h);if(m.length===0)return"";let a=0;const s=[];for(const[x,u]of m.entries()){const p=a,n=a+u.visibleLength;if(n>l&&p<c){const i=Math.max(0,l-p),e=Math.min(u.visibleLength,c-p);s.push({end:e,index:x,segment:u,start:i})}a=n}if(s.length===0)return"";const B=[],f=s[0].segment;B.push(f.before);for(let x=0;x<s.length;x++){const{end:u,segment:p,start:n}=s[x];if(n===0&&u===p.visibleLength)B.push(p.content);else{const i=[...h.segmenter.segment(p.content)];B.push(i.slice(n,u).map(e=>e.segment).join(""))}if(x<s.length-1){const i=s[x+1].segment,e=p.after,o=i.before;e!==o&&(e||o)&&B.push(e,o)}}return B.push(s.at(-1).segment.after),B.join("")},"slice");export{H as slice};
@@ -1,77 +1,16 @@
1
- 'use strict';
1
+ "use strict";var d=Object.defineProperty;var c=(e,t)=>d(e,"name",{value:t,configurable:!0});Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const g=require("node:util"),l=require("../get-string-width.cjs");var o=Object.defineProperty,a=c((e,t)=>o(e,"name",{value:t,configurable:!0}),"r");const n=a(e=>{const t=g.stripVTControlCharacters(e);return{ansi:e,json:JSON.stringify(e),lengthDifference:e.length-t.length,stripped:t,visible:e.replaceAll("\x1B","\\u001B")}},"formatAnsiString"),u=a((e,t)=>{const i=n(e),s=n(t);return{message:a(()=>{if(e===t)return"ANSI strings are identical";const r=i.stripped===s.stripped;return g.format(`ANSI string comparison failed:
2
2
 
3
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
3
+ Actual:
4
+ - Visible content: %s
5
+ - With escape codes: %s
6
+ - JSON: %s
7
+ - Length: %d
4
8
 
5
- const node_util = require('node:util');
6
- const getStringWidth = require('../get-string-width.cjs');
9
+ Expected:
10
+ - Visible content: %s
11
+ - With escape codes: %s
12
+ - JSON: %s
13
+ - Length: %d
7
14
 
8
- var __defProp = Object.defineProperty;
9
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
- const formatAnsiString = /* @__PURE__ */ __name((ansiString) => {
11
- const stripped = node_util.stripVTControlCharacters(ansiString);
12
- return {
13
- // Original ANSI string
14
- ansi: ansiString,
15
- // JSON stringified version to see all escape codes
16
- json: JSON.stringify(ansiString),
17
- // Length difference between ANSI and stripped string
18
- lengthDifference: ansiString.length - stripped.length,
19
- // String with ANSI codes stripped
20
- stripped,
21
- // String with ANSI escape codes shown as visible characters
22
- visible: ansiString.replaceAll("\x1B", "\\u001B")
23
- };
24
- }, "formatAnsiString");
25
- const expectAnsiStrings = /* @__PURE__ */ __name((actual, expected) => {
26
- const actualFormatted = formatAnsiString(actual);
27
- const expectedFormatted = formatAnsiString(expected);
28
- return {
29
- message: /* @__PURE__ */ __name(() => {
30
- if (actual === expected) {
31
- return "ANSI strings are identical";
32
- }
33
- const strippedEqual = actualFormatted.stripped === expectedFormatted.stripped;
34
- return node_util.format(
35
- "ANSI string comparison failed:\n\nActual:\n - Visible content: %s\n - With escape codes: %s\n - JSON: %s\n - Length: %d\n\nExpected:\n - Visible content: %s\n - With escape codes: %s\n - JSON: %s\n - Length: %d\n\n%s\n",
36
- actualFormatted.stripped,
37
- actualFormatted.visible,
38
- actualFormatted.json,
39
- getStringWidth.getStringWidth(actualFormatted.ansi),
40
- expectedFormatted.stripped,
41
- expectedFormatted.visible,
42
- expectedFormatted.json,
43
- getStringWidth.getStringWidth(expectedFormatted.ansi),
44
- strippedEqual ? "✓ Visible content is identical, but escape codes differ" : "✗ Visible content differs"
45
- );
46
- }, "message"),
47
- pass: actual === expected
48
- };
49
- }, "expectAnsiStrings");
50
- const compareAnsiStrings = /* @__PURE__ */ __name((actual, expected) => {
51
- const actualFormatted = formatAnsiString(actual);
52
- const expectedFormatted = formatAnsiString(expected);
53
- const strippedEqual = actualFormatted.stripped === expectedFormatted.stripped;
54
- const ansiEqual = actual === expected;
55
- return {
56
- // Format information for both strings
57
- actual: actualFormatted,
58
- // Are the strings identical including ANSI codes?
59
- ansiEqual,
60
- expected: expectedFormatted,
61
- // Are the strings identical when ANSI codes are stripped?
62
- strippedEqual,
63
- // Summary information
64
- summary: {
65
- actualLength: actual.length,
66
- actualStrippedLength: actualFormatted.stripped.length,
67
- ansiEqual,
68
- expectedLength: expected.length,
69
- expectedStrippedLength: expectedFormatted.stripped.length,
70
- strippedEqual
71
- }
72
- };
73
- }, "compareAnsiStrings");
74
-
75
- exports.compareAnsiStrings = compareAnsiStrings;
76
- exports.expectAnsiStrings = expectAnsiStrings;
77
- exports.formatAnsiString = formatAnsiString;
15
+ %s
16
+ `,i.stripped,i.visible,i.json,l.getStringWidth(i.ansi),s.stripped,s.visible,s.json,l.getStringWidth(s.ansi),r?"✓ Visible content is identical, but escape codes differ":"✗ Visible content differs")},"message"),pass:e===t}},"expectAnsiStrings"),S=a((e,t)=>{const i=n(e),s=n(t),r=i.stripped===s.stripped,p=e===t;return{actual:i,ansiEqual:p,expected:s,strippedEqual:r,summary:{actualLength:e.length,actualStrippedLength:i.stripped.length,ansiEqual:p,expectedLength:t.length,expectedStrippedLength:s.stripped.length,strippedEqual:r}}},"compareAnsiStrings");exports.compareAnsiStrings=S;exports.expectAnsiStrings=u;exports.formatAnsiString=n;
@@ -1,71 +1,16 @@
1
- import { format, stripVTControlCharacters } from 'node:util';
2
- import { getStringWidth } from '../get-string-width.mjs';
1
+ var o=Object.defineProperty;var c=(e,t)=>o(e,"name",{value:t,configurable:!0});import{stripVTControlCharacters as d,format as g}from"node:util";import{getStringWidth as l}from"../get-string-width.mjs";var u=Object.defineProperty,r=c((e,t)=>u(e,"name",{value:t,configurable:!0}),"r");const p=r(e=>{const t=d(e);return{ansi:e,json:JSON.stringify(e),lengthDifference:e.length-t.length,stripped:t,visible:e.replaceAll("\x1B","\\u001B")}},"formatAnsiString"),S=r((e,t)=>{const s=p(e),i=p(t);return{message:r(()=>{if(e===t)return"ANSI strings are identical";const n=s.stripped===i.stripped;return g(`ANSI string comparison failed:
3
2
 
4
- var __defProp = Object.defineProperty;
5
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
- const formatAnsiString = /* @__PURE__ */ __name((ansiString) => {
7
- const stripped = stripVTControlCharacters(ansiString);
8
- return {
9
- // Original ANSI string
10
- ansi: ansiString,
11
- // JSON stringified version to see all escape codes
12
- json: JSON.stringify(ansiString),
13
- // Length difference between ANSI and stripped string
14
- lengthDifference: ansiString.length - stripped.length,
15
- // String with ANSI codes stripped
16
- stripped,
17
- // String with ANSI escape codes shown as visible characters
18
- visible: ansiString.replaceAll("\x1B", "\\u001B")
19
- };
20
- }, "formatAnsiString");
21
- const expectAnsiStrings = /* @__PURE__ */ __name((actual, expected) => {
22
- const actualFormatted = formatAnsiString(actual);
23
- const expectedFormatted = formatAnsiString(expected);
24
- return {
25
- message: /* @__PURE__ */ __name(() => {
26
- if (actual === expected) {
27
- return "ANSI strings are identical";
28
- }
29
- const strippedEqual = actualFormatted.stripped === expectedFormatted.stripped;
30
- return format(
31
- "ANSI string comparison failed:\n\nActual:\n - Visible content: %s\n - With escape codes: %s\n - JSON: %s\n - Length: %d\n\nExpected:\n - Visible content: %s\n - With escape codes: %s\n - JSON: %s\n - Length: %d\n\n%s\n",
32
- actualFormatted.stripped,
33
- actualFormatted.visible,
34
- actualFormatted.json,
35
- getStringWidth(actualFormatted.ansi),
36
- expectedFormatted.stripped,
37
- expectedFormatted.visible,
38
- expectedFormatted.json,
39
- getStringWidth(expectedFormatted.ansi),
40
- strippedEqual ? "✓ Visible content is identical, but escape codes differ" : "✗ Visible content differs"
41
- );
42
- }, "message"),
43
- pass: actual === expected
44
- };
45
- }, "expectAnsiStrings");
46
- const compareAnsiStrings = /* @__PURE__ */ __name((actual, expected) => {
47
- const actualFormatted = formatAnsiString(actual);
48
- const expectedFormatted = formatAnsiString(expected);
49
- const strippedEqual = actualFormatted.stripped === expectedFormatted.stripped;
50
- const ansiEqual = actual === expected;
51
- return {
52
- // Format information for both strings
53
- actual: actualFormatted,
54
- // Are the strings identical including ANSI codes?
55
- ansiEqual,
56
- expected: expectedFormatted,
57
- // Are the strings identical when ANSI codes are stripped?
58
- strippedEqual,
59
- // Summary information
60
- summary: {
61
- actualLength: actual.length,
62
- actualStrippedLength: actualFormatted.stripped.length,
63
- ansiEqual,
64
- expectedLength: expected.length,
65
- expectedStrippedLength: expectedFormatted.stripped.length,
66
- strippedEqual
67
- }
68
- };
69
- }, "compareAnsiStrings");
3
+ Actual:
4
+ - Visible content: %s
5
+ - With escape codes: %s
6
+ - JSON: %s
7
+ - Length: %d
70
8
 
71
- export { compareAnsiStrings, expectAnsiStrings, formatAnsiString };
9
+ Expected:
10
+ - Visible content: %s
11
+ - With escape codes: %s
12
+ - JSON: %s
13
+ - Length: %d
14
+
15
+ %s
16
+ `,s.stripped,s.visible,s.json,l(s.ansi),i.stripped,i.visible,i.json,l(i.ansi),n?"✓ Visible content is identical, but escape codes differ":"✗ Visible content differs")},"message"),pass:e===t}},"expectAnsiStrings"),b=r((e,t)=>{const s=p(e),i=p(t),n=s.stripped===i.stripped,a=e===t;return{actual:s,ansiEqual:a,expected:i,strippedEqual:n,summary:{actualLength:e.length,actualStrippedLength:s.stripped.length,ansiEqual:a,expectedLength:t.length,expectedStrippedLength:i.stripped.length,strippedEqual:n}}},"compareAnsiStrings");export{b as compareAnsiStrings,S as expectAnsiStrings,p as formatAnsiString};
@@ -1,11 +1 @@
1
- 'use strict';
2
-
3
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
-
5
- const test_utils = require('./utils.cjs');
6
-
7
- var __defProp = Object.defineProperty;
8
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
- const toEqualAnsi = /* @__PURE__ */ __name((actual, expected) => test_utils.expectAnsiStrings(actual, expected), "toEqualAnsi");
10
-
11
- exports.toEqualAnsi = toEqualAnsi;
1
+ "use strict";var r=Object.defineProperty;var i=(e,t)=>r(e,"name",{value:t,configurable:!0});Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("./utils.cjs");var u=Object.defineProperty,n=i((e,t)=>u(e,"name",{value:t,configurable:!0}),"i");const o=n((e,t)=>s.expectAnsiStrings(e,t),"toEqualAnsi");exports.toEqualAnsi=o;
@@ -1,7 +1 @@
1
- import { expectAnsiStrings } from './utils.mjs';
2
-
3
- var __defProp = Object.defineProperty;
4
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
- const toEqualAnsi = /* @__PURE__ */ __name((actual, expected) => expectAnsiStrings(actual, expected), "toEqualAnsi");
6
-
7
- export { toEqualAnsi };
1
+ var i=Object.defineProperty;var t=(e,r)=>i(e,"name",{value:r,configurable:!0});import{expectAnsiStrings as n}from"./utils.mjs";var o=Object.defineProperty,a=t((e,r)=>o(e,"name",{value:r,configurable:!0}),"i");const c=a((e,r)=>n(e,r),"toEqualAnsi");export{c as toEqualAnsi};