@visulima/string 3.0.0-alpha.10 → 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.
- package/CHANGELOG.md +33 -0
- package/LICENSE.md +68 -3
- package/dist/align-text.d.ts +35 -0
- package/dist/align-text.js +2 -34
- package/dist/case/camel-case.d.ts +17 -2
- package/dist/case/camel-case.js +1 -55
- package/dist/case/capital-case.d.ts +14 -2
- package/dist/case/capital-case.js +1 -47
- package/dist/case/constant-case.d.ts +14 -2
- package/dist/case/constant-case.js +1 -7
- package/dist/case/dot-case.d.ts +14 -2
- package/dist/case/dot-case.js +1 -7
- package/dist/case/flat-case.d.ts +12 -2
- package/dist/case/flat-case.js +1 -7
- package/dist/case/flip-case.d.ts +16 -2
- package/dist/case/flip-case.js +1 -82
- package/dist/case/identify-case.d.ts +15 -2
- package/dist/case/identify-case.js +1 -66
- package/dist/case/index.d.ts +8 -2
- package/dist/case/index.js +1 -20
- package/dist/case/kebab-case.d.ts +25 -2
- package/dist/case/kebab-case.js +1 -55
- package/dist/case/lower-first.d.ts +13 -2
- package/dist/case/lower-first.js +1 -9
- package/dist/case/no-case.d.ts +14 -2
- package/dist/case/no-case.js +1 -7
- package/dist/case/pascal-case.d.ts +17 -2
- package/dist/case/pascal-case.js +1 -48
- package/dist/case/pascal-snake-case.d.ts +14 -2
- package/dist/case/pascal-snake-case.js +1 -28
- package/dist/case/path-case.d.ts +14 -2
- package/dist/case/path-case.js +1 -7
- package/dist/case/sentence-case.d.ts +14 -2
- package/dist/case/sentence-case.js +1 -54
- package/dist/case/snake-case.d.ts +14 -2
- package/dist/case/snake-case.js +1 -7
- package/dist/case/split-by-case.d.ts +29 -2
- package/dist/case/split-by-case.js +1 -763
- package/dist/case/title-case.d.ts +12 -2
- package/dist/case/title-case.js +1 -40
- package/dist/case/train-case.d.ts +14 -2
- package/dist/case/train-case.js +1 -40
- package/dist/case/upper-first.d.ts +13 -2
- package/dist/case/upper-first.js +1 -9
- package/dist/closest-string.d.ts +32 -0
- package/dist/closest-string.js +1 -22
- package/dist/compare-similarity.d.ts +38 -1
- package/dist/compare-similarity.js +1 -12
- package/dist/get-string-truncated-width.d.ts +151 -0
- package/dist/get-string-truncated-width.js +1 -332
- package/dist/get-string-width.d.ts +58 -0
- package/dist/get-string-width.js +1 -5
- package/dist/index.d.ts +194 -9
- package/dist/index.js +1 -44
- package/dist/native-string-types.d.ts +239 -0
- package/dist/outdent.d.ts +74 -0
- package/dist/outdent.js +1 -109
- package/dist/packem_shared/LRUCache-Bjo6gsbC.js +1 -0
- package/dist/packem_shared/closest-uarbVSbs.js +1 -0
- package/dist/packem_shared/closestN-Vd5oNJy_.js +1 -0
- package/dist/packem_shared/constants-DmzZF6_u.js +1 -0
- package/dist/packem_shared/countOccurrences-DIHSCdcG.js +1 -0
- package/dist/packem_shared/direction-dtczwUOE.js +1 -0
- package/dist/packem_shared/eastAsianWidthType-lcBsj7vg.js +1 -0
- package/dist/packem_shared/excerpt-DhV2yoHG.js +54 -0
- package/dist/packem_shared/generate-cache-key-DPByFaMH.js +1 -0
- package/dist/packem_shared/indent-CDlPQmpe.js +1 -0
- package/dist/packem_shared/isFullwidthCodePoint-Dmsf2-5L.js +1 -0
- package/dist/packem_shared/joinSegments-D27SxoCV.js +1 -0
- package/dist/packem_shared/lookup-ChWuUpyb.js +1 -0
- package/dist/packem_shared/normalize-german-eszett-AKfdw2MZ.js +1 -0
- package/dist/packem_shared/redent-BECVOaZp.js +1 -0
- package/dist/packem_shared/replaceString-aq-C7Wor.js +1 -0
- package/dist/packem_shared/stripIndent-Dt8hSxVM.js +1 -0
- package/dist/packem_shared/transliterate-D1p1yYE7.js +5 -0
- package/dist/packem_shared/types.d-FOLSY2Tc.d.ts +392 -0
- package/dist/packem_shared/types.d-NJ4vcG-A.d.ts +346 -0
- package/dist/slice.d.ts +42 -0
- package/dist/slice.js +1 -415
- package/dist/slugify.d.ts +10 -1
- package/dist/slugify.js +1 -46
- package/dist/test/utils.d.ts +17 -0
- package/dist/test/utils.js +13 -88
- package/dist/test/vitest.d.ts +3 -0
- package/dist/test/vitest.js +1 -5
- package/dist/truncate.d.ts +43 -0
- package/dist/truncate.js +1 -112
- package/dist/utilities.d.ts +28 -1
- package/dist/utilities.js +1 -52
- package/dist/word-similarity-sort.d.ts +34 -0
- package/dist/word-similarity-sort.js +1 -22
- package/dist/word-wrap.d.ts +44 -0
- package/dist/word-wrap.js +8 -639
- package/package.json +46 -46
- package/dist/packem_shared/LRUCache-3r3SovvR.js +0 -46
- package/dist/packem_shared/closest-IHuSvnSn.js +0 -139
- package/dist/packem_shared/closestN-DUsjgiXb.js +0 -25
- package/dist/packem_shared/constants-BsZS5f0z.js +0 -95
- package/dist/packem_shared/countOccurrences-CS9XprQN.js +0 -22
- package/dist/packem_shared/direction-C9gfWWTK.js +0 -16
- package/dist/packem_shared/eastAsianWidthType-SD3YniiT.js +0 -20
- package/dist/packem_shared/excerpt-COsVNttN.js +0 -1502
- package/dist/packem_shared/generate-cache-key-DdayDfjV.js +0 -6
- package/dist/packem_shared/indent-D3DSCa6s.js +0 -33
- package/dist/packem_shared/isFullwidthCodePoint-IFXZxNjq.js +0 -10
- package/dist/packem_shared/joinSegments-CvxSgKz0.js +0 -44
- package/dist/packem_shared/lookup-BE8lEqy4.js +0 -104
- package/dist/packem_shared/normalize-german-eszett-4p3yKEzn.js +0 -8
- package/dist/packem_shared/redent-DSb1IJWn.js +0 -8
- package/dist/packem_shared/replaceString-Ce8X2ZQ-.js +0 -192
- package/dist/packem_shared/stripIndent-D_TRjxZ_.js +0 -20
- package/dist/packem_shared/transliterate-CKt9VK7D.js +0 -47756
- package/dist/packem_shared/types.d-BVNv675q.d.ts +0 -61
- package/dist/packem_shared/types.d-DfgbcNKh.d.ts +0 -57
package/dist/slice.js
CHANGED
|
@@ -1,415 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { getStringWidth } from './get-string-width.js';
|
|
3
|
-
import LRUCache from './packem_shared/LRUCache-3r3SovvR.js';
|
|
4
|
-
|
|
5
|
-
const segmentCache = new LRUCache(100);
|
|
6
|
-
const defaultSegmenter = new Intl.Segmenter("en", { granularity: "grapheme" });
|
|
7
|
-
const RE_ASCII_ONLY = /^[\u0000-\u007F]*$/;
|
|
8
|
-
const ANSI_RESET_CODES = /* @__PURE__ */ new Set([
|
|
9
|
-
"0",
|
|
10
|
-
// Full reset
|
|
11
|
-
"22",
|
|
12
|
-
// Bold reset
|
|
13
|
-
"23",
|
|
14
|
-
// Italic reset
|
|
15
|
-
"24",
|
|
16
|
-
// Underline reset
|
|
17
|
-
"27",
|
|
18
|
-
// Inverse reset
|
|
19
|
-
"28",
|
|
20
|
-
// Hidden reset
|
|
21
|
-
"29",
|
|
22
|
-
// Strikethrough reset
|
|
23
|
-
"39",
|
|
24
|
-
// Foreground color reset
|
|
25
|
-
"49"
|
|
26
|
-
// Background color reset
|
|
27
|
-
]);
|
|
28
|
-
const STYLE_CODES = /* @__PURE__ */ new Set([
|
|
29
|
-
"1",
|
|
30
|
-
// Bold
|
|
31
|
-
"3",
|
|
32
|
-
// Italic
|
|
33
|
-
"4",
|
|
34
|
-
// Underline
|
|
35
|
-
"7",
|
|
36
|
-
// Inverse
|
|
37
|
-
"8",
|
|
38
|
-
// Hidden
|
|
39
|
-
"9"
|
|
40
|
-
// Strikethrough
|
|
41
|
-
]);
|
|
42
|
-
const FORMAT_RESET_CODES = /* @__PURE__ */ new Map([
|
|
43
|
-
["22", "1"],
|
|
44
|
-
// Bold reset
|
|
45
|
-
["23", "3"],
|
|
46
|
-
// Italic reset
|
|
47
|
-
["24", "4"],
|
|
48
|
-
// Underline reset
|
|
49
|
-
["27", "7"],
|
|
50
|
-
// Inverse reset
|
|
51
|
-
["28", "8"],
|
|
52
|
-
// Hidden reset
|
|
53
|
-
["29", "9"]
|
|
54
|
-
// Strikethrough reset
|
|
55
|
-
]);
|
|
56
|
-
const isForegroundColor = (code) => code >= "30" && code <= "37" || code >= "90" && code <= "97" || code.startsWith("38;");
|
|
57
|
-
const isBackgroundColor = (code) => code >= "40" && code <= "47" || code >= "100" && code <= "107" || code.startsWith("48;");
|
|
58
|
-
const FORMAT_STYLES = [
|
|
59
|
-
{ close: "\x1B[22m", open: "\x1B[1m" },
|
|
60
|
-
// Bold
|
|
61
|
-
{ close: "\x1B[23m", open: "\x1B[3m" },
|
|
62
|
-
// Italic
|
|
63
|
-
{ close: "\x1B[24m", open: "\x1B[4m" },
|
|
64
|
-
// Underline
|
|
65
|
-
{ close: "\x1B[27m", open: "\x1B[7m" },
|
|
66
|
-
// Inverse
|
|
67
|
-
{ close: "\x1B[28m", open: "\x1B[8m" },
|
|
68
|
-
// Hidden
|
|
69
|
-
{ close: "\x1B[29m", open: "\x1B[9m" }
|
|
70
|
-
// Strikethrough
|
|
71
|
-
];
|
|
72
|
-
const findFirstPositionOfAny = (input, substrings) => {
|
|
73
|
-
let firstPos = -1;
|
|
74
|
-
for (const sub of substrings) {
|
|
75
|
-
const pos = input.indexOf(sub);
|
|
76
|
-
if (pos !== -1 && (firstPos === -1 || pos < firstPos)) {
|
|
77
|
-
firstPos = pos;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return firstPos;
|
|
81
|
-
};
|
|
82
|
-
const processIntoStyledSegments = (input, options) => {
|
|
83
|
-
if (!input.includes("\x1B")) {
|
|
84
|
-
return [
|
|
85
|
-
{
|
|
86
|
-
after: "",
|
|
87
|
-
before: "",
|
|
88
|
-
content: input,
|
|
89
|
-
visibleLength: getStringWidth(input, options.width)
|
|
90
|
-
}
|
|
91
|
-
];
|
|
92
|
-
}
|
|
93
|
-
const cachedResult = segmentCache.get(input);
|
|
94
|
-
if (cachedResult) {
|
|
95
|
-
return cachedResult;
|
|
96
|
-
}
|
|
97
|
-
const parts = [];
|
|
98
|
-
const matches = [];
|
|
99
|
-
let lastIndex = 0;
|
|
100
|
-
let match;
|
|
101
|
-
RE_ANSI.lastIndex = 0;
|
|
102
|
-
while ((match = RE_ANSI.exec(input)) !== null) {
|
|
103
|
-
const matchedText = match[0];
|
|
104
|
-
parts.push(input.slice(lastIndex, match.index));
|
|
105
|
-
matches.push(matchedText);
|
|
106
|
-
lastIndex = match.index + matchedText.length;
|
|
107
|
-
}
|
|
108
|
-
if (lastIndex < input.length) {
|
|
109
|
-
parts.push(input.slice(lastIndex));
|
|
110
|
-
}
|
|
111
|
-
const closingSequences = [];
|
|
112
|
-
for (const ansi of matches) {
|
|
113
|
-
if (ansi === "\x1B[0m" || ansi === "\x1B]8;;\x07") {
|
|
114
|
-
closingSequences.push(ansi);
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
if (ansi.startsWith("\x1B[") && ansi.endsWith("m")) {
|
|
118
|
-
const code = ansi.slice(2, -1);
|
|
119
|
-
if (ANSI_RESET_CODES.has(code)) {
|
|
120
|
-
closingSequences.push(ansi);
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
const activeStylesSet = /* @__PURE__ */ new Set();
|
|
126
|
-
const segments = [];
|
|
127
|
-
for (const [index, text] of parts.entries()) {
|
|
128
|
-
if (index > 0 && matches[index - 1]) {
|
|
129
|
-
const ansi = matches[index - 1];
|
|
130
|
-
if (ansi === "\x1B[0m") {
|
|
131
|
-
activeStylesSet.clear();
|
|
132
|
-
} else if (ansi === "\x1B]8;;\x07") {
|
|
133
|
-
for (const style of activeStylesSet) {
|
|
134
|
-
if (style.startsWith("\x1B]8;;") && !style.endsWith("\x1B]8;;\x07")) {
|
|
135
|
-
activeStylesSet.delete(style);
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
} else if (ansi.startsWith("\x1B[") && ansi.endsWith("m")) {
|
|
140
|
-
const code = ansi.slice(2, -1);
|
|
141
|
-
if (code === "39") {
|
|
142
|
-
for (const style of activeStylesSet) {
|
|
143
|
-
if (style.startsWith("\x1B[") && style.endsWith("m")) {
|
|
144
|
-
const styleCode = style.slice(2, -1);
|
|
145
|
-
if (isForegroundColor(styleCode)) {
|
|
146
|
-
activeStylesSet.delete(style);
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
} else if (code === "49") {
|
|
152
|
-
for (const style of activeStylesSet) {
|
|
153
|
-
if (style.startsWith("\x1B[") && style.endsWith("m")) {
|
|
154
|
-
const styleCode = style.slice(2, -1);
|
|
155
|
-
if (isBackgroundColor(styleCode)) {
|
|
156
|
-
activeStylesSet.delete(style);
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
} else if (FORMAT_RESET_CODES.has(code)) {
|
|
162
|
-
const targetCode = FORMAT_RESET_CODES.get(code);
|
|
163
|
-
for (const style of activeStylesSet) {
|
|
164
|
-
if (style === `\x1B[${targetCode}m`) {
|
|
165
|
-
activeStylesSet.delete(style);
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
} else {
|
|
170
|
-
if (isForegroundColor(code)) {
|
|
171
|
-
for (const style of activeStylesSet) {
|
|
172
|
-
if (style.startsWith("\x1B[") && style.endsWith("m")) {
|
|
173
|
-
const styleCode = style.slice(2, -1);
|
|
174
|
-
if (isForegroundColor(styleCode)) {
|
|
175
|
-
activeStylesSet.delete(style);
|
|
176
|
-
break;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
} else if (isBackgroundColor(code)) {
|
|
181
|
-
for (const style of activeStylesSet) {
|
|
182
|
-
if (style.startsWith("\x1B[") && style.endsWith("m")) {
|
|
183
|
-
const styleCode = style.slice(2, -1);
|
|
184
|
-
if (isBackgroundColor(styleCode)) {
|
|
185
|
-
activeStylesSet.delete(style);
|
|
186
|
-
break;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
} else if (STYLE_CODES.has(code)) {
|
|
191
|
-
const targetStyle = `\x1B[${code}m`;
|
|
192
|
-
if (activeStylesSet.has(targetStyle)) {
|
|
193
|
-
activeStylesSet.delete(targetStyle);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
activeStylesSet.add(ansi);
|
|
197
|
-
}
|
|
198
|
-
} else if (ansi.startsWith("\x1B]8;;") && !ansi.endsWith("\x1B]8;;\x07")) {
|
|
199
|
-
for (const style of activeStylesSet) {
|
|
200
|
-
if (style.startsWith("\x1B]8;;") && !style.endsWith("\x1B]8;;\x07")) {
|
|
201
|
-
activeStylesSet.delete(style);
|
|
202
|
-
break;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
activeStylesSet.add(ansi);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
if (text === "") {
|
|
209
|
-
continue;
|
|
210
|
-
}
|
|
211
|
-
let closingSequence = "";
|
|
212
|
-
if (activeStylesSet.size > 0) {
|
|
213
|
-
if (closingSequences.includes("\x1B[0m")) {
|
|
214
|
-
closingSequence = "\x1B[0m";
|
|
215
|
-
} else {
|
|
216
|
-
const closingParts = [];
|
|
217
|
-
let needsHyperlinkClose = false;
|
|
218
|
-
for (const style of activeStylesSet) {
|
|
219
|
-
if (style.startsWith("\x1B]8;;") && !style.endsWith("\x1B]8;;\x07")) {
|
|
220
|
-
needsHyperlinkClose = true;
|
|
221
|
-
break;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
if (needsHyperlinkClose && closingSequences.includes("\x1B]8;;\x07")) {
|
|
225
|
-
closingParts.push("\x1B]8;;\x07");
|
|
226
|
-
}
|
|
227
|
-
let needsForegroundClose = false;
|
|
228
|
-
let needsBackgroundClose = false;
|
|
229
|
-
for (const style of activeStylesSet) {
|
|
230
|
-
if (style.startsWith("\x1B[") && style.endsWith("m")) {
|
|
231
|
-
const styleCode = style.slice(2, -1);
|
|
232
|
-
if (isForegroundColor(styleCode)) {
|
|
233
|
-
needsForegroundClose = true;
|
|
234
|
-
} else if (isBackgroundColor(styleCode)) {
|
|
235
|
-
needsBackgroundClose = true;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
if (needsForegroundClose && needsBackgroundClose) {
|
|
240
|
-
const fgOpenPos = findFirstPositionOfAny(input, [
|
|
241
|
-
"\x1B[3",
|
|
242
|
-
// Basic colors 30-37
|
|
243
|
-
"\x1B[9",
|
|
244
|
-
// Bright colors 90-97
|
|
245
|
-
"\x1B[38;"
|
|
246
|
-
// RGB/256 colors
|
|
247
|
-
]);
|
|
248
|
-
const bgOpenPos = findFirstPositionOfAny(input, [
|
|
249
|
-
"\x1B[4",
|
|
250
|
-
// Basic colors 40-47
|
|
251
|
-
"\x1B[10",
|
|
252
|
-
// Bright colors 100-107
|
|
253
|
-
"\x1B[48;"
|
|
254
|
-
// RGB/256 colors
|
|
255
|
-
]);
|
|
256
|
-
if (fgOpenPos >= 0 && bgOpenPos >= 0) {
|
|
257
|
-
if (fgOpenPos > bgOpenPos) {
|
|
258
|
-
closingParts.push("\x1B[39m", "\x1B[49m");
|
|
259
|
-
} else {
|
|
260
|
-
closingParts.push("\x1B[49m", "\x1B[39m");
|
|
261
|
-
}
|
|
262
|
-
} else {
|
|
263
|
-
closingParts.push("\x1B[39m", "\x1B[49m");
|
|
264
|
-
}
|
|
265
|
-
} else {
|
|
266
|
-
if (needsForegroundClose) {
|
|
267
|
-
closingParts.push("\x1B[39m");
|
|
268
|
-
}
|
|
269
|
-
if (needsBackgroundClose) {
|
|
270
|
-
closingParts.push("\x1B[49m");
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
if (needsForegroundClose && needsBackgroundClose && input.includes("\x1B[39m") && input.includes("\x1B[49m")) {
|
|
274
|
-
if (input.indexOf("\x1B[39m") < input.indexOf("\x1B[49m")) {
|
|
275
|
-
closingParts.length -= 2;
|
|
276
|
-
closingParts.push("\x1B[39m", "\x1B[49m");
|
|
277
|
-
} else if (input.indexOf("\x1B[49m") < input.indexOf("\x1B[39m")) {
|
|
278
|
-
closingParts.length -= 2;
|
|
279
|
-
closingParts.push("\x1B[49m", "\x1B[39m");
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
const activeFormatStyles = FORMAT_STYLES.filter((style) => activeStylesSet.has(style.open)).map((style) => {
|
|
283
|
-
return {
|
|
284
|
-
position: input.indexOf(style.open),
|
|
285
|
-
style
|
|
286
|
-
};
|
|
287
|
-
}).filter((item) => item.position >= 0).toSorted((a, b) => b.position - a.position);
|
|
288
|
-
for (const activeFormatStyle of activeFormatStyles) {
|
|
289
|
-
const item = activeFormatStyle;
|
|
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
|
-
};
|
|
311
|
-
const fastSlice = (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
|
-
};
|
|
339
|
-
const slice = (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 (RE_ASCII_ONLY.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
|
-
};
|
|
414
|
-
|
|
415
|
-
export { slice };
|
|
1
|
+
var _=Object.defineProperty;var w=(t,c)=>_(t,"name",{value:c,configurable:!0});import{j as v,k as A,g as O}from"./packem_shared/constants-DmzZF6_u.js";import{getStringWidth as k}from"./get-string-width.js";import j from"./packem_shared/LRUCache-Bjo6gsbC.js";var N=Object.defineProperty,b=w((t,c)=>N(t,"name",{value:c,configurable:!0}),"y");const y=new j(100),F=new Intl.Segmenter("en",{granularity:"grapheme"}),M=/^[\u0000-\u007F]*$/,P=new Set(["0","22","23","24","27","28","29","39","49"]),V=new Set(["1","3","4","7","8","9"]),E=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"),I=b(t=>t>="40"&&t<="47"||t>="100"&&t<="107"||t.startsWith("48;"),"isBackgroundColor"),$=[{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"}],L=b((t,c)=>{let l=-1;for(const d of c){const h=t.indexOf(d);h!==-1&&(l===-1||h<l)&&(l=h)}return l},"findFirstPositionOfAny"),C=b((t,c)=>{if(!t.includes("\x1B"))return[{after:"",before:"",content:t,visibleLength:k(t,c.width)}];const l=y.get(t);if(l)return l;const d=[],h=[];let W=0,m;for(O.lastIndex=0;(m=O.exec(t))!==null;){const r=m[0];d.push(t.slice(W,m.index)),h.push(r),W=m.index+r.length}W<t.length&&d.push(t.slice(W));const a=[];for(const r of h){if(r==="\x1B[0m"||r==="\x1B]8;;\x07"){a.push(r);continue}if(r.startsWith("\x1B[")&&r.endsWith("m")){const x=r.slice(2,-1);if(P.has(x)){a.push(r);continue}}}const s=new Set,B=[];for(const[r,x]of d.entries()){if(r>0&&h[r-1]){const n=h[r-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 f=e.slice(2,-1);if(S(f)){s.delete(e);break}}}else if(i==="49"){for(const e of s)if(e.startsWith("\x1B[")&&e.endsWith("m")){const f=e.slice(2,-1);if(I(f)){s.delete(e);break}}}else if(E.has(i)){const e=E.get(i);for(const f of s)if(f===`\x1B[${e}m`){s.delete(f);break}}else{if(S(i)){for(const e of s)if(e.startsWith("\x1B[")&&e.endsWith("m")){const f=e.slice(2,-1);if(S(f)){s.delete(e);break}}}else if(I(i)){for(const e of s)if(e.startsWith("\x1B[")&&e.endsWith("m")){const f=e.slice(2,-1);if(I(f)){s.delete(e);break}}}else if(V.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 o of s)if(o.startsWith("\x1B]8;;")&&!o.endsWith("\x1B]8;;\x07")){i=!0;break}i&&a.includes("\x1B]8;;\x07")&&n.push("\x1B]8;;\x07");let e=!1,f=!1;for(const o of s)if(o.startsWith("\x1B[")&&o.endsWith("m")){const g=o.slice(2,-1);S(g)?e=!0:I(g)&&(f=!0)}if(e&&f){const o=L(t,["\x1B[3","\x1B[9","\x1B[38;"]),g=L(t,["\x1B[4","\x1B[10","\x1B[48;"]);o>=0&&g>=0?o>g?n.push("\x1B[39m","\x1B[49m"):n.push("\x1B[49m","\x1B[39m"):n.push("\x1B[39m","\x1B[49m")}else e&&n.push("\x1B[39m"),f&&n.push("\x1B[49m");e&&f&&t.includes("\x1B[39m")&&t.includes("\x1B[49m")&&(t.indexOf("\x1B[39m")<t.indexOf("\x1B[49m")?(n.length-=2,n.push("\x1B[39m","\x1B[49m")):t.indexOf("\x1B[49m")<t.indexOf("\x1B[39m")&&(n.length-=2,n.push("\x1B[49m","\x1B[39m")));const R=$.filter(o=>s.has(o.open)).map(o=>({position:t.indexOf(o.open),style:o})).filter(o=>o.position>=0).toSorted((o,g)=>g.position-o.position);for(const o of R){const g=o;a.includes(g.style.close)&&n.push(g.style.close)}u=n.join("")}const p=[...s].join("");B.push({after:u,before:p,content:x,visibleLength:k(x,{fullWidth:1,wideWidth:1})})}return y.set(t,B),B},"processIntoStyledSegments"),D=b((t,c,l,d)=>{const h=[...d.segmenter.segment(t)],W=[];let m=0,a=!1;for(const s of h){const B=k(s.segment,d.width),r=m,x=m+B;if(!a)if(r<c){m=x;continue}else a=!0;if(r>=l||x>l)break;W.push(s.segment),m=x}return W.join("")},"fastSlice"),K=b((t,c=0,l=Number.MAX_SAFE_INTEGER,d={})=>{const h={segmenter:F,...d};if(c>=l||t==="")return"";const W=k(t,h.width);if(c===0&&l>=W)return t;if(c<0||l<0)throw new RangeError("Negative indices aren't supported");if(!t.includes("\x1B"))return M.test(t)?t.slice(c,l):D(t,c,l,h);if(v.lastIndex=0,A.lastIndex=0,!v.test(t)&&!A.test(t))return t;const m=C(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>c&&p<l){const i=Math.max(0,c-p),e=Math.min(u.visibleLength,l-p);s.push({end:e,index:x,segment:u,start:i})}a=n}if(s.length===0)return"";const B=[],r=s[0].segment;B.push(r.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,f=i.before;e!==f&&(e||f)&&B.push(e,f)}}return B.push(s.at(-1).segment.after),B.join("")},"slice");export{K as slice};
|
package/dist/slugify.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
import { S as SlugifyOptions } from "./packem_shared/types.d-
|
|
1
|
+
import { S as SlugifyOptions } from "./packem_shared/types.d-NJ4vcG-A.js";
|
|
2
|
+
/**
|
|
3
|
+
* Converts a string into a URL-friendly slug.
|
|
4
|
+
*
|
|
5
|
+
* It transliterates non-ASCII characters, optionally converts case,
|
|
6
|
+
* removes disallowed characters (replacing with separator), and collapses separators.
|
|
7
|
+
* @param input The string to convert.
|
|
8
|
+
* @param options Optional configuration options.
|
|
9
|
+
* @returns The generated slug.
|
|
10
|
+
*/
|
|
2
11
|
declare const slugify: (input: string, options?: SlugifyOptions) => string;
|
|
3
12
|
export { slugify as default };
|
package/dist/slugify.js
CHANGED
|
@@ -1,46 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { escapeRegExp } from './utilities.js';
|
|
3
|
-
|
|
4
|
-
const removeDisallowedChars = (input, allowedChars, separator) => {
|
|
5
|
-
const escapedChars = escapeRegExp(allowedChars).replaceAll(String.raw`\-`, "-");
|
|
6
|
-
const pattern = new RegExp(`[^${escapedChars}]`, "g");
|
|
7
|
-
return input.replaceAll(pattern, separator);
|
|
8
|
-
};
|
|
9
|
-
const slugify = (input, options) => {
|
|
10
|
-
const config = {
|
|
11
|
-
allowedChars: "a-zA-Z0-9-_.~",
|
|
12
|
-
fixChineseSpacing: true,
|
|
13
|
-
ignore: [],
|
|
14
|
-
lowercase: true,
|
|
15
|
-
replaceAfter: [],
|
|
16
|
-
replaceBefore: [],
|
|
17
|
-
separator: "-",
|
|
18
|
-
transliterate: true,
|
|
19
|
-
trim: false,
|
|
20
|
-
unknown: "",
|
|
21
|
-
uppercase: false,
|
|
22
|
-
...options
|
|
23
|
-
};
|
|
24
|
-
if (config.lowercase && config.uppercase) {
|
|
25
|
-
console.warn("slugify: Both lowercase and uppercase options are true. Defaulting to lowercase.");
|
|
26
|
-
config.uppercase = false;
|
|
27
|
-
}
|
|
28
|
-
let slug = config.transliterate ? transliterate(input, config) : input.normalize("NFC");
|
|
29
|
-
if (config.lowercase) {
|
|
30
|
-
slug = slug.toLowerCase();
|
|
31
|
-
} else if (config.uppercase) {
|
|
32
|
-
slug = slug.toUpperCase();
|
|
33
|
-
}
|
|
34
|
-
slug = removeDisallowedChars(slug, config.allowedChars, config.separator);
|
|
35
|
-
const escapedSeparator = escapeRegExp(config.separator);
|
|
36
|
-
if (escapedSeparator) {
|
|
37
|
-
const separatorRegex = new RegExp(`${escapedSeparator}+`, "g");
|
|
38
|
-
slug = slug.replace(separatorRegex, config.separator);
|
|
39
|
-
}
|
|
40
|
-
if (escapedSeparator) {
|
|
41
|
-
return slug.replaceAll(new RegExp(`^${escapedSeparator}+|${escapedSeparator}+$`, "g"), "");
|
|
42
|
-
}
|
|
43
|
-
return slug;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export { slugify as default };
|
|
1
|
+
var c=Object.defineProperty;var s=(a,o)=>c(a,"name",{value:o,configurable:!0});import i from"./packem_shared/transliterate-D1p1yYE7.js";import{escapeRegExp as t}from"./utilities.js";var u=Object.defineProperty,p=s((a,o)=>u(a,"name",{value:o,configurable:!0}),"o");const f=p((a,o,e)=>{const r=t(o).replaceAll(String.raw`\-`,"-"),l=new RegExp(`[^${r}]`,"g");return a.replaceAll(l,e)},"removeDisallowedChars"),C=p((a,o)=>{const e={allowedChars:"a-zA-Z0-9-_.~",fixChineseSpacing:!0,ignore:[],lowercase:!0,replaceAfter:[],replaceBefore:[],separator:"-",transliterate:!0,trim:!1,unknown:"",uppercase:!1,...o};e.lowercase&&e.uppercase&&(console.warn("slugify: Both lowercase and uppercase options are true. Defaulting to lowercase."),e.uppercase=!1);let r=e.transliterate?i(a,e):a.normalize("NFC");e.lowercase?r=r.toLowerCase():e.uppercase&&(r=r.toUpperCase()),r=f(r,e.allowedChars,e.separator);const l=t(e.separator);if(l){const n=new RegExp(`${l}+`,"g");r=r.replace(n,e.separator)}return l?r.replaceAll(new RegExp(`^${l}+|${l}+$`,"g"),""):r},"slugify");export{C as default};
|
package/dist/test/utils.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats ANSI strings for test output.
|
|
3
|
+
* @param ansiString The ANSI string to format
|
|
4
|
+
* @returns An object with formatted representations of the string
|
|
5
|
+
*/
|
|
1
6
|
declare const formatAnsiString: (ansiString: string) => {
|
|
2
7
|
ansi: string;
|
|
3
8
|
json: string;
|
|
@@ -11,7 +16,19 @@ interface ExpectationResult {
|
|
|
11
16
|
message: () => string;
|
|
12
17
|
pass: boolean;
|
|
13
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates an expect matcher that provides detailed information about ANSI string comparison failures.
|
|
21
|
+
* @param actual The actual ANSI string
|
|
22
|
+
* @param expected The expected ANSI string
|
|
23
|
+
* @returns A detailed comparison result
|
|
24
|
+
*/
|
|
14
25
|
declare const expectAnsiStrings: (actual: string, expected: string) => ExpectationResult;
|
|
26
|
+
/**
|
|
27
|
+
* Compares ANSI strings and returns the differences.
|
|
28
|
+
* @param actual The actual ANSI string
|
|
29
|
+
* @param expected The expected ANSI string
|
|
30
|
+
* @returns Details about the comparison
|
|
31
|
+
*/
|
|
15
32
|
declare const compareAnsiStrings: (actual: string, expected: string) => {
|
|
16
33
|
actual: ReturnType<typeof formatAnsiString>;
|
|
17
34
|
ansiEqual: boolean;
|
package/dist/test/utils.js
CHANGED
|
@@ -1,91 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
var d=Object.defineProperty;var a=(e,t)=>d(e,"name",{value:t,configurable:!0});import{createRequire as g}from"node:module";import{getStringWidth as l}from"../get-string-width.js";const u=g(import.meta.url),n=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,f=a(e=>{if(typeof n<"u"&&n.versions&&n.versions.node){const[t,s]=n.versions.node.split(".").map(Number);if(t>22||t===22&&s>=3||t===20&&s>=16)return n.getBuiltinModule(e)}return u(e)},"__cjs_getBuiltinModule"),{format:h,stripVTControlCharacters:m}=f("node:util");var S=Object.defineProperty,o=a((e,t)=>S(e,"name",{value:t,configurable:!0}),"r");const p=o(e=>{const t=m(e);return{ansi:e,json:JSON.stringify(e),lengthDifference:e.length-t.length,stripped:t,visible:e.replaceAll("\x1B",String.raw`\u001B`)}},"formatAnsiString"),j=o((e,t)=>{const s=p(e),i=p(t);return{message:o(()=>{if(e===t)return"ANSI strings are identical";const r=s.stripped===i.stripped;return h(`ANSI string comparison failed:
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Actual:
|
|
4
|
+
- Visible content: %s
|
|
5
|
+
- With escape codes: %s
|
|
6
|
+
- JSON: %s
|
|
7
|
+
- Length: %d
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
Expected:
|
|
10
|
+
- Visible content: %s
|
|
11
|
+
- With escape codes: %s
|
|
12
|
+
- JSON: %s
|
|
13
|
+
- Length: %d
|
|
6
14
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
-
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
-
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
-
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
-
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
// Fallback to createRequire
|
|
17
|
-
return __cjs_require(module);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const {
|
|
21
|
-
format,
|
|
22
|
-
stripVTControlCharacters
|
|
23
|
-
} = __cjs_getBuiltinModule("node:util");
|
|
24
|
-
import { getStringWidth } from '../get-string-width.js';
|
|
25
|
-
|
|
26
|
-
const formatAnsiString = (ansiString) => {
|
|
27
|
-
const stripped = stripVTControlCharacters(ansiString);
|
|
28
|
-
return {
|
|
29
|
-
// Original ANSI string
|
|
30
|
-
ansi: ansiString,
|
|
31
|
-
// JSON stringified version to see all escape codes
|
|
32
|
-
json: JSON.stringify(ansiString),
|
|
33
|
-
// Length difference between ANSI and stripped string
|
|
34
|
-
lengthDifference: ansiString.length - stripped.length,
|
|
35
|
-
// String with ANSI codes stripped
|
|
36
|
-
stripped,
|
|
37
|
-
// String with ANSI escape codes shown as visible characters
|
|
38
|
-
visible: ansiString.replaceAll("\x1B", String.raw`\u001B`)
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
const expectAnsiStrings = (actual, expected) => {
|
|
42
|
-
const actualFormatted = formatAnsiString(actual);
|
|
43
|
-
const expectedFormatted = formatAnsiString(expected);
|
|
44
|
-
return {
|
|
45
|
-
message: () => {
|
|
46
|
-
if (actual === expected) {
|
|
47
|
-
return "ANSI strings are identical";
|
|
48
|
-
}
|
|
49
|
-
const strippedEqual = actualFormatted.stripped === expectedFormatted.stripped;
|
|
50
|
-
return format(
|
|
51
|
-
"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",
|
|
52
|
-
actualFormatted.stripped,
|
|
53
|
-
actualFormatted.visible,
|
|
54
|
-
actualFormatted.json,
|
|
55
|
-
getStringWidth(actualFormatted.ansi),
|
|
56
|
-
expectedFormatted.stripped,
|
|
57
|
-
expectedFormatted.visible,
|
|
58
|
-
expectedFormatted.json,
|
|
59
|
-
getStringWidth(expectedFormatted.ansi),
|
|
60
|
-
strippedEqual ? "✓ Visible content is identical, but escape codes differ" : "✗ Visible content differs"
|
|
61
|
-
);
|
|
62
|
-
},
|
|
63
|
-
pass: actual === expected
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
const compareAnsiStrings = (actual, expected) => {
|
|
67
|
-
const actualFormatted = formatAnsiString(actual);
|
|
68
|
-
const expectedFormatted = formatAnsiString(expected);
|
|
69
|
-
const strippedEqual = actualFormatted.stripped === expectedFormatted.stripped;
|
|
70
|
-
const ansiEqual = actual === expected;
|
|
71
|
-
return {
|
|
72
|
-
// Format information for both strings
|
|
73
|
-
actual: actualFormatted,
|
|
74
|
-
// Are the strings identical including ANSI codes?
|
|
75
|
-
ansiEqual,
|
|
76
|
-
expected: expectedFormatted,
|
|
77
|
-
// Are the strings identical when ANSI codes are stripped?
|
|
78
|
-
strippedEqual,
|
|
79
|
-
// Summary information
|
|
80
|
-
summary: {
|
|
81
|
-
actualLength: actual.length,
|
|
82
|
-
actualStrippedLength: actualFormatted.stripped.length,
|
|
83
|
-
ansiEqual,
|
|
84
|
-
expectedLength: expected.length,
|
|
85
|
-
expectedStrippedLength: expectedFormatted.stripped.length,
|
|
86
|
-
strippedEqual
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export { compareAnsiStrings, expectAnsiStrings, formatAnsiString };
|
|
15
|
+
%s
|
|
16
|
+
`,s.stripped,s.visible,s.json,l(s.ansi),i.stripped,i.visible,i.json,l(i.ansi),r?"✓ Visible content is identical, but escape codes differ":"✗ Visible content differs")},"message"),pass:e===t}},"expectAnsiStrings"),v=o((e,t)=>{const s=p(e),i=p(t),r=s.stripped===i.stripped,c=e===t;return{actual:s,ansiEqual:c,expected:i,strippedEqual:r,summary:{actualLength:e.length,actualStrippedLength:s.stripped.length,ansiEqual:c,expectedLength:t.length,expectedStrippedLength:i.stripped.length,strippedEqual:r}}},"compareAnsiStrings");export{v as compareAnsiStrings,j as expectAnsiStrings,p as formatAnsiString};
|
package/dist/test/vitest.d.ts
CHANGED
|
@@ -2,5 +2,8 @@ import { ExpectationResult } from "./utils.js";
|
|
|
2
2
|
interface CustomMatchers {
|
|
3
3
|
toEqualAnsi: (expected: string) => ExpectationResult;
|
|
4
4
|
}
|
|
5
|
+
/**
|
|
6
|
+
* Extends Vitest expect with ANSI string comparison via expect.extend.
|
|
7
|
+
*/
|
|
5
8
|
declare const toEqualAnsi: (actual: string, expected: string) => ExpectationResult;
|
|
6
9
|
export { CustomMatchers, toEqualAnsi };
|
package/dist/test/vitest.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const toEqualAnsi = (actual, expected) => expectAnsiStrings(actual, expected);
|
|
4
|
-
|
|
5
|
-
export { toEqualAnsi };
|
|
1
|
+
var i=Object.defineProperty;var t=(e,r)=>i(e,"name",{value:r,configurable:!0});import{expectAnsiStrings as n}from"./utils.js";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};
|