@visulima/string 3.0.0-alpha.9 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +305 -0
- package/LICENSE.md +68 -3
- package/README.md +80 -2
- package/dist/align-text.d.ts +35 -0
- package/dist/align-text.js +2 -34
- package/dist/case/camel-case.d.ts +17 -3
- package/dist/case/camel-case.js +1 -55
- package/dist/case/capital-case.d.ts +14 -3
- package/dist/case/capital-case.js +1 -47
- package/dist/case/constant-case.d.ts +14 -3
- package/dist/case/constant-case.js +1 -7
- package/dist/case/dot-case.d.ts +14 -3
- package/dist/case/dot-case.js +1 -7
- package/dist/case/flat-case.d.ts +12 -3
- package/dist/case/flat-case.js +1 -7
- package/dist/case/flip-case.d.ts +16 -3
- package/dist/case/flip-case.js +1 -82
- package/dist/case/identify-case.d.ts +15 -3
- package/dist/case/identify-case.js +1 -66
- package/dist/case/index.d.ts +8 -3
- package/dist/case/index.js +1 -20
- package/dist/case/kebab-case.d.ts +25 -3
- package/dist/case/kebab-case.js +1 -55
- package/dist/case/lower-first.d.ts +13 -3
- package/dist/case/lower-first.js +1 -9
- package/dist/case/no-case.d.ts +14 -3
- package/dist/case/no-case.js +1 -7
- package/dist/case/pascal-case.d.ts +17 -3
- package/dist/case/pascal-case.js +1 -48
- package/dist/case/pascal-snake-case.d.ts +14 -3
- package/dist/case/pascal-snake-case.js +1 -28
- package/dist/case/path-case.d.ts +14 -3
- package/dist/case/path-case.js +1 -7
- package/dist/case/sentence-case.d.ts +14 -3
- package/dist/case/sentence-case.js +1 -54
- package/dist/case/snake-case.d.ts +14 -3
- package/dist/case/snake-case.js +1 -7
- package/dist/case/split-by-case.d.ts +29 -3
- package/dist/case/split-by-case.js +1 -763
- package/dist/case/title-case.d.ts +12 -3
- package/dist/case/title-case.js +1 -40
- package/dist/case/train-case.d.ts +14 -3
- package/dist/case/train-case.js +1 -40
- package/dist/case/upper-first.d.ts +13 -3
- 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 +37 -0
- package/dist/compare-similarity.js +1 -12
- package/dist/count-occurrences.d.ts +9 -0
- package/dist/count-occurrences.js +1 -0
- package/dist/direction.d.ts +7 -0
- package/dist/direction.js +1 -0
- package/dist/east-asian-width.d.ts +58 -0
- package/dist/east-asian-width.js +1 -0
- package/dist/excerpt.d.ts +25 -0
- package/dist/excerpt.js +53 -0
- 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/indent.d.ts +88 -0
- package/dist/indent.js +1 -0
- package/dist/index.d.ts +12 -20
- package/dist/index.js +1 -44
- package/dist/is-fullwidth-code-point.d.ts +7 -0
- package/dist/is-fullwidth-code-point.js +1 -0
- package/dist/levenshtein.d.ts +25 -0
- package/dist/levenshtein.js +1 -0
- package/dist/native-string-types.d.ts +241 -18
- package/dist/outdent.d.ts +74 -0
- package/dist/outdent.js +1 -109
- package/dist/packem_shared/_isFullWidth-Dqc3MWgl.js +1 -0
- package/dist/packem_shared/closest-C6YDQs4m.js +1 -0
- package/dist/packem_shared/constants-aPzGW29R.js +1 -0
- package/dist/packem_shared/dedent-CPjAYUXh.js +1 -0
- package/dist/packem_shared/eastAsianWidth-DJV8Kqd-.js +1 -0
- package/dist/packem_shared/generate-cache-key-B_0X7MKm.js +1 -0
- package/dist/packem_shared/indent-cz8WMI0e.js +1 -0
- package/dist/packem_shared/joinSegments-CaHT-45s.js +1 -0
- package/dist/packem_shared/lru-cache-BtMSrYQJ.js +1 -0
- package/dist/packem_shared/normalize-german-eszett-hNMwtGjd.js +1 -0
- package/dist/packem_shared/redent-ByOoJ6fN.js +1 -0
- package/dist/packem_shared/strip-vt-control-characters-BW1RglLp.js +1 -0
- package/dist/packem_shared/types.d-CMNqA5bi.d.ts +402 -0
- package/dist/packem_shared/types.d-LgsTR37y.d.ts +360 -0
- package/dist/replace-string.d.ts +10 -0
- package/dist/replace-string.js +1 -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/transliterate.d.ts +10 -0
- package/dist/transliterate.js +5 -0
- package/dist/truncate.d.ts +43 -0
- package/dist/truncate.js +1 -112
- package/dist/utilities.d.ts +28 -2
- 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 +70 -36
- 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/lru-cache.d-BsP6kbVJ.d.ts +0 -13
- 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
|
+
import{b as W,s as v,l as F,c as x,m,n as U,o as b,p as j,q as y,r as $,t as B,u as q,v as G,w as K,x as H,y as V,z as Z,A as Q,B as X,C as tt,D as et,E as st,F as nt,G as lt,H as rt,I as ot,J as at,K as it,L as ht,M as ct,N as ut}from"../packem_shared/constants-aPzGW29R.js";import{i as ft}from"../packem_shared/lru-cache-BtMSrYQJ.js";import{r as pt}from"../packem_shared/strip-vt-control-characters-BW1RglLp.js";const N=new ft(1e3),gt=/[.*+?^${}()|[\]\\]/g,At=t=>{const l=t.join("");if(N.has(l)){const A=N.get(l);return A.lastIndex=0,A}const c=t.map(A=>A.replaceAll(gt,String.raw`\$&`)).join("|"),g=new RegExp(c,"g");return N.set(l,g),g},Et=t=>{const l=[];let c=0,g;for(W.lastIndex=0;(g=W.exec(t))!==null;)g.index>c&&l.push(t.slice(c,g.index)),l.push(g[0]),c=W.lastIndex;return c<t.length&&l.push(t.slice(c)),l.filter(Boolean)},Rt=/[ČŠŽĐ]/i,O=new Uint8Array(128),P=new Uint8Array(128),z=new Uint8Array(128);for(let t=0;t<128;t++)O[t]=t>=65&&t<=90?1:0,P[t]=t>=97&&t<=122?1:0,z[t]=t>=48&&t<=57?1:0;const w=t=>O[t],M=t=>P[t],T=t=>z[t],d=(t,l,c,g,A)=>{if(t.length===0)return[];let f=!1;const C=Object.values(l);for(const r of C)if(r(t[0])){f=!0;break}if(!f&&!c)return[t];const p=[...t],R=[];let s=p[0],o="other";const h=Object.entries(l);for(const r of h){const[n,i]=r;if(i(p[0])){o=n;break}}let e=c&&g?p[0]===p[0].toLocaleUpperCase(g):!1;for(let r=1;r<p.length;r++){const n=p[r];let i="other";for(const E of h){const[L,_]=E;if(_(n)){i=L;break}}const u=c&&g?n===n.toLocaleUpperCase(g):!1;let a=!1;A?a=A(o,i,e,u,n,r,p):(o!==i&&o!=="other"&&i!=="other"&&(a=!0),c&&i!=="other"&&!e&&u&&(a=!0)),a?(R.push(s),s=n):s+=n,o=i,c&&(e=u)}return s&&s.length>0&&R.push(s),R.length>0?R:[t]},Lt=(t,l,c,g)=>{if(c.size===0)return l;for(const A of c)if(t.startsWith(A,l))return g.push(A),l+A.length;return l},D=(t,l=new Set)=>{if(t.length===0)return[];if(t.toUpperCase()===t)return[t];let c=0;const g=[],A=t.length;for(let f=1;f<A;f++){const C=Lt(t,c,l,g);if(C!==c){c=C,f=c-1;continue}const p=t.codePointAt(f-1),R=t.codePointAt(f),s=p&&p<128&&w(p),o=R&&R<128&&w(R),h=p&&p<128&&M(p),e=p&&p<128&&T(p),r=R&&R<128&&T(R);if(h&&o){g.push(t.slice(c,f)),c=f;continue}if(e&&!r||!e&&r){g.push(t.slice(c,f)),c=f;continue}if(r&&!e){let n=!1,i=!1;if(f+1<A){const u=t.codePointAt(f+1);n=u&&u<128&&w(u),i=u&&u<128&&T(u)}if(!i&&n){g.push(t.slice(c,f),t.slice(f,f+1)),c=f+1;continue}}if(f+1<A){const n=t.codePointAt(f+1),i=n&&n<128&&M(n);if(s&&o&&i){const u=t.slice(c,f+1);l.has(u)||(g.push(t.slice(c,f)),c=f)}}}return c<A&&g.push(t.slice(c)),g.filter(f=>f!=="")},J=(t,l,c)=>{if(t.length===0)return[];const g=t===t.toLocaleUpperCase(l);if(l.startsWith("de")){if(!g&&t.replaceAll("ß","SS")===t.toLocaleUpperCase(l))return[t];const s=[...t],o=s.length,h=[];let e=s[0],r=s[0]===s[0].toLocaleUpperCase(l),n=r,i=r?0:-1;for(let u=1;u<o;u++){const a=s[u],E=a===a.toLocaleUpperCase(l);if(E===r)e+=a;else if(E)e&&e.length>0&&(h.push(e),e=a),n=!0,i=u;else{if(n&&u-i>1){const L=s[u-1],_=e.slice(0,-1);_&&_.length>0&&h.push(_),e=L+a}else e+=a;n=!1,i=-1}r=E}return e&&e.length>0&&h.push(e),h}if(l.startsWith("uk")||l.startsWith("ru")||l.startsWith("bg")||l.startsWith("sr")||l.startsWith("mk")||l.startsWith("be")){if(!m.test(t)&&!U.test(t))return[t];const s=[...t],o=s.length,h=[];let e=s[0];const r=s[0];let n;m.test(r)?n=1:U.test(r)?n=2:n=0;let i=r===r.toLocaleUpperCase(l);for(let a=1;a<o;a++){const E=s[a];let L;m.test(E)?L=1:U.test(E)?L=2:L=0;const _=E===E.toLocaleUpperCase(l);n!==L&&(n===1||n===2)&&(L===1||L===2)||L===n&&!i&&_?(h.push(e),e=E):e+=E,n=L,i=_}e&&e.length>0&&h.push(e);const u=[];for(let a=0;a<h.length;a++)a<h.length-1&&h[a].length===1&&U.test(h[a])&&m.test(h[a+1][0])?(u.push(h[a]+h[a+1]),a+=1):u.push(h[a]);return u}if(l.startsWith("el")){if(!b.test(t)&&!U.test(t))return[t];const s=[];j.lastIndex=0;let o;for(;(o=j.exec(t))!==null;)s.push(o[0]);s.length===0&&s.push(t);const h=[];if(s.length===1){const e=s[0];if(!e||!b.test(e[0])||e.length===1)return[e??t]}for(const e of s){if(!e)continue;if(!b.test(e[0])||e.length===1){h.push(e);continue}const r=e.length;let n=e[0],i=e[0]===e[0].toLocaleUpperCase(l);for(let u=1;u<r;u++){const a=e[u],E=a===a.toLocaleUpperCase(l);!i&&E?(h.push(n),n=a):n+=a,i=E}n&&h.push(n)}return h}if(l.startsWith("ja")||l.startsWith("ko")){const s=l.startsWith("ja"),o=s?{hiragana:e=>q.test(e),kanji:e=>B.test(e),katakana:e=>$.test(e),latin:e=>U.test(e)}:{hangul:e=>G.test(e),latin:e=>U.test(e)},h=new Set(["が","で","と","に","の","は","へ","も","や","を"]);if(s){const e=d(t,o,!1,l,(n,i)=>n==="hiragana"&&i==="katakana"||n==="katakana"&&i==="hiragana"||n==="hiragana"&&i==="latin"||n==="katakana"&&i==="latin"||n==="kanji"&&i==="latin"||n==="latin"&&(i==="hiragana"||i==="katakana"||i==="kanji")),r=[];for(const n of e){const i=n;i.length===1&&h.has(i)&&r.length>0?r[r.length-1]=r.at(-1)+i:r.push(i)}return r.length>0?r:[t]}return d(t,o,!1,l,(e,r)=>e==="hangul"&&r==="latin"||e==="latin"&&r==="hangul")}if(l.startsWith("sl")){const s=[...t],o=s.length,h=[];let e=s[0],r=s[0]===s[0].toLocaleUpperCase(l);for(let n=1;n<o;n++){const i=s[n],u=i===i.toLocaleUpperCase(l),a=Rt.test(i),E=n<o-1&&s[n+1]===s[n+1].toLocaleUpperCase(l);!r&&u||a&&E?(h.push(e),e=i,a&&E&&(h.push(e),e="")):e+=i,r=u}return e&&e.length>0&&h.push(e),h}if(l.startsWith("zh"))return d(t,{han:s=>B.test(s),latin:s=>U.test(s)},!1,l);if(["ar","fa","he","ur"].includes(l.split("-")[0])){const s=o=>K.test(o)||H.test(o);return d(t,{latin:o=>U.test(o),rtl:o=>s(o)},!1,l)}if(["am","bn","gu","hi","km","kn","lo","ml","mr","ne","or","pa","si","ta","te","th"].includes(l.split("-")[0])){const s=o=>V.test(o)||Z.test(o)||Q.test(o)||X.test(o)||tt.test(o)||et.test(o)||st.test(o)||nt.test(o)||lt.test(o)||rt.test(o)||ot.test(o)||at.test(o)||it.test(o)||ht.test(o)||ct.test(o)||ut.test(o);return d(t,{indic:o=>s(o),latin:o=>U.test(o)},!1,l)}if(["be","bg","ru","sr","uk"].includes(l))return d(t,{cyrillic:s=>m.test(s),latin:s=>U.test(s)},!0,l);if(["ar","fa","he"].includes(l))return d(t,{latin:s=>U.test(s),rtl:s=>K.test(s)||H.test(s)},!1,l);if(l.startsWith("ko"))return d(t,{hangul:s=>G.test(s),latin:s=>U.test(s)},!1,l);if(l.startsWith("uz")){if(!m.test(t)&&!U.test(t))return[t];const s=[...t],o=s.length,h=[];let e=s[0],r=s[0]===s[0].toLocaleUpperCase(l);for(let n=1;n<o;n++){const i=s[n],u=i===i.toLocaleUpperCase(l);if(y.test(i)||y.test(s[n-1])){e+=i;continue}!r&&u?(h.push(e),e=i):e+=i,r=u}return e&&e.length>0&&h.push(e),h}const A=[...t],f=A.length,C=[];let p=A[0],R=A[0]===A[0].toLocaleUpperCase(l);for(const s of c)if(t.startsWith(s)){C.push(s),p=A[s.length],R=p===p.toLocaleUpperCase(l);break}for(let s=1;s<f;s++){const o=A[s],h=o===o.toLocaleUpperCase(l);let e=0;for(const r of c)if(t.startsWith(r,s)){C.push(p,r),e=r.length,p="";const n=r.at(-1);n&&(R=n===n.toLocaleUpperCase(l));break}if(e>0){s+=e-1;continue}!R&&h?(C.push(p),p=o):p+=o,R=h}return p&&C.push(p),C},Ct=(t,l,c)=>{const g=[],A=x.test(t)?t.split(x).filter(Boolean):[t];for(const f of A){const C=f;if(x.test(C))g.push(C);else{W.lastIndex=0;const p=W.test(C)?Et(C).filter(Boolean):[C];for(const R of p)if(W.lastIndex=0,W.test(R))g.push(R);else if(l){const s=l.toLowerCase().split("-")[0];g.push(...J(R,s,c))}else g.push(...D(R,c))}}return g},kt=(t,l={})=>{if(!t||typeof t!="string")return[];const{handleAnsi:c=!1,handleEmoji:g=!1,knownAcronyms:A=[],locale:f,normalize:C=!1,separators:p,stripAnsi:R=!1,stripEmoji:s=!1}=l,o=new Set([...A].toSorted((a,E)=>E.length-a.length));let h=t;R&&(h=pt(h)),s&&(h=v(h));let e;Array.isArray(p)?e=At(p):p instanceof RegExp?e=p:e=F;const r=[];let n=h;const i=e.flags.includes("g")?e:new RegExp(e.source,`${e.flags}g`);for(;n.length>0;){const a=i.exec(n);if(!a){n===".."?r.push(".."):n==="."?r.push("."):n.length>0&&r.push(n);break}const E=a.index,L=a[0],_=L.length,S=n.slice(0,E),Y=n.slice(E+_);if(L.startsWith("../"))r.push(".."),n=n.slice(E+3);else if(L.startsWith("./"))r.push("."),n=n.slice(E+2);else if(E===0&&L==="..")r.push(".."),n=n.slice(2);else if(E===0&&L===".")r.push("."),n=n.slice(1);else{S.length>0&&r.push(S);let I=0;for(;(I=L.indexOf("../",I))!==-1;)r.push(".."),I+=3;for(I=0;(I=L.indexOf("./",I))!==-1;)(I===0||L[I-1]!==".")&&r.push("."),I+=2;let k=Y;for(;k.startsWith("../");)r.push(".."),k=k.slice(3);for(;k.startsWith("./");)r.push("."),k=k.slice(2);if(k===".."){r.push("..");break}else if(k==="."){r.push(".");break}else n=k}i.lastIndex=0}if(r.length===0){const a=h.split(e).filter(Boolean);r.push(...a)}let u=[];for(const a of r)c||g?u.push(...Ct(a,f,o)):f?u.push(...J(a,f,o)):u.push(...D(a,o));return C&&(u=u.map(a=>o.has(a)?a:f&&a===a.toLocaleUpperCase(f)?a[0]+a.slice(1).toLocaleLowerCase(f):a.toUpperCase()===a&&!o.has(a)?a.slice(0,1)+a.slice(1).toLowerCase():a)),u};export{kt as splitByCase};
|