@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.
- package/CHANGELOG.md +18 -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
|
@@ -1,763 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
-
|
|
5
|
-
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
-
|
|
7
|
-
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
-
// Check if we're in Node.js and version supports getBuiltinModule
|
|
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
|
-
stripVTControlCharacters
|
|
22
|
-
} = __cjs_getBuiltinModule("node:util");
|
|
23
|
-
import { i as RE_EMOJI, s as stripEmoji, R as RE_FAST_ANSI, l as RE_CYRILLIC, m as RE_LATIN, n as RE_GREEK, o as RE_GREEK_LATIN_SPLIT, p as RE_UZBEK_LATIN_MODIFIER, q as RE_KATAKANA, r as RE_KANJI, t as RE_HIRAGANA, u as RE_HANGUL, v as RE_HEBREW, w as RE_ARABIC, x as RE_SEPARATORS, y as RE_DEVANAGARI, z as RE_BENGALI, A as RE_GUJARATI, B as RE_GURMUKHI, C as RE_KANNADA, D as RE_TAMIL, E as RE_TELUGU, F as RE_MALAYALAM, G as RE_SINHALA, H as RE_THAI, I as RE_LAO, J as RE_TIBETAN, K as RE_MYANMAR, L as RE_ETHIOPIC, M as RE_KHMER, N as RE_ORIYA } from '../packem_shared/constants-BsZS5f0z.js';
|
|
24
|
-
import LRUCache from '../packem_shared/LRUCache-3r3SovvR.js';
|
|
25
|
-
|
|
26
|
-
const regexCache = new LRUCache(1e3);
|
|
27
|
-
const RE_ESCAPE_SPECIAL = /[.*+?^${}()|[\]\\]/g;
|
|
28
|
-
const getSeparatorsRegex = (separators) => {
|
|
29
|
-
const key = separators.join("");
|
|
30
|
-
if (regexCache.has(key)) {
|
|
31
|
-
return regexCache.get(key);
|
|
32
|
-
}
|
|
33
|
-
const pattern = separators.map((s) => s.replaceAll(RE_ESCAPE_SPECIAL, String.raw`\$&`)).join("|");
|
|
34
|
-
const regex = new RegExp(pattern, "g");
|
|
35
|
-
regexCache.set(key, regex);
|
|
36
|
-
return regex;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const splitByEmoji = (text) => {
|
|
40
|
-
const segments = [];
|
|
41
|
-
let lastIndex = 0;
|
|
42
|
-
let match;
|
|
43
|
-
RE_EMOJI.lastIndex = 0;
|
|
44
|
-
while ((match = RE_EMOJI.exec(text)) !== null) {
|
|
45
|
-
if (match.index > lastIndex) {
|
|
46
|
-
segments.push(text.slice(lastIndex, match.index));
|
|
47
|
-
}
|
|
48
|
-
segments.push(match[0]);
|
|
49
|
-
lastIndex = RE_EMOJI.lastIndex;
|
|
50
|
-
}
|
|
51
|
-
if (lastIndex < text.length) {
|
|
52
|
-
segments.push(text.slice(lastIndex));
|
|
53
|
-
}
|
|
54
|
-
return segments.filter(Boolean);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const RE_SLOVENIAN_SPECIAL = /[ČŠŽĐ]/i;
|
|
58
|
-
const isUpperCode = new Uint8Array(128);
|
|
59
|
-
const isLowerCode = new Uint8Array(128);
|
|
60
|
-
const isDigitCode = new Uint8Array(128);
|
|
61
|
-
for (let index = 0; index < 128; index++) {
|
|
62
|
-
isUpperCode[index] = index >= 65 && index <= 90 ? 1 : 0;
|
|
63
|
-
isLowerCode[index] = index >= 97 && index <= 122 ? 1 : 0;
|
|
64
|
-
isDigitCode[index] = index >= 48 && index <= 57 ? 1 : 0;
|
|
65
|
-
}
|
|
66
|
-
const isUpper = (code) => isUpperCode[code];
|
|
67
|
-
const isLower = (code) => isLowerCode[code];
|
|
68
|
-
const isDigit = (code) => isDigitCode[code];
|
|
69
|
-
const handleScriptTransitions = (s, scriptDetectors, caseSensitive, locale, customSplitLogic) => {
|
|
70
|
-
if (s.length === 0) {
|
|
71
|
-
return [];
|
|
72
|
-
}
|
|
73
|
-
let hasDetectedScript = false;
|
|
74
|
-
const detectorValues = Object.values(scriptDetectors);
|
|
75
|
-
for (const detectorValue of detectorValues) {
|
|
76
|
-
if (detectorValue(s[0])) {
|
|
77
|
-
hasDetectedScript = true;
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (!hasDetectedScript && !caseSensitive) {
|
|
82
|
-
return [s];
|
|
83
|
-
}
|
|
84
|
-
const chars = [...s];
|
|
85
|
-
const result = [];
|
|
86
|
-
let currentSegment = chars[0];
|
|
87
|
-
let previousType = "other";
|
|
88
|
-
const scriptEntries = Object.entries(scriptDetectors);
|
|
89
|
-
for (const scriptEntry of scriptEntries) {
|
|
90
|
-
const [type, detector] = scriptEntry;
|
|
91
|
-
if (detector(chars[0])) {
|
|
92
|
-
previousType = type;
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
let previousIsUpper = caseSensitive && locale ? chars[0] === chars[0].toLocaleUpperCase(locale) : false;
|
|
97
|
-
for (let index = 1; index < chars.length; index++) {
|
|
98
|
-
const char = chars[index];
|
|
99
|
-
let currentType = "other";
|
|
100
|
-
for (const scriptEntry of scriptEntries) {
|
|
101
|
-
const [type, detector] = scriptEntry;
|
|
102
|
-
if (detector(char)) {
|
|
103
|
-
currentType = type;
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
const isUpperCaseChar = caseSensitive && locale ? char === char.toLocaleUpperCase(locale) : false;
|
|
108
|
-
let shouldSplit = false;
|
|
109
|
-
if (customSplitLogic) {
|
|
110
|
-
shouldSplit = customSplitLogic(previousType, currentType, previousIsUpper, isUpperCaseChar, char, index, chars);
|
|
111
|
-
} else {
|
|
112
|
-
if (previousType !== currentType && previousType !== "other" && currentType !== "other") {
|
|
113
|
-
shouldSplit = true;
|
|
114
|
-
}
|
|
115
|
-
if (caseSensitive && currentType !== "other" && !previousIsUpper && isUpperCaseChar) {
|
|
116
|
-
shouldSplit = true;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
if (shouldSplit) {
|
|
120
|
-
result.push(currentSegment);
|
|
121
|
-
currentSegment = char;
|
|
122
|
-
} else {
|
|
123
|
-
currentSegment += char;
|
|
124
|
-
}
|
|
125
|
-
previousType = currentType;
|
|
126
|
-
if (caseSensitive) {
|
|
127
|
-
previousIsUpper = isUpperCaseChar;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
if (currentSegment && currentSegment.length > 0) {
|
|
131
|
-
result.push(currentSegment);
|
|
132
|
-
}
|
|
133
|
-
return result.length > 0 ? result : [s];
|
|
134
|
-
};
|
|
135
|
-
const detectAndProcessAcronym = (s, start, knownAcronyms, tokens) => {
|
|
136
|
-
if (knownAcronyms.size === 0) {
|
|
137
|
-
return start;
|
|
138
|
-
}
|
|
139
|
-
for (const acronym of knownAcronyms) {
|
|
140
|
-
if (s.startsWith(acronym, start)) {
|
|
141
|
-
tokens.push(acronym);
|
|
142
|
-
return start + acronym.length;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return start;
|
|
146
|
-
};
|
|
147
|
-
const splitCamelCaseFast = (s, knownAcronyms = /* @__PURE__ */ new Set()) => {
|
|
148
|
-
if (s.length === 0) {
|
|
149
|
-
return [];
|
|
150
|
-
}
|
|
151
|
-
if (s.toUpperCase() === s) {
|
|
152
|
-
return [s];
|
|
153
|
-
}
|
|
154
|
-
let start = 0;
|
|
155
|
-
const tokens = [];
|
|
156
|
-
const width = s.length;
|
|
157
|
-
for (let index = 1; index < width; index++) {
|
|
158
|
-
const newStart = detectAndProcessAcronym(s, start, knownAcronyms, tokens);
|
|
159
|
-
if (newStart !== start) {
|
|
160
|
-
start = newStart;
|
|
161
|
-
index = start - 1;
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
const previousCode = s.codePointAt(index - 1);
|
|
165
|
-
const currentCode = s.codePointAt(index);
|
|
166
|
-
const previousIsUpper = previousCode && previousCode < 128 && isUpper(previousCode);
|
|
167
|
-
const currentIsUpper = currentCode && currentCode < 128 && isUpper(currentCode);
|
|
168
|
-
const previousIsLower = previousCode && previousCode < 128 && isLower(previousCode);
|
|
169
|
-
const previousIsDigit = previousCode && previousCode < 128 && isDigit(previousCode);
|
|
170
|
-
const currentIsDigit = currentCode && currentCode < 128 && isDigit(currentCode);
|
|
171
|
-
if (previousIsLower && currentIsUpper) {
|
|
172
|
-
tokens.push(s.slice(start, index));
|
|
173
|
-
start = index;
|
|
174
|
-
continue;
|
|
175
|
-
}
|
|
176
|
-
if (previousIsDigit && !currentIsDigit || !previousIsDigit && currentIsDigit) {
|
|
177
|
-
tokens.push(s.slice(start, index));
|
|
178
|
-
start = index;
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
if (currentIsDigit && !previousIsDigit) {
|
|
182
|
-
let isNextUpper = false;
|
|
183
|
-
let isNextDigit = false;
|
|
184
|
-
if (index + 1 < width) {
|
|
185
|
-
const nextCode = s.codePointAt(index + 1);
|
|
186
|
-
isNextUpper = nextCode && nextCode < 128 && isUpper(nextCode);
|
|
187
|
-
isNextDigit = nextCode && nextCode < 128 && isDigit(nextCode);
|
|
188
|
-
}
|
|
189
|
-
if (!isNextDigit && isNextUpper) {
|
|
190
|
-
tokens.push(s.slice(start, index), s.slice(index, index + 1));
|
|
191
|
-
start = index + 1;
|
|
192
|
-
continue;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
if (index + 1 < width) {
|
|
196
|
-
const nextCode = s.codePointAt(index + 1);
|
|
197
|
-
const nextIsLower = nextCode && nextCode < 128 && isLower(nextCode);
|
|
198
|
-
if (previousIsUpper && currentIsUpper && nextIsLower) {
|
|
199
|
-
const candidate = s.slice(start, index + 1);
|
|
200
|
-
if (!knownAcronyms.has(candidate)) {
|
|
201
|
-
tokens.push(s.slice(start, index));
|
|
202
|
-
start = index;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
if (start < width) {
|
|
208
|
-
tokens.push(s.slice(start));
|
|
209
|
-
}
|
|
210
|
-
return tokens.filter((token) => token !== "");
|
|
211
|
-
};
|
|
212
|
-
const splitCamelCaseLocale = (s, locale, knownAcronyms) => {
|
|
213
|
-
if (s.length === 0) {
|
|
214
|
-
return [];
|
|
215
|
-
}
|
|
216
|
-
const isUpperCase = s === s.toLocaleUpperCase(locale);
|
|
217
|
-
if (locale.startsWith("de")) {
|
|
218
|
-
if (!isUpperCase && s.replaceAll("ß", "SS") === s.toLocaleUpperCase(locale)) {
|
|
219
|
-
return [s];
|
|
220
|
-
}
|
|
221
|
-
const chars2 = [...s];
|
|
222
|
-
const width_2 = chars2.length;
|
|
223
|
-
const result2 = [];
|
|
224
|
-
let currentSegment2 = chars2[0];
|
|
225
|
-
let previousIsUpper2 = chars2[0] === chars2[0].toLocaleUpperCase(locale);
|
|
226
|
-
let isInUpperSequence = previousIsUpper2;
|
|
227
|
-
let upperSequenceStart = previousIsUpper2 ? 0 : -1;
|
|
228
|
-
for (let index = 1; index < width_2; index++) {
|
|
229
|
-
const char = chars2[index];
|
|
230
|
-
const isUpperCaseChar = char === char.toLocaleUpperCase(locale);
|
|
231
|
-
if (isUpperCaseChar === previousIsUpper2) {
|
|
232
|
-
currentSegment2 += char;
|
|
233
|
-
} else if (isUpperCaseChar) {
|
|
234
|
-
if (currentSegment2 && currentSegment2.length > 0) {
|
|
235
|
-
result2.push(currentSegment2);
|
|
236
|
-
currentSegment2 = char;
|
|
237
|
-
}
|
|
238
|
-
isInUpperSequence = true;
|
|
239
|
-
upperSequenceStart = index;
|
|
240
|
-
} else {
|
|
241
|
-
if (isInUpperSequence && index - upperSequenceStart > 1) {
|
|
242
|
-
const lastUpperChar = chars2[index - 1];
|
|
243
|
-
const withoutLastUpper = currentSegment2.slice(0, -1);
|
|
244
|
-
if (withoutLastUpper && withoutLastUpper.length > 0) {
|
|
245
|
-
result2.push(withoutLastUpper);
|
|
246
|
-
}
|
|
247
|
-
currentSegment2 = lastUpperChar + char;
|
|
248
|
-
} else {
|
|
249
|
-
currentSegment2 += char;
|
|
250
|
-
}
|
|
251
|
-
isInUpperSequence = false;
|
|
252
|
-
upperSequenceStart = -1;
|
|
253
|
-
}
|
|
254
|
-
previousIsUpper2 = isUpperCaseChar;
|
|
255
|
-
}
|
|
256
|
-
if (currentSegment2 && currentSegment2.length > 0) {
|
|
257
|
-
result2.push(currentSegment2);
|
|
258
|
-
}
|
|
259
|
-
return result2;
|
|
260
|
-
}
|
|
261
|
-
if (locale.startsWith("uk") || locale.startsWith("ru") || locale.startsWith("bg") || locale.startsWith("sr") || locale.startsWith("mk") || locale.startsWith("be")) {
|
|
262
|
-
if (!RE_CYRILLIC.test(s) && !RE_LATIN.test(s)) {
|
|
263
|
-
return [s];
|
|
264
|
-
}
|
|
265
|
-
const chars2 = [...s];
|
|
266
|
-
const width_2 = chars2.length;
|
|
267
|
-
const result2 = [];
|
|
268
|
-
let currentSegment2 = chars2[0];
|
|
269
|
-
const firstChar = chars2[0];
|
|
270
|
-
let previousType;
|
|
271
|
-
if (RE_CYRILLIC.test(firstChar)) {
|
|
272
|
-
previousType = 1;
|
|
273
|
-
} else if (RE_LATIN.test(firstChar)) {
|
|
274
|
-
previousType = 2;
|
|
275
|
-
} else {
|
|
276
|
-
previousType = 0;
|
|
277
|
-
}
|
|
278
|
-
let previousIsUpper2 = firstChar === firstChar.toLocaleUpperCase(locale);
|
|
279
|
-
for (let index = 1; index < width_2; index++) {
|
|
280
|
-
const char = chars2[index];
|
|
281
|
-
let currentType;
|
|
282
|
-
if (RE_CYRILLIC.test(char)) {
|
|
283
|
-
currentType = 1;
|
|
284
|
-
} else if (RE_LATIN.test(char)) {
|
|
285
|
-
currentType = 2;
|
|
286
|
-
} else {
|
|
287
|
-
currentType = 0;
|
|
288
|
-
}
|
|
289
|
-
const isUpperCaseChar = char === char.toLocaleUpperCase(locale);
|
|
290
|
-
if (previousType !== currentType && (previousType === 1 || previousType === 2) && (currentType === 1 || currentType === 2) || currentType === previousType && !previousIsUpper2 && isUpperCaseChar) {
|
|
291
|
-
result2.push(currentSegment2);
|
|
292
|
-
currentSegment2 = char;
|
|
293
|
-
} else {
|
|
294
|
-
currentSegment2 += char;
|
|
295
|
-
}
|
|
296
|
-
previousType = currentType;
|
|
297
|
-
previousIsUpper2 = isUpperCaseChar;
|
|
298
|
-
}
|
|
299
|
-
if (currentSegment2 && currentSegment2.length > 0) {
|
|
300
|
-
result2.push(currentSegment2);
|
|
301
|
-
}
|
|
302
|
-
const finalResult = [];
|
|
303
|
-
for (let index = 0; index < result2.length; index++) {
|
|
304
|
-
if (index < result2.length - 1 && result2[index].length === 1 && RE_LATIN.test(result2[index]) && RE_CYRILLIC.test(result2[index + 1][0])) {
|
|
305
|
-
finalResult.push(result2[index] + result2[index + 1]);
|
|
306
|
-
index += 1;
|
|
307
|
-
} else {
|
|
308
|
-
finalResult.push(result2[index]);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
return finalResult;
|
|
312
|
-
}
|
|
313
|
-
if (locale.startsWith("el")) {
|
|
314
|
-
if (!RE_GREEK.test(s) && !RE_LATIN.test(s)) {
|
|
315
|
-
return [s];
|
|
316
|
-
}
|
|
317
|
-
const parts = [];
|
|
318
|
-
RE_GREEK_LATIN_SPLIT.lastIndex = 0;
|
|
319
|
-
let greekExecMatch;
|
|
320
|
-
while ((greekExecMatch = RE_GREEK_LATIN_SPLIT.exec(s)) !== null) {
|
|
321
|
-
parts.push(greekExecMatch[0]);
|
|
322
|
-
}
|
|
323
|
-
if (parts.length === 0) {
|
|
324
|
-
parts.push(s);
|
|
325
|
-
}
|
|
326
|
-
const result2 = [];
|
|
327
|
-
const width = parts.length;
|
|
328
|
-
if (width === 1) {
|
|
329
|
-
const part = parts[0];
|
|
330
|
-
if (!part || !RE_GREEK.test(part[0]) || part.length === 1) {
|
|
331
|
-
return [part ?? s];
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
for (const greekPart of parts) {
|
|
335
|
-
if (!greekPart) {
|
|
336
|
-
continue;
|
|
337
|
-
}
|
|
338
|
-
if (!RE_GREEK.test(greekPart[0]) || greekPart.length === 1) {
|
|
339
|
-
result2.push(greekPart);
|
|
340
|
-
continue;
|
|
341
|
-
}
|
|
342
|
-
const partLength = greekPart.length;
|
|
343
|
-
let word = greekPart[0];
|
|
344
|
-
let previousIsUpper2 = greekPart[0] === greekPart[0].toLocaleUpperCase(locale);
|
|
345
|
-
for (let index = 1; index < partLength; index++) {
|
|
346
|
-
const char = greekPart[index];
|
|
347
|
-
const isUpperCaseChar = char === char.toLocaleUpperCase(locale);
|
|
348
|
-
if (!previousIsUpper2 && isUpperCaseChar) {
|
|
349
|
-
result2.push(word);
|
|
350
|
-
word = char;
|
|
351
|
-
} else {
|
|
352
|
-
word += char;
|
|
353
|
-
}
|
|
354
|
-
previousIsUpper2 = isUpperCaseChar;
|
|
355
|
-
}
|
|
356
|
-
if (word) {
|
|
357
|
-
result2.push(word);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
return result2;
|
|
361
|
-
}
|
|
362
|
-
if (locale.startsWith("ja") || locale.startsWith("ko")) {
|
|
363
|
-
const isJapanese = locale.startsWith("ja");
|
|
364
|
-
const scriptDetectors = isJapanese ? {
|
|
365
|
-
hiragana: (char) => RE_HIRAGANA.test(char),
|
|
366
|
-
kanji: (char) => RE_KANJI.test(char),
|
|
367
|
-
katakana: (char) => RE_KATAKANA.test(char),
|
|
368
|
-
latin: (char) => RE_LATIN.test(char)
|
|
369
|
-
} : {
|
|
370
|
-
hangul: (char) => RE_HANGUL.test(char),
|
|
371
|
-
latin: (char) => RE_LATIN.test(char)
|
|
372
|
-
};
|
|
373
|
-
const particles = /* @__PURE__ */ new Set(["が", "で", "と", "に", "の", "は", "へ", "も", "や", "を"]);
|
|
374
|
-
if (isJapanese) {
|
|
375
|
-
const baseSegments = handleScriptTransitions(
|
|
376
|
-
s,
|
|
377
|
-
scriptDetectors,
|
|
378
|
-
false,
|
|
379
|
-
locale,
|
|
380
|
-
(previousType, currentType) => previousType === "hiragana" && currentType === "katakana" || previousType === "katakana" && currentType === "hiragana" || previousType === "hiragana" && currentType === "latin" || previousType === "katakana" && currentType === "latin" || previousType === "kanji" && currentType === "latin" || previousType === "latin" && (currentType === "hiragana" || currentType === "katakana" || currentType === "kanji")
|
|
381
|
-
// latin -> japanese
|
|
382
|
-
);
|
|
383
|
-
const result2 = [];
|
|
384
|
-
for (const baseSegment of baseSegments) {
|
|
385
|
-
const segment = baseSegment;
|
|
386
|
-
if (segment.length === 1 && particles.has(segment) && result2.length > 0) {
|
|
387
|
-
result2[result2.length - 1] = result2.at(-1) + segment;
|
|
388
|
-
} else {
|
|
389
|
-
result2.push(segment);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
return result2.length > 0 ? result2 : [s];
|
|
393
|
-
}
|
|
394
|
-
return handleScriptTransitions(
|
|
395
|
-
s,
|
|
396
|
-
scriptDetectors,
|
|
397
|
-
false,
|
|
398
|
-
locale,
|
|
399
|
-
(previousType, currentType) => previousType === "hangul" && currentType === "latin" || previousType === "latin" && currentType === "hangul"
|
|
400
|
-
// latin -> hangul
|
|
401
|
-
);
|
|
402
|
-
}
|
|
403
|
-
if (locale.startsWith("sl")) {
|
|
404
|
-
const chars2 = [...s];
|
|
405
|
-
const width_2 = chars2.length;
|
|
406
|
-
const result2 = [];
|
|
407
|
-
let currentSegment2 = chars2[0];
|
|
408
|
-
let previousIsUpper2 = chars2[0] === chars2[0].toLocaleUpperCase(locale);
|
|
409
|
-
for (let index = 1; index < width_2; index++) {
|
|
410
|
-
const char = chars2[index];
|
|
411
|
-
const isUpperCaseChar = char === char.toLocaleUpperCase(locale);
|
|
412
|
-
const isSpecialChar = RE_SLOVENIAN_SPECIAL.test(char);
|
|
413
|
-
const nextIsUpper = index < width_2 - 1 && chars2[index + 1] === chars2[index + 1].toLocaleUpperCase(locale);
|
|
414
|
-
if (!previousIsUpper2 && isUpperCaseChar || isSpecialChar && nextIsUpper) {
|
|
415
|
-
result2.push(currentSegment2);
|
|
416
|
-
currentSegment2 = char;
|
|
417
|
-
if (isSpecialChar && nextIsUpper) {
|
|
418
|
-
result2.push(currentSegment2);
|
|
419
|
-
currentSegment2 = "";
|
|
420
|
-
}
|
|
421
|
-
} else {
|
|
422
|
-
currentSegment2 += char;
|
|
423
|
-
}
|
|
424
|
-
previousIsUpper2 = isUpperCaseChar;
|
|
425
|
-
}
|
|
426
|
-
if (currentSegment2 && currentSegment2.length > 0) {
|
|
427
|
-
result2.push(currentSegment2);
|
|
428
|
-
}
|
|
429
|
-
return result2;
|
|
430
|
-
}
|
|
431
|
-
if (locale.startsWith("zh")) {
|
|
432
|
-
return handleScriptTransitions(
|
|
433
|
-
s,
|
|
434
|
-
{
|
|
435
|
-
han: (char) => RE_KANJI.test(char),
|
|
436
|
-
latin: (char) => RE_LATIN.test(char)
|
|
437
|
-
},
|
|
438
|
-
false,
|
|
439
|
-
locale
|
|
440
|
-
);
|
|
441
|
-
}
|
|
442
|
-
if (["ar", "fa", "he", "ur"].includes(locale.split("-")[0])) {
|
|
443
|
-
const isRtlChar = (ch) => RE_HEBREW.test(ch) || RE_ARABIC.test(ch);
|
|
444
|
-
return handleScriptTransitions(
|
|
445
|
-
s,
|
|
446
|
-
{
|
|
447
|
-
latin: (char) => RE_LATIN.test(char),
|
|
448
|
-
rtl: (char) => isRtlChar(char)
|
|
449
|
-
},
|
|
450
|
-
false,
|
|
451
|
-
locale
|
|
452
|
-
);
|
|
453
|
-
}
|
|
454
|
-
if ([
|
|
455
|
-
"am",
|
|
456
|
-
// Amharic
|
|
457
|
-
"bn",
|
|
458
|
-
// Bengali
|
|
459
|
-
"gu",
|
|
460
|
-
// Gujarati
|
|
461
|
-
"hi",
|
|
462
|
-
// Hindi
|
|
463
|
-
"km",
|
|
464
|
-
// Khmer
|
|
465
|
-
"kn",
|
|
466
|
-
// Kannada
|
|
467
|
-
"lo",
|
|
468
|
-
// Lao
|
|
469
|
-
"ml",
|
|
470
|
-
// Malayalam
|
|
471
|
-
"mr",
|
|
472
|
-
// Marathi
|
|
473
|
-
"ne",
|
|
474
|
-
// Nepali
|
|
475
|
-
"or",
|
|
476
|
-
// Oriya
|
|
477
|
-
"pa",
|
|
478
|
-
// Punjabi
|
|
479
|
-
"si",
|
|
480
|
-
// Sinhala
|
|
481
|
-
"ta",
|
|
482
|
-
// Tamil
|
|
483
|
-
"te",
|
|
484
|
-
// Telugu
|
|
485
|
-
"th"
|
|
486
|
-
// Thai
|
|
487
|
-
].includes(locale.split("-")[0])) {
|
|
488
|
-
const isIndicChar = (ch) => RE_DEVANAGARI.test(ch) || RE_BENGALI.test(ch) || RE_GUJARATI.test(ch) || RE_GURMUKHI.test(ch) || RE_KANNADA.test(ch) || RE_TAMIL.test(ch) || RE_TELUGU.test(ch) || RE_MALAYALAM.test(ch) || RE_SINHALA.test(ch) || RE_THAI.test(ch) || RE_LAO.test(ch) || RE_TIBETAN.test(ch) || RE_MYANMAR.test(ch) || RE_ETHIOPIC.test(ch) || RE_KHMER.test(ch) || RE_ORIYA.test(ch);
|
|
489
|
-
return handleScriptTransitions(
|
|
490
|
-
s,
|
|
491
|
-
{
|
|
492
|
-
indic: (char) => isIndicChar(char),
|
|
493
|
-
latin: (char) => RE_LATIN.test(char)
|
|
494
|
-
},
|
|
495
|
-
false,
|
|
496
|
-
locale
|
|
497
|
-
);
|
|
498
|
-
}
|
|
499
|
-
if (["be", "bg", "ru", "sr", "uk"].includes(locale)) {
|
|
500
|
-
return handleScriptTransitions(
|
|
501
|
-
s,
|
|
502
|
-
{
|
|
503
|
-
cyrillic: (char) => RE_CYRILLIC.test(char),
|
|
504
|
-
latin: (char) => RE_LATIN.test(char)
|
|
505
|
-
},
|
|
506
|
-
true,
|
|
507
|
-
// Enable case-sensitive splitting
|
|
508
|
-
locale
|
|
509
|
-
);
|
|
510
|
-
}
|
|
511
|
-
if (["ar", "fa", "he"].includes(locale)) {
|
|
512
|
-
return handleScriptTransitions(
|
|
513
|
-
s,
|
|
514
|
-
{
|
|
515
|
-
latin: (char) => RE_LATIN.test(char),
|
|
516
|
-
rtl: (char) => RE_HEBREW.test(char) || RE_ARABIC.test(char)
|
|
517
|
-
},
|
|
518
|
-
false,
|
|
519
|
-
locale
|
|
520
|
-
);
|
|
521
|
-
}
|
|
522
|
-
if (locale.startsWith("ko")) {
|
|
523
|
-
return handleScriptTransitions(
|
|
524
|
-
s,
|
|
525
|
-
{
|
|
526
|
-
hangul: (char) => RE_HANGUL.test(char),
|
|
527
|
-
latin: (char) => RE_LATIN.test(char)
|
|
528
|
-
},
|
|
529
|
-
false,
|
|
530
|
-
locale
|
|
531
|
-
);
|
|
532
|
-
}
|
|
533
|
-
if (locale.startsWith("uz")) {
|
|
534
|
-
if (!RE_CYRILLIC.test(s) && !RE_LATIN.test(s)) {
|
|
535
|
-
return [s];
|
|
536
|
-
}
|
|
537
|
-
const chars2 = [...s];
|
|
538
|
-
const width_2 = chars2.length;
|
|
539
|
-
const result2 = [];
|
|
540
|
-
let currentSegment2 = chars2[0];
|
|
541
|
-
let previousIsUpper2 = chars2[0] === chars2[0].toLocaleUpperCase(locale);
|
|
542
|
-
for (let index = 1; index < width_2; index++) {
|
|
543
|
-
const char = chars2[index];
|
|
544
|
-
const isUpperCaseChar = char === char.toLocaleUpperCase(locale);
|
|
545
|
-
if (RE_UZBEK_LATIN_MODIFIER.test(char) || RE_UZBEK_LATIN_MODIFIER.test(chars2[index - 1])) {
|
|
546
|
-
currentSegment2 += char;
|
|
547
|
-
continue;
|
|
548
|
-
}
|
|
549
|
-
if (!previousIsUpper2 && isUpperCaseChar) {
|
|
550
|
-
result2.push(currentSegment2);
|
|
551
|
-
currentSegment2 = char;
|
|
552
|
-
} else {
|
|
553
|
-
currentSegment2 += char;
|
|
554
|
-
}
|
|
555
|
-
previousIsUpper2 = isUpperCaseChar;
|
|
556
|
-
}
|
|
557
|
-
if (currentSegment2 && currentSegment2.length > 0) {
|
|
558
|
-
result2.push(currentSegment2);
|
|
559
|
-
}
|
|
560
|
-
return result2;
|
|
561
|
-
}
|
|
562
|
-
const chars = [...s];
|
|
563
|
-
const width_ = chars.length;
|
|
564
|
-
const result = [];
|
|
565
|
-
let currentSegment = chars[0];
|
|
566
|
-
let previousIsUpper = chars[0] === chars[0].toLocaleUpperCase(locale);
|
|
567
|
-
for (const acronym of knownAcronyms) {
|
|
568
|
-
if (s.startsWith(acronym)) {
|
|
569
|
-
result.push(acronym);
|
|
570
|
-
currentSegment = chars[acronym.length];
|
|
571
|
-
previousIsUpper = currentSegment === currentSegment.toLocaleUpperCase(locale);
|
|
572
|
-
break;
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
for (let index = 1; index < width_; index++) {
|
|
576
|
-
const char = chars[index];
|
|
577
|
-
const isUpperCaseChar = char === char.toLocaleUpperCase(locale);
|
|
578
|
-
let acronymLength = 0;
|
|
579
|
-
for (const acronym of knownAcronyms) {
|
|
580
|
-
if (s.startsWith(acronym, index)) {
|
|
581
|
-
result.push(currentSegment, acronym);
|
|
582
|
-
acronymLength = acronym.length;
|
|
583
|
-
currentSegment = "";
|
|
584
|
-
const lastAcronymChar = acronym.at(-1);
|
|
585
|
-
if (lastAcronymChar) {
|
|
586
|
-
previousIsUpper = lastAcronymChar === lastAcronymChar.toLocaleUpperCase(locale);
|
|
587
|
-
}
|
|
588
|
-
break;
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
if (acronymLength > 0) {
|
|
592
|
-
index += acronymLength - 1;
|
|
593
|
-
continue;
|
|
594
|
-
}
|
|
595
|
-
if (!previousIsUpper && isUpperCaseChar) {
|
|
596
|
-
result.push(currentSegment);
|
|
597
|
-
currentSegment = char;
|
|
598
|
-
} else {
|
|
599
|
-
currentSegment += char;
|
|
600
|
-
}
|
|
601
|
-
previousIsUpper = isUpperCaseChar;
|
|
602
|
-
}
|
|
603
|
-
if (currentSegment) {
|
|
604
|
-
result.push(currentSegment);
|
|
605
|
-
}
|
|
606
|
-
return result;
|
|
607
|
-
};
|
|
608
|
-
const processTextWithAnsiEmoji = (text, locale, knownAcronyms) => {
|
|
609
|
-
const result = [];
|
|
610
|
-
const segments = RE_FAST_ANSI.test(text) ? text.split(RE_FAST_ANSI).filter(Boolean) : [text];
|
|
611
|
-
for (const segment of segments) {
|
|
612
|
-
const seg = segment;
|
|
613
|
-
if (RE_FAST_ANSI.test(seg)) {
|
|
614
|
-
result.push(seg);
|
|
615
|
-
} else {
|
|
616
|
-
const subs = RE_EMOJI.test(seg) ? splitByEmoji(seg).filter(Boolean) : [seg];
|
|
617
|
-
for (const emojiSub of subs) {
|
|
618
|
-
if (RE_EMOJI.test(emojiSub)) {
|
|
619
|
-
result.push(emojiSub);
|
|
620
|
-
} else {
|
|
621
|
-
if (locale) {
|
|
622
|
-
const normalizedLocale = locale.toLowerCase().split("-")[0];
|
|
623
|
-
result.push(...splitCamelCaseLocale(emojiSub, normalizedLocale, knownAcronyms));
|
|
624
|
-
} else {
|
|
625
|
-
result.push(...splitCamelCaseFast(emojiSub, knownAcronyms));
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
return result;
|
|
632
|
-
};
|
|
633
|
-
const splitByCase = (input, options = {}) => {
|
|
634
|
-
if (!input || typeof input !== "string") {
|
|
635
|
-
return [];
|
|
636
|
-
}
|
|
637
|
-
const {
|
|
638
|
-
handleAnsi = false,
|
|
639
|
-
handleEmoji = false,
|
|
640
|
-
knownAcronyms = [],
|
|
641
|
-
locale,
|
|
642
|
-
normalize = false,
|
|
643
|
-
separators,
|
|
644
|
-
stripAnsi: stripAnsiOption = false,
|
|
645
|
-
stripEmoji: stripEmojiOption = false
|
|
646
|
-
} = options;
|
|
647
|
-
const acronymSet = new Set([...knownAcronyms].toSorted((a, b) => b.length - a.length));
|
|
648
|
-
let cleanedInput = input;
|
|
649
|
-
if (stripAnsiOption) {
|
|
650
|
-
cleanedInput = stripVTControlCharacters(cleanedInput);
|
|
651
|
-
}
|
|
652
|
-
if (stripEmojiOption) {
|
|
653
|
-
cleanedInput = stripEmoji(cleanedInput);
|
|
654
|
-
}
|
|
655
|
-
let separatorRegex;
|
|
656
|
-
if (Array.isArray(separators)) {
|
|
657
|
-
separatorRegex = getSeparatorsRegex(separators);
|
|
658
|
-
} else if (separators instanceof RegExp) {
|
|
659
|
-
separatorRegex = separators;
|
|
660
|
-
} else {
|
|
661
|
-
separatorRegex = RE_SEPARATORS;
|
|
662
|
-
}
|
|
663
|
-
const parts = [];
|
|
664
|
-
let workingInput = cleanedInput;
|
|
665
|
-
const regex = separatorRegex.flags.includes("g") ? separatorRegex : new RegExp(separatorRegex.source, `${separatorRegex.flags}g`);
|
|
666
|
-
while (workingInput.length > 0) {
|
|
667
|
-
const match = regex.exec(workingInput);
|
|
668
|
-
if (!match) {
|
|
669
|
-
if (workingInput === "..") {
|
|
670
|
-
parts.push("..");
|
|
671
|
-
} else if (workingInput === ".") {
|
|
672
|
-
parts.push(".");
|
|
673
|
-
} else if (workingInput.length > 0) {
|
|
674
|
-
parts.push(workingInput);
|
|
675
|
-
}
|
|
676
|
-
break;
|
|
677
|
-
}
|
|
678
|
-
const matchIndex = match.index;
|
|
679
|
-
const matchText = match[0];
|
|
680
|
-
const matchLength = matchText.length;
|
|
681
|
-
const beforeMatch = workingInput.slice(0, matchIndex);
|
|
682
|
-
const afterMatch = workingInput.slice(matchIndex + matchLength);
|
|
683
|
-
if (matchText.startsWith("../")) {
|
|
684
|
-
parts.push("..");
|
|
685
|
-
workingInput = workingInput.slice(matchIndex + 3);
|
|
686
|
-
} else if (matchText.startsWith("./")) {
|
|
687
|
-
parts.push(".");
|
|
688
|
-
workingInput = workingInput.slice(matchIndex + 2);
|
|
689
|
-
} else if (matchIndex === 0 && matchText === "..") {
|
|
690
|
-
parts.push("..");
|
|
691
|
-
workingInput = workingInput.slice(2);
|
|
692
|
-
} else if (matchIndex === 0 && matchText === ".") {
|
|
693
|
-
parts.push(".");
|
|
694
|
-
workingInput = workingInput.slice(1);
|
|
695
|
-
} else {
|
|
696
|
-
if (beforeMatch.length > 0) {
|
|
697
|
-
parts.push(beforeMatch);
|
|
698
|
-
}
|
|
699
|
-
let pos = 0;
|
|
700
|
-
while ((pos = matchText.indexOf("../", pos)) !== -1) {
|
|
701
|
-
parts.push("..");
|
|
702
|
-
pos += 3;
|
|
703
|
-
}
|
|
704
|
-
pos = 0;
|
|
705
|
-
while ((pos = matchText.indexOf("./", pos)) !== -1) {
|
|
706
|
-
if (pos === 0 || matchText[pos - 1] !== ".") {
|
|
707
|
-
parts.push(".");
|
|
708
|
-
}
|
|
709
|
-
pos += 2;
|
|
710
|
-
}
|
|
711
|
-
let remainingAfterMatch = afterMatch;
|
|
712
|
-
while (remainingAfterMatch.startsWith("../")) {
|
|
713
|
-
parts.push("..");
|
|
714
|
-
remainingAfterMatch = remainingAfterMatch.slice(3);
|
|
715
|
-
}
|
|
716
|
-
while (remainingAfterMatch.startsWith("./")) {
|
|
717
|
-
parts.push(".");
|
|
718
|
-
remainingAfterMatch = remainingAfterMatch.slice(2);
|
|
719
|
-
}
|
|
720
|
-
if (remainingAfterMatch === "..") {
|
|
721
|
-
parts.push("..");
|
|
722
|
-
break;
|
|
723
|
-
} else if (remainingAfterMatch === ".") {
|
|
724
|
-
parts.push(".");
|
|
725
|
-
break;
|
|
726
|
-
} else {
|
|
727
|
-
workingInput = remainingAfterMatch;
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
regex.lastIndex = 0;
|
|
731
|
-
}
|
|
732
|
-
if (parts.length === 0) {
|
|
733
|
-
const standardParts = cleanedInput.split(separatorRegex).filter(Boolean);
|
|
734
|
-
parts.push(...standardParts);
|
|
735
|
-
}
|
|
736
|
-
let tokens = [];
|
|
737
|
-
for (const splitPart of parts) {
|
|
738
|
-
if (handleAnsi || handleEmoji) {
|
|
739
|
-
tokens.push(...processTextWithAnsiEmoji(splitPart, locale, acronymSet));
|
|
740
|
-
} else if (locale) {
|
|
741
|
-
tokens.push(...splitCamelCaseLocale(splitPart, locale, acronymSet));
|
|
742
|
-
} else {
|
|
743
|
-
tokens.push(...splitCamelCaseFast(splitPart, acronymSet));
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
if (normalize) {
|
|
747
|
-
tokens = tokens.map((token) => {
|
|
748
|
-
if (acronymSet.has(token)) {
|
|
749
|
-
return token;
|
|
750
|
-
}
|
|
751
|
-
if (locale && token === token.toLocaleUpperCase(locale)) {
|
|
752
|
-
return token[0] + token.slice(1).toLocaleLowerCase(locale);
|
|
753
|
-
}
|
|
754
|
-
if (token.toUpperCase() === token && !acronymSet.has(token)) {
|
|
755
|
-
return token.slice(0, 1) + token.slice(1).toLowerCase();
|
|
756
|
-
}
|
|
757
|
-
return token;
|
|
758
|
-
});
|
|
759
|
-
}
|
|
760
|
-
return tokens;
|
|
761
|
-
};
|
|
762
|
-
|
|
763
|
-
export { splitByCase };
|
|
1
|
+
var $=Object.defineProperty;var W=(e,s)=>$(e,"name",{value:s,configurable:!0});import{createRequire as V}from"node:module";import{i as y,s as ee,l as te,R as x,m as b,n as C,o as T,p as S,q as se,r as O,t as ne,u as M,v as P,w as G,x as re,y as ae,z as le,A as oe,B as ie,C as ce,D as he,E as pe,F as ue,G as fe,H as ge,I as Ae,J as Ee,K as Re,L as _e,M as de,N as K}from"../packem_shared/constants-DmzZF6_u.js";import Le from"../packem_shared/LRUCache-Bjo6gsbC.js";const Z=V(import.meta.url),j=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,Q=W(e=>{if(typeof j<"u"&&j.versions&&j.versions.node){const[s,h]=j.versions.node.split(".").map(Number);if(s>22||s===22&&h>=3||s===20&&h>=16)return j.getBuiltinModule(e)}return Z(e)},"__cjs_getBuiltinModule"),{stripVTControlCharacters:X}=Q("node:util");var Ce=Object.defineProperty,me=W((e,s)=>Ce(e,"name",{value:s,configurable:!0}),"g");const N=new Le(1e3),Ue=/[.*+?^${}()|[\]\\]/g,ke=me(e=>{const s=e.join("");if(N.has(s))return N.get(s);const h=e.map(R=>R.replaceAll(Ue,String.raw`\$&`)).join("|"),g=new RegExp(h,"g");return N.set(s,g),g},"getSeparatorsRegex");var Ie=Object.defineProperty,be=W((e,s)=>Ie(e,"name",{value:s,configurable:!0}),"t");const We=be(e=>{const s=[];let h=0,g;for(y.lastIndex=0;(g=y.exec(e))!==null;)g.index>h&&s.push(e.slice(h,g.index)),s.push(g[0]),h=y.lastIndex;return h<e.length&&s.push(e.slice(h)),s.filter(Boolean)},"splitByEmoji");var je=Object.defineProperty,A=W((e,s)=>je(e,"name",{value:s,configurable:!0}),"u");const ye=/[ČŠŽĐ]/i,z=new Uint8Array(128),D=new Uint8Array(128),J=new Uint8Array(128);for(let e=0;e<128;e++)z[e]=e>=65&&e<=90?1:0,D[e]=e>=97&&e<=122?1:0,J[e]=e>=48&&e<=57?1:0;const w=A(e=>z[e],"isUpper"),H=A(e=>D[e],"isLower"),v=A(e=>J[e],"isDigit"),I=A((e,s,h,g,R)=>{if(e.length===0)return[];let u=!1;const L=Object.values(s);for(const a of L)if(a(e[0])){u=!0;break}if(!u&&!h)return[e];const f=[...e],_=[];let n=f[0],l="other";const c=Object.entries(s);for(const a of c){const[r,i]=a;if(i(f[0])){l=r;break}}let t=h&&g?f[0]===f[0].toLocaleUpperCase(g):!1;for(let a=1;a<f.length;a++){const r=f[a];let i="other";for(const E of c){const[d,m]=E;if(m(r)){i=d;break}}const p=h&&g?r===r.toLocaleUpperCase(g):!1;let o=!1;R?o=R(l,i,t,p,r,a,f):(l!==i&&l!=="other"&&i!=="other"&&(o=!0),h&&i!=="other"&&!t&&p&&(o=!0)),o?(_.push(n),n=r):n+=r,l=i,h&&(t=p)}return n&&n.length>0&&_.push(n),_.length>0?_:[e]},"handleScriptTransitions"),xe=A((e,s,h,g)=>{if(h.size===0)return s;for(const R of h)if(e.startsWith(R,s))return g.push(R),s+R.length;return s},"detectAndProcessAcronym"),q=A((e,s=new Set)=>{if(e.length===0)return[];if(e.toUpperCase()===e)return[e];let h=0;const g=[],R=e.length;for(let u=1;u<R;u++){const L=xe(e,h,s,g);if(L!==h){h=L,u=h-1;continue}const f=e.codePointAt(u-1),_=e.codePointAt(u),n=f&&f<128&&w(f),l=_&&_<128&&w(_),c=f&&f<128&&H(f),t=f&&f<128&&v(f),a=_&&_<128&&v(_);if(c&&l){g.push(e.slice(h,u)),h=u;continue}if(t&&!a||!t&&a){g.push(e.slice(h,u)),h=u;continue}if(a&&!t){let r=!1,i=!1;if(u+1<R){const p=e.codePointAt(u+1);r=p&&p<128&&w(p),i=p&&p<128&&v(p)}if(!i&&r){g.push(e.slice(h,u),e.slice(u,u+1)),h=u+1;continue}}if(u+1<R){const r=e.codePointAt(u+1),i=r&&r<128&&H(r);if(n&&l&&i){const p=e.slice(h,u+1);s.has(p)||(g.push(e.slice(h,u)),h=u)}}}return h<R&&g.push(e.slice(h)),g.filter(u=>u!=="")},"splitCamelCaseFast"),F=A((e,s,h)=>{if(e.length===0)return[];const g=e===e.toLocaleUpperCase(s);if(s.startsWith("de")){if(!g&&e.replaceAll("ß","SS")===e.toLocaleUpperCase(s))return[e];const n=[...e],l=n.length,c=[];let t=n[0],a=n[0]===n[0].toLocaleUpperCase(s),r=a,i=a?0:-1;for(let p=1;p<l;p++){const o=n[p],E=o===o.toLocaleUpperCase(s);if(E===a)t+=o;else if(E)t&&t.length>0&&(c.push(t),t=o),r=!0,i=p;else{if(r&&p-i>1){const d=n[p-1],m=t.slice(0,-1);m&&m.length>0&&c.push(m),t=d+o}else t+=o;r=!1,i=-1}a=E}return t&&t.length>0&&c.push(t),c}if(s.startsWith("uk")||s.startsWith("ru")||s.startsWith("bg")||s.startsWith("sr")||s.startsWith("mk")||s.startsWith("be")){if(!b.test(e)&&!C.test(e))return[e];const n=[...e],l=n.length,c=[];let t=n[0];const a=n[0];let r;b.test(a)?r=1:C.test(a)?r=2:r=0;let i=a===a.toLocaleUpperCase(s);for(let o=1;o<l;o++){const E=n[o];let d;b.test(E)?d=1:C.test(E)?d=2:d=0;const m=E===E.toLocaleUpperCase(s);r!==d&&(r===1||r===2)&&(d===1||d===2)||d===r&&!i&&m?(c.push(t),t=E):t+=E,r=d,i=m}t&&t.length>0&&c.push(t);const p=[];for(let o=0;o<c.length;o++)o<c.length-1&&c[o].length===1&&C.test(c[o])&&b.test(c[o+1][0])?(p.push(c[o]+c[o+1]),o+=1):p.push(c[o]);return p}if(s.startsWith("el")){if(!T.test(e)&&!C.test(e))return[e];const n=[];S.lastIndex=0;let l;for(;(l=S.exec(e))!==null;)n.push(l[0]);n.length===0&&n.push(e);const c=[];if(n.length===1){const t=n[0];if(!t||!T.test(t[0])||t.length===1)return[t??e]}for(const t of n){if(!t)continue;if(!T.test(t[0])||t.length===1){c.push(t);continue}const a=t.length;let r=t[0],i=t[0]===t[0].toLocaleUpperCase(s);for(let p=1;p<a;p++){const o=t[p],E=o===o.toLocaleUpperCase(s);!i&&E?(c.push(r),r=o):r+=o,i=E}r&&c.push(r)}return c}if(s.startsWith("ja")||s.startsWith("ko")){const n=s.startsWith("ja"),l=n?{hiragana:A(t=>ne.test(t),"hiragana"),kanji:A(t=>O.test(t),"kanji"),katakana:A(t=>se.test(t),"katakana"),latin:A(t=>C.test(t),"latin")}:{hangul:A(t=>M.test(t),"hangul"),latin:A(t=>C.test(t),"latin")},c=new Set(["が","で","と","に","の","は","へ","も","や","を"]);if(n){const t=I(e,l,!1,s,(r,i)=>r==="hiragana"&&i==="katakana"||r==="katakana"&&i==="hiragana"||r==="hiragana"&&i==="latin"||r==="katakana"&&i==="latin"||r==="kanji"&&i==="latin"||r==="latin"&&(i==="hiragana"||i==="katakana"||i==="kanji")),a=[];for(const r of t){const i=r;i.length===1&&c.has(i)&&a.length>0?a[a.length-1]=a.at(-1)+i:a.push(i)}return a.length>0?a:[e]}return I(e,l,!1,s,(t,a)=>t==="hangul"&&a==="latin"||t==="latin"&&a==="hangul")}if(s.startsWith("sl")){const n=[...e],l=n.length,c=[];let t=n[0],a=n[0]===n[0].toLocaleUpperCase(s);for(let r=1;r<l;r++){const i=n[r],p=i===i.toLocaleUpperCase(s),o=ye.test(i),E=r<l-1&&n[r+1]===n[r+1].toLocaleUpperCase(s);!a&&p||o&&E?(c.push(t),t=i,o&&E&&(c.push(t),t="")):t+=i,a=p}return t&&t.length>0&&c.push(t),c}if(s.startsWith("zh"))return I(e,{han:A(n=>O.test(n),"han"),latin:A(n=>C.test(n),"latin")},!1,s);if(["ar","fa","he","ur"].includes(s.split("-")[0])){const n=A(l=>P.test(l)||G.test(l),"isRtlChar");return I(e,{latin:A(l=>C.test(l),"latin"),rtl:A(l=>n(l),"rtl")},!1,s)}if(["am","bn","gu","hi","km","kn","lo","ml","mr","ne","or","pa","si","ta","te","th"].includes(s.split("-")[0])){const n=A(l=>re.test(l)||ae.test(l)||le.test(l)||oe.test(l)||ie.test(l)||ce.test(l)||he.test(l)||pe.test(l)||ue.test(l)||fe.test(l)||ge.test(l)||Ae.test(l)||Ee.test(l)||Re.test(l)||_e.test(l)||de.test(l),"isIndicChar");return I(e,{indic:A(l=>n(l),"indic"),latin:A(l=>C.test(l),"latin")},!1,s)}if(["be","bg","ru","sr","uk"].includes(s))return I(e,{cyrillic:A(n=>b.test(n),"cyrillic"),latin:A(n=>C.test(n),"latin")},!0,s);if(["ar","fa","he"].includes(s))return I(e,{latin:A(n=>C.test(n),"latin"),rtl:A(n=>P.test(n)||G.test(n),"rtl")},!1,s);if(s.startsWith("ko"))return I(e,{hangul:A(n=>M.test(n),"hangul"),latin:A(n=>C.test(n),"latin")},!1,s);if(s.startsWith("uz")){if(!b.test(e)&&!C.test(e))return[e];const n=[...e],l=n.length,c=[];let t=n[0],a=n[0]===n[0].toLocaleUpperCase(s);for(let r=1;r<l;r++){const i=n[r],p=i===i.toLocaleUpperCase(s);if(K.test(i)||K.test(n[r-1])){t+=i;continue}!a&&p?(c.push(t),t=i):t+=i,a=p}return t&&t.length>0&&c.push(t),c}const R=[...e],u=R.length,L=[];let f=R[0],_=R[0]===R[0].toLocaleUpperCase(s);for(const n of h)if(e.startsWith(n)){L.push(n),f=R[n.length],_=f===f.toLocaleUpperCase(s);break}for(let n=1;n<u;n++){const l=R[n],c=l===l.toLocaleUpperCase(s);let t=0;for(const a of h)if(e.startsWith(a,n)){L.push(f,a),t=a.length,f="";const r=a.at(-1);r&&(_=r===r.toLocaleUpperCase(s));break}if(t>0){n+=t-1;continue}!_&&c?(L.push(f),f=l):f+=l,_=c}return f&&L.push(f),L},"splitCamelCaseLocale"),Te=A((e,s,h)=>{const g=[],R=x.test(e)?e.split(x).filter(Boolean):[e];for(const u of R){const L=u;if(x.test(L))g.push(L);else{const f=y.test(L)?We(L).filter(Boolean):[L];for(const _ of f)if(y.test(_))g.push(_);else if(s){const n=s.toLowerCase().split("-")[0];g.push(...F(_,n,h))}else g.push(...q(_,h))}}return g},"processTextWithAnsiEmoji"),Se=A((e,s={})=>{if(!e||typeof e!="string")return[];const{handleAnsi:h=!1,handleEmoji:g=!1,knownAcronyms:R=[],locale:u,normalize:L=!1,separators:f,stripAnsi:_=!1,stripEmoji:n=!1}=s,l=new Set([...R].toSorted((o,E)=>E.length-o.length));let c=e;_&&(c=X(c)),n&&(c=ee(c));let t;Array.isArray(f)?t=ke(f):f instanceof RegExp?t=f:t=te;const a=[];let r=c;const i=t.flags.includes("g")?t:new RegExp(t.source,`${t.flags}g`);for(;r.length>0;){const o=i.exec(r);if(!o){r===".."?a.push(".."):r==="."?a.push("."):r.length>0&&a.push(r);break}const E=o.index,d=o[0],m=d.length,B=r.slice(0,E),Y=r.slice(E+m);if(d.startsWith("../"))a.push(".."),r=r.slice(E+3);else if(d.startsWith("./"))a.push("."),r=r.slice(E+2);else if(E===0&&d==="..")a.push(".."),r=r.slice(2);else if(E===0&&d===".")a.push("."),r=r.slice(1);else{B.length>0&&a.push(B);let U=0;for(;(U=d.indexOf("../",U))!==-1;)a.push(".."),U+=3;for(U=0;(U=d.indexOf("./",U))!==-1;)(U===0||d[U-1]!==".")&&a.push("."),U+=2;let k=Y;for(;k.startsWith("../");)a.push(".."),k=k.slice(3);for(;k.startsWith("./");)a.push("."),k=k.slice(2);if(k===".."){a.push("..");break}else if(k==="."){a.push(".");break}else r=k}i.lastIndex=0}if(a.length===0){const o=c.split(t).filter(Boolean);a.push(...o)}let p=[];for(const o of a)h||g?p.push(...Te(o,u,l)):u?p.push(...F(o,u,l)):p.push(...q(o,l));return L&&(p=p.map(o=>l.has(o)?o:u&&o===o.toLocaleUpperCase(u)?o[0]+o.slice(1).toLocaleLowerCase(u):o.toUpperCase()===o&&!l.has(o)?o.slice(0,1)+o.slice(1).toLowerCase():o)),p},"splitByCase");export{Se as splitByCase};
|