@visulima/string 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE.md +77 -0
  3. package/README.md +880 -0
  4. package/dist/case/camel-case.cjs +59 -0
  5. package/dist/case/camel-case.d.cts +7 -0
  6. package/dist/case/camel-case.d.mts +7 -0
  7. package/dist/case/camel-case.d.ts +7 -0
  8. package/dist/case/camel-case.mjs +57 -0
  9. package/dist/case/capital-case.cjs +51 -0
  10. package/dist/case/capital-case.d.cts +7 -0
  11. package/dist/case/capital-case.d.mts +7 -0
  12. package/dist/case/capital-case.d.ts +7 -0
  13. package/dist/case/capital-case.mjs +49 -0
  14. package/dist/case/constant-case.cjs +11 -0
  15. package/dist/case/constant-case.d.cts +7 -0
  16. package/dist/case/constant-case.d.mts +7 -0
  17. package/dist/case/constant-case.d.ts +7 -0
  18. package/dist/case/constant-case.mjs +9 -0
  19. package/dist/case/dot-case.cjs +11 -0
  20. package/dist/case/dot-case.d.cts +7 -0
  21. package/dist/case/dot-case.d.mts +7 -0
  22. package/dist/case/dot-case.d.ts +7 -0
  23. package/dist/case/dot-case.mjs +9 -0
  24. package/dist/case/flat-case.cjs +11 -0
  25. package/dist/case/flat-case.d.cts +7 -0
  26. package/dist/case/flat-case.d.mts +7 -0
  27. package/dist/case/flat-case.d.ts +7 -0
  28. package/dist/case/flat-case.mjs +9 -0
  29. package/dist/case/flip-case.cjs +61 -0
  30. package/dist/case/flip-case.d.cts +8 -0
  31. package/dist/case/flip-case.d.mts +8 -0
  32. package/dist/case/flip-case.d.ts +8 -0
  33. package/dist/case/flip-case.mjs +57 -0
  34. package/dist/case/identify-case.cjs +30 -0
  35. package/dist/case/identify-case.d.cts +7 -0
  36. package/dist/case/identify-case.d.mts +7 -0
  37. package/dist/case/identify-case.d.ts +7 -0
  38. package/dist/case/identify-case.mjs +28 -0
  39. package/dist/case/index.cjs +47 -0
  40. package/dist/case/index.d.cts +26 -0
  41. package/dist/case/index.d.mts +26 -0
  42. package/dist/case/index.d.ts +26 -0
  43. package/dist/case/index.mjs +20 -0
  44. package/dist/case/kebab-case.cjs +61 -0
  45. package/dist/case/kebab-case.d.cts +11 -0
  46. package/dist/case/kebab-case.d.mts +11 -0
  47. package/dist/case/kebab-case.d.ts +11 -0
  48. package/dist/case/kebab-case.mjs +57 -0
  49. package/dist/case/lower-first.cjs +13 -0
  50. package/dist/case/lower-first.d.cts +7 -0
  51. package/dist/case/lower-first.d.mts +7 -0
  52. package/dist/case/lower-first.d.ts +7 -0
  53. package/dist/case/lower-first.mjs +11 -0
  54. package/dist/case/no-case.cjs +11 -0
  55. package/dist/case/no-case.d.cts +7 -0
  56. package/dist/case/no-case.d.mts +7 -0
  57. package/dist/case/no-case.d.ts +7 -0
  58. package/dist/case/no-case.mjs +9 -0
  59. package/dist/case/pascal-case.cjs +52 -0
  60. package/dist/case/pascal-case.d.cts +7 -0
  61. package/dist/case/pascal-case.d.mts +7 -0
  62. package/dist/case/pascal-case.d.ts +7 -0
  63. package/dist/case/pascal-case.mjs +50 -0
  64. package/dist/case/pascal-snake-case.cjs +32 -0
  65. package/dist/case/pascal-snake-case.d.cts +7 -0
  66. package/dist/case/pascal-snake-case.d.mts +7 -0
  67. package/dist/case/pascal-snake-case.d.ts +7 -0
  68. package/dist/case/pascal-snake-case.mjs +30 -0
  69. package/dist/case/path-case.cjs +11 -0
  70. package/dist/case/path-case.d.cts +7 -0
  71. package/dist/case/path-case.d.mts +7 -0
  72. package/dist/case/path-case.d.ts +7 -0
  73. package/dist/case/path-case.mjs +9 -0
  74. package/dist/case/sentence-case.cjs +58 -0
  75. package/dist/case/sentence-case.d.cts +7 -0
  76. package/dist/case/sentence-case.d.mts +7 -0
  77. package/dist/case/sentence-case.d.ts +7 -0
  78. package/dist/case/sentence-case.mjs +56 -0
  79. package/dist/case/snake-case.cjs +11 -0
  80. package/dist/case/snake-case.d.cts +7 -0
  81. package/dist/case/snake-case.d.mts +7 -0
  82. package/dist/case/snake-case.d.ts +7 -0
  83. package/dist/case/snake-case.mjs +9 -0
  84. package/dist/case/split-by-case.cjs +638 -0
  85. package/dist/case/split-by-case.d.cts +16 -0
  86. package/dist/case/split-by-case.d.mts +16 -0
  87. package/dist/case/split-by-case.d.ts +16 -0
  88. package/dist/case/split-by-case.mjs +634 -0
  89. package/dist/case/title-case.cjs +47 -0
  90. package/dist/case/title-case.d.cts +7 -0
  91. package/dist/case/title-case.d.mts +7 -0
  92. package/dist/case/title-case.d.ts +7 -0
  93. package/dist/case/title-case.mjs +45 -0
  94. package/dist/case/train-case.cjs +44 -0
  95. package/dist/case/train-case.d.cts +7 -0
  96. package/dist/case/train-case.d.mts +7 -0
  97. package/dist/case/train-case.d.ts +7 -0
  98. package/dist/case/train-case.mjs +42 -0
  99. package/dist/case/upper-first.cjs +13 -0
  100. package/dist/case/upper-first.d.cts +7 -0
  101. package/dist/case/upper-first.d.mts +7 -0
  102. package/dist/case/upper-first.d.ts +7 -0
  103. package/dist/case/upper-first.mjs +11 -0
  104. package/dist/get-string-truncated-width.cjs +386 -0
  105. package/dist/get-string-truncated-width.d.cts +25 -0
  106. package/dist/get-string-truncated-width.d.mts +25 -0
  107. package/dist/get-string-truncated-width.d.ts +25 -0
  108. package/dist/get-string-truncated-width.mjs +382 -0
  109. package/dist/get-string-width.cjs +11 -0
  110. package/dist/get-string-width.d.cts +6 -0
  111. package/dist/get-string-width.d.mts +6 -0
  112. package/dist/get-string-width.d.ts +6 -0
  113. package/dist/get-string-width.mjs +7 -0
  114. package/dist/index.cjs +60 -0
  115. package/dist/index.d.cts +43 -0
  116. package/dist/index.d.mts +43 -0
  117. package/dist/index.d.ts +43 -0
  118. package/dist/index.mjs +26 -0
  119. package/dist/native-string-types.d.cts +128 -0
  120. package/dist/native-string-types.d.mts +128 -0
  121. package/dist/native-string-types.d.ts +128 -0
  122. package/dist/outdent.cjs +122 -0
  123. package/dist/outdent.d.cts +15 -0
  124. package/dist/outdent.d.mts +15 -0
  125. package/dist/outdent.d.ts +15 -0
  126. package/dist/outdent.mjs +118 -0
  127. package/dist/packem_shared/LRUCache-Crb-m7cw.cjs +53 -0
  128. package/dist/packem_shared/LRUCache-udNErhWw.mjs +51 -0
  129. package/dist/packem_shared/WrapMode-BgOOthJV.mjs +545 -0
  130. package/dist/packem_shared/WrapMode-ZqTeXK8X.cjs +550 -0
  131. package/dist/packem_shared/constants-BnVGLrDr.mjs +99 -0
  132. package/dist/packem_shared/constants-HevSYUjU.cjs +149 -0
  133. package/dist/packem_shared/generate-cache-key-D8f1auDB.cjs +10 -0
  134. package/dist/packem_shared/generate-cache-key-YSju5pj2.mjs +8 -0
  135. package/dist/packem_shared/joinSegments-BH1CT4dK.cjs +48 -0
  136. package/dist/packem_shared/joinSegments-BHY8PPnk.mjs +46 -0
  137. package/dist/packem_shared/normalize-german-eszett-DJK0S2qj.cjs +11 -0
  138. package/dist/packem_shared/normalize-german-eszett-fpJ4lZL6.mjs +9 -0
  139. package/dist/packem_shared/types-BAd3WDHo.d.mts +59 -0
  140. package/dist/packem_shared/types-BNbQJg02.d.cts +41 -0
  141. package/dist/packem_shared/types-BNbQJg02.d.mts +41 -0
  142. package/dist/packem_shared/types-BNbQJg02.d.ts +41 -0
  143. package/dist/packem_shared/types-BttWSSIk.d.ts +59 -0
  144. package/dist/packem_shared/types-D2-6p7t1.d.cts +59 -0
  145. package/dist/slice.cjs +413 -0
  146. package/dist/slice.d.cts +10 -0
  147. package/dist/slice.d.mts +10 -0
  148. package/dist/slice.d.ts +10 -0
  149. package/dist/slice.mjs +409 -0
  150. package/dist/test/utils.cjs +77 -0
  151. package/dist/test/utils.d.cts +30 -0
  152. package/dist/test/utils.d.mts +30 -0
  153. package/dist/test/utils.d.ts +30 -0
  154. package/dist/test/utils.mjs +71 -0
  155. package/dist/test/vitest.cjs +11 -0
  156. package/dist/test/vitest.d.cts +8 -0
  157. package/dist/test/vitest.d.mts +8 -0
  158. package/dist/test/vitest.d.ts +8 -0
  159. package/dist/test/vitest.mjs +7 -0
  160. package/dist/truncate.cjs +90 -0
  161. package/dist/truncate.d.cts +12 -0
  162. package/dist/truncate.d.mts +12 -0
  163. package/dist/truncate.d.ts +12 -0
  164. package/dist/truncate.mjs +86 -0
  165. package/dist/utils.cjs +9 -0
  166. package/dist/utils.d.cts +14 -0
  167. package/dist/utils.d.mts +14 -0
  168. package/dist/utils.d.ts +14 -0
  169. package/dist/utils.mjs +1 -0
  170. package/package.json +468 -0
@@ -0,0 +1,634 @@
1
+ import { stripVTControlCharacters } from 'node:util';
2
+ import { h as RE_EMOJI, s as stripEmoji, i as RE_SEPARATORS, R as RE_FAST_ANSI, j as RE_CYRILLIC, k as RE_LATIN, l as RE_GREEK, m as RE_GREEK_LATIN_SPLIT, n as RE_KANJI, o as RE_HEBREW, p as RE_ARABIC, q as RE_HANGUL, r as RE_UZBEK_LATIN_MODIFIER, t as RE_KATAKANA, u as RE_HIRAGANA, v as RE_DEVANAGARI, w as RE_BENGALI, x as RE_GUJARATI, y as RE_GURMUKHI, z as RE_KANNADA, A as RE_TAMIL, B as RE_TELUGU, C as RE_MALAYALAM, D as RE_SINHALA, E as RE_THAI, F as RE_LAO, G as RE_TIBETAN, H as RE_MYANMAR, I as RE_ETHIOPIC, J as RE_KHMER, K as RE_ORIYA } from '../packem_shared/constants-BnVGLrDr.mjs';
3
+ import LRUCache from '../packem_shared/LRUCache-udNErhWw.mjs';
4
+
5
+ var __defProp$2 = Object.defineProperty;
6
+ var __name$2 = (target, value) => __defProp$2(target, "name", { value, configurable: true });
7
+ const regexCache = new LRUCache(1e3);
8
+ const getSeparatorsRegex = /* @__PURE__ */ __name$2((separators) => {
9
+ const key = separators.join("");
10
+ if (regexCache.has(key)) {
11
+ return regexCache.get(key);
12
+ }
13
+ const pattern = separators.map((s) => s.replaceAll(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
14
+ const regex = new RegExp(pattern, "g");
15
+ regexCache.set(key, regex);
16
+ return regex;
17
+ }, "getSeparatorsRegex");
18
+
19
+ var __defProp$1 = Object.defineProperty;
20
+ var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
21
+ const splitByEmoji = /* @__PURE__ */ __name$1((text) => {
22
+ const segments = [];
23
+ let lastIndex = 0;
24
+ let match;
25
+ RE_EMOJI.lastIndex = 0;
26
+ while ((match = RE_EMOJI.exec(text)) !== null) {
27
+ if (match.index > lastIndex) {
28
+ segments.push(text.slice(lastIndex, match.index));
29
+ }
30
+ segments.push(match[0]);
31
+ lastIndex = RE_EMOJI.lastIndex;
32
+ }
33
+ if (lastIndex < text.length) {
34
+ segments.push(text.slice(lastIndex));
35
+ }
36
+ return segments.filter(Boolean);
37
+ }, "splitByEmoji");
38
+
39
+ var __defProp = Object.defineProperty;
40
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
41
+ const isUpperCode = new Uint8Array(128);
42
+ const isLowerCode = new Uint8Array(128);
43
+ const isDigitCode = new Uint8Array(128);
44
+ for (let index = 0; index < 128; index++) {
45
+ isUpperCode[index] = index >= 65 && index <= 90 ? 1 : 0;
46
+ isLowerCode[index] = index >= 97 && index <= 122 ? 1 : 0;
47
+ isDigitCode[index] = index >= 48 && index <= 57 ? 1 : 0;
48
+ }
49
+ const handleScriptTransitions = /* @__PURE__ */ __name((s, scriptDetectors, caseSensitive, locale, customSplitLogic) => {
50
+ if (s.length === 0) {
51
+ return [];
52
+ }
53
+ let hasDetectedScript = false;
54
+ for (const detector of Object.values(scriptDetectors)) {
55
+ if (detector(s[0])) {
56
+ hasDetectedScript = true;
57
+ break;
58
+ }
59
+ }
60
+ if (!hasDetectedScript && !caseSensitive) {
61
+ return [s];
62
+ }
63
+ const chars = [...s];
64
+ const result = [];
65
+ let currentSegment = chars[0];
66
+ let previousType = "other";
67
+ for (const [type, detector] of Object.entries(scriptDetectors)) {
68
+ if (detector(chars[0])) {
69
+ previousType = type;
70
+ break;
71
+ }
72
+ }
73
+ let previousIsUpper = caseSensitive && locale ? chars[0] === chars[0].toLocaleUpperCase(locale) : false;
74
+ for (let index = 1; index < chars.length; index++) {
75
+ const char = chars[index];
76
+ let currentType = "other";
77
+ for (const [type, detector] of Object.entries(scriptDetectors)) {
78
+ if (detector(char)) {
79
+ currentType = type;
80
+ break;
81
+ }
82
+ }
83
+ const isUpper = caseSensitive && locale ? char === char.toLocaleUpperCase(locale) : false;
84
+ let shouldSplit = false;
85
+ if (customSplitLogic) {
86
+ shouldSplit = customSplitLogic(previousType, currentType, previousIsUpper, isUpper, char, index, chars);
87
+ } else {
88
+ if (previousType !== currentType && previousType !== "other" && currentType !== "other") {
89
+ shouldSplit = true;
90
+ }
91
+ if (caseSensitive && currentType !== "other" && !previousIsUpper && isUpper) {
92
+ shouldSplit = true;
93
+ }
94
+ }
95
+ if (shouldSplit) {
96
+ result.push(currentSegment);
97
+ currentSegment = char;
98
+ } else {
99
+ currentSegment += char;
100
+ }
101
+ previousType = currentType;
102
+ if (caseSensitive) {
103
+ previousIsUpper = isUpper;
104
+ }
105
+ }
106
+ if (currentSegment && currentSegment.length > 0) {
107
+ result.push(currentSegment);
108
+ }
109
+ return result.length > 0 ? result : [s];
110
+ }, "handleScriptTransitions");
111
+ const splitCamelCaseFast = /* @__PURE__ */ __name((s, knownAcronyms = /* @__PURE__ */ new Set()) => {
112
+ if (s.length === 0) {
113
+ return [];
114
+ }
115
+ if (s.toUpperCase() === s) {
116
+ return [s];
117
+ }
118
+ let start = 0;
119
+ const tokens = [];
120
+ const width = s.length;
121
+ for (let index = 1; index < width; index++) {
122
+ const previousCode = s.codePointAt(index - 1);
123
+ const currentCode = s.codePointAt(index);
124
+ if (knownAcronyms.size > 0) {
125
+ for (const acronym of knownAcronyms) {
126
+ if (s.startsWith(acronym, start)) {
127
+ tokens.push(acronym);
128
+ start += acronym.length;
129
+ index = start - 1;
130
+ break;
131
+ }
132
+ }
133
+ if (index < start) {
134
+ continue;
135
+ }
136
+ }
137
+ const previousIsUpper = previousCode && previousCode < 128 && isUpperCode[previousCode];
138
+ const currentIsUpper = currentCode && currentCode < 128 && isUpperCode[currentCode];
139
+ const previousIsLower = previousCode && previousCode < 128 && isLowerCode[previousCode];
140
+ const previousIsDigit = previousCode && previousCode < 128 && isDigitCode[previousCode];
141
+ const currentIsDigit = currentCode && currentCode < 128 && isDigitCode[currentCode];
142
+ if (previousIsLower && currentIsUpper) {
143
+ tokens.push(s.slice(start, index));
144
+ start = index;
145
+ continue;
146
+ }
147
+ if (previousIsDigit && !currentIsDigit || !previousIsDigit && currentIsDigit) {
148
+ tokens.push(s.slice(start, index));
149
+ start = index;
150
+ continue;
151
+ }
152
+ if (currentIsDigit && !previousIsDigit) {
153
+ let isNextUpper = false;
154
+ let isNextDigit = false;
155
+ if (index + 1 < width) {
156
+ const nextCode = s.codePointAt(index + 1);
157
+ isNextUpper = nextCode && nextCode < 128 && isUpperCode[nextCode];
158
+ isNextDigit = nextCode && nextCode < 128 && isDigitCode[nextCode];
159
+ }
160
+ if (!isNextDigit && isNextUpper) {
161
+ tokens.push(s.slice(start, index), s.slice(index, index + 1));
162
+ start = index + 1;
163
+ continue;
164
+ }
165
+ }
166
+ if (index + 1 < width) {
167
+ const nextCode = s.codePointAt(index + 1);
168
+ const nextIsLower = nextCode && nextCode < 128 && isLowerCode[nextCode];
169
+ if (previousIsUpper && currentIsUpper && nextIsLower) {
170
+ const candidate = s.slice(start, index + 1);
171
+ if (!knownAcronyms.has(candidate)) {
172
+ tokens.push(s.slice(start, index));
173
+ start = index;
174
+ }
175
+ }
176
+ }
177
+ }
178
+ if (start < width) {
179
+ tokens.push(s.slice(start));
180
+ }
181
+ return tokens.filter((token) => token !== "");
182
+ }, "splitCamelCaseFast");
183
+ const splitCamelCaseLocale = /* @__PURE__ */ __name((s, locale, knownAcronyms) => {
184
+ if (s.length === 0) {
185
+ return [];
186
+ }
187
+ const isUpperCase = s === s.toLocaleUpperCase(locale);
188
+ if (locale.startsWith("de")) {
189
+ if (!isUpperCase && s.replaceAll("ß", "SS") === s.toLocaleUpperCase(locale)) {
190
+ return [s];
191
+ }
192
+ const chars2 = [...s];
193
+ const width_2 = chars2.length;
194
+ const result2 = [];
195
+ let currentSegment2 = chars2[0];
196
+ let previousIsUpper2 = chars2[0] === chars2[0].toLocaleUpperCase(locale);
197
+ let isInUpperSequence = previousIsUpper2;
198
+ let upperSequenceStart = previousIsUpper2 ? 0 : -1;
199
+ for (let index = 1; index < width_2; index++) {
200
+ const char = chars2[index];
201
+ const isUpper = char === char.toLocaleUpperCase(locale);
202
+ if (isUpper === previousIsUpper2) {
203
+ currentSegment2 += char;
204
+ } else if (isUpper) {
205
+ if (currentSegment2 && currentSegment2.length > 0) {
206
+ result2.push(currentSegment2);
207
+ currentSegment2 = char;
208
+ }
209
+ isInUpperSequence = true;
210
+ upperSequenceStart = index;
211
+ } else {
212
+ if (isInUpperSequence && index - upperSequenceStart > 1) {
213
+ const lastUpperChar = chars2[index - 1];
214
+ const withoutLastUpper = currentSegment2.slice(0, -1);
215
+ if (withoutLastUpper && withoutLastUpper.length > 0) {
216
+ result2.push(withoutLastUpper);
217
+ }
218
+ currentSegment2 = lastUpperChar + char;
219
+ } else {
220
+ currentSegment2 += char;
221
+ }
222
+ isInUpperSequence = false;
223
+ upperSequenceStart = -1;
224
+ }
225
+ previousIsUpper2 = isUpper;
226
+ }
227
+ if (currentSegment2 && currentSegment2.length > 0) {
228
+ result2.push(currentSegment2);
229
+ }
230
+ return result2;
231
+ }
232
+ if (locale.startsWith("uk") || locale.startsWith("ru") || locale.startsWith("bg") || locale.startsWith("sr") || locale.startsWith("mk") || locale.startsWith("be")) {
233
+ if (!RE_CYRILLIC.test(s) && !RE_LATIN.test(s)) {
234
+ return [s];
235
+ }
236
+ const chars2 = [...s];
237
+ const width_2 = chars2.length;
238
+ const result2 = [];
239
+ let currentSegment2 = chars2[0];
240
+ let previousType = RE_CYRILLIC.test(chars2[0]) ? 1 : RE_LATIN.test(chars2[0]) ? 2 : 0;
241
+ let previousIsUpper2 = chars2[0] === chars2[0].toLocaleUpperCase(locale);
242
+ for (let index = 1; index < width_2; index++) {
243
+ const char = chars2[index];
244
+ const currentType = RE_CYRILLIC.test(char) ? 1 : RE_LATIN.test(char) ? 2 : 0;
245
+ const isUpper = char === char.toLocaleUpperCase(locale);
246
+ if (previousType !== currentType && (previousType === 1 || previousType === 2) && (currentType === 1 || currentType === 2) || currentType === previousType && !previousIsUpper2 && isUpper) {
247
+ result2.push(currentSegment2);
248
+ currentSegment2 = char;
249
+ } else {
250
+ currentSegment2 += char;
251
+ }
252
+ previousType = currentType;
253
+ previousIsUpper2 = isUpper;
254
+ }
255
+ if (currentSegment2 && currentSegment2.length > 0) {
256
+ result2.push(currentSegment2);
257
+ }
258
+ const finalResult = [];
259
+ for (let index = 0; index < result2.length; index++) {
260
+ if (index < result2.length - 1 && // eslint-disable-next-line security/detect-object-injection
261
+ result2[index].length === 1 && // eslint-disable-next-line security/detect-object-injection
262
+ RE_LATIN.test(result2[index]) && RE_CYRILLIC.test(result2[index + 1][0])) {
263
+ finalResult.push(result2[index] + result2[index + 1]);
264
+ index++;
265
+ } else {
266
+ finalResult.push(result2[index]);
267
+ }
268
+ }
269
+ return finalResult;
270
+ }
271
+ if (locale.startsWith("el")) {
272
+ if (!RE_GREEK.test(s) && !RE_LATIN.test(s)) {
273
+ return [s];
274
+ }
275
+ const parts = s.match(RE_GREEK_LATIN_SPLIT) ?? [s];
276
+ const result2 = [];
277
+ const width = parts.length;
278
+ if (width === 1) {
279
+ const part = parts[0];
280
+ if (!part || !RE_GREEK.test(part[0]) || part.length === 1) {
281
+ return [part || s];
282
+ }
283
+ }
284
+ for (const part of parts) {
285
+ if (!part) {
286
+ continue;
287
+ }
288
+ if (!RE_GREEK.test(part[0]) || part.length === 1) {
289
+ result2.push(part);
290
+ continue;
291
+ }
292
+ const partLength = part.length;
293
+ let word = part[0];
294
+ let previousIsUpper2 = part[0] === part[0].toLocaleUpperCase(locale);
295
+ for (let index = 1; index < partLength; index++) {
296
+ const char = part[index];
297
+ const isUpper = char === char.toLocaleUpperCase(locale);
298
+ if (!previousIsUpper2 && isUpper) {
299
+ result2.push(word);
300
+ word = char;
301
+ } else {
302
+ word += char;
303
+ }
304
+ previousIsUpper2 = isUpper;
305
+ }
306
+ if (word) {
307
+ result2.push(word);
308
+ }
309
+ }
310
+ return result2;
311
+ }
312
+ if (locale.startsWith("ja") || locale.startsWith("ko")) {
313
+ const isJapanese = locale.startsWith("ja");
314
+ const scriptDetectors = isJapanese ? {
315
+ hiragana: /* @__PURE__ */ __name((char) => RE_HIRAGANA.test(char), "hiragana"),
316
+ kanji: /* @__PURE__ */ __name((char) => RE_KANJI.test(char), "kanji"),
317
+ katakana: /* @__PURE__ */ __name((char) => RE_KATAKANA.test(char), "katakana"),
318
+ latin: /* @__PURE__ */ __name((char) => RE_LATIN.test(char), "latin")
319
+ } : {
320
+ hangul: /* @__PURE__ */ __name((char) => RE_HANGUL.test(char), "hangul"),
321
+ latin: /* @__PURE__ */ __name((char) => RE_LATIN.test(char), "latin")
322
+ };
323
+ const particles = /* @__PURE__ */ new Set(["と", "に", "へ", "を", "は", "が", "の", "で", "や", "も"]);
324
+ if (isJapanese) {
325
+ const baseSegments = handleScriptTransitions(
326
+ s,
327
+ scriptDetectors,
328
+ false,
329
+ locale,
330
+ (previousType, currentType) => previousType === "hiragana" && currentType === "katakana" || // hiragana -> katakana
331
+ previousType === "katakana" && currentType === "hiragana" || // katakana -> hiragana
332
+ previousType === "hiragana" && currentType === "latin" || // hiragana -> latin
333
+ previousType === "katakana" && currentType === "latin" || // katakana -> latin
334
+ previousType === "kanji" && currentType === "latin" || // kanji -> latin
335
+ previousType === "latin" && (currentType === "hiragana" || currentType === "katakana" || currentType === "kanji")
336
+ // latin -> japanese
337
+ );
338
+ const result2 = [];
339
+ for (const segment of baseSegments) {
340
+ if (segment.length === 1 && particles.has(segment) && result2.length > 0) {
341
+ result2[result2.length - 1] += segment;
342
+ } else {
343
+ result2.push(segment);
344
+ }
345
+ }
346
+ return result2.length > 0 ? result2 : [s];
347
+ }
348
+ return handleScriptTransitions(
349
+ s,
350
+ scriptDetectors,
351
+ false,
352
+ locale,
353
+ (previousType, currentType) => previousType === "hangul" && currentType === "latin" || // hangul -> latin
354
+ previousType === "latin" && currentType === "hangul"
355
+ // latin -> hangul
356
+ );
357
+ }
358
+ if (locale.startsWith("sl")) {
359
+ const chars2 = [...s];
360
+ const width_2 = chars2.length;
361
+ const result2 = [];
362
+ let currentSegment2 = chars2[0];
363
+ let previousIsUpper2 = chars2[0] === chars2[0].toLocaleUpperCase(locale);
364
+ for (let index = 1; index < width_2; index++) {
365
+ const char = chars2[index];
366
+ const isUpper = char === char.toLocaleUpperCase(locale);
367
+ const isSpecialChar = /[ČŠŽĐ]/i.test(char);
368
+ const nextIsUpper = index < width_2 - 1 && chars2[index + 1] === chars2[index + 1].toLocaleUpperCase(locale);
369
+ if (!previousIsUpper2 && isUpper || isSpecialChar && nextIsUpper) {
370
+ result2.push(currentSegment2);
371
+ currentSegment2 = char;
372
+ if (isSpecialChar && nextIsUpper) {
373
+ result2.push(currentSegment2);
374
+ currentSegment2 = "";
375
+ }
376
+ } else {
377
+ currentSegment2 += char;
378
+ }
379
+ previousIsUpper2 = isUpper;
380
+ }
381
+ if (currentSegment2 && currentSegment2.length > 0) {
382
+ result2.push(currentSegment2);
383
+ }
384
+ return result2;
385
+ }
386
+ if (locale.startsWith("zh")) {
387
+ return handleScriptTransitions(
388
+ s,
389
+ {
390
+ han: /* @__PURE__ */ __name((char) => RE_KANJI.test(char), "han"),
391
+ latin: /* @__PURE__ */ __name((char) => RE_LATIN.test(char), "latin")
392
+ },
393
+ false,
394
+ locale
395
+ );
396
+ }
397
+ if (["ar", "fa", "he", "ur"].includes(locale.split("-")[0])) {
398
+ const isRtlChar = /* @__PURE__ */ __name((ch) => RE_HEBREW.test(ch) || RE_ARABIC.test(ch), "isRtlChar");
399
+ return handleScriptTransitions(
400
+ s,
401
+ {
402
+ latin: /* @__PURE__ */ __name((char) => RE_LATIN.test(char), "latin"),
403
+ rtl: /* @__PURE__ */ __name((char) => isRtlChar(char), "rtl")
404
+ },
405
+ false,
406
+ locale
407
+ );
408
+ }
409
+ if ([
410
+ "am",
411
+ // Amharic
412
+ "bn",
413
+ // Bengali
414
+ "gu",
415
+ // Gujarati
416
+ "hi",
417
+ // Hindi
418
+ "km",
419
+ // Khmer
420
+ "kn",
421
+ // Kannada
422
+ "lo",
423
+ // Lao
424
+ "ml",
425
+ // Malayalam
426
+ "mr",
427
+ // Marathi
428
+ "ne",
429
+ // Nepali
430
+ "or",
431
+ // Oriya
432
+ "pa",
433
+ // Punjabi
434
+ "si",
435
+ // Sinhala
436
+ "ta",
437
+ // Tamil
438
+ "te",
439
+ // Telugu
440
+ "th"
441
+ // Thai
442
+ ].includes(locale.split("-")[0])) {
443
+ const isIndicChar = /* @__PURE__ */ __name((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), "isIndicChar");
444
+ return handleScriptTransitions(
445
+ s,
446
+ {
447
+ indic: /* @__PURE__ */ __name((char) => isIndicChar(char), "indic"),
448
+ latin: /* @__PURE__ */ __name((char) => RE_LATIN.test(char), "latin")
449
+ },
450
+ false,
451
+ locale
452
+ );
453
+ }
454
+ if (["be", "bg", "ru", "sr", "uk"].includes(locale)) {
455
+ return handleScriptTransitions(
456
+ s,
457
+ {
458
+ cyrillic: /* @__PURE__ */ __name((char) => RE_CYRILLIC.test(char), "cyrillic"),
459
+ latin: /* @__PURE__ */ __name((char) => RE_LATIN.test(char), "latin")
460
+ },
461
+ true,
462
+ // Enable case-sensitive splitting
463
+ locale
464
+ );
465
+ }
466
+ if (["ar", "fa", "he"].includes(locale)) {
467
+ return handleScriptTransitions(
468
+ s,
469
+ {
470
+ latin: /* @__PURE__ */ __name((char) => RE_LATIN.test(char), "latin"),
471
+ rtl: /* @__PURE__ */ __name((char) => RE_HEBREW.test(char) || RE_ARABIC.test(char), "rtl")
472
+ },
473
+ false,
474
+ locale
475
+ );
476
+ }
477
+ if (locale.startsWith("ko")) {
478
+ return handleScriptTransitions(
479
+ s,
480
+ {
481
+ hangul: /* @__PURE__ */ __name((char) => RE_HANGUL.test(char), "hangul"),
482
+ latin: /* @__PURE__ */ __name((char) => RE_LATIN.test(char), "latin")
483
+ },
484
+ false,
485
+ locale
486
+ );
487
+ }
488
+ if (locale.startsWith("uz")) {
489
+ if (!RE_CYRILLIC.test(s) && !RE_LATIN.test(s)) {
490
+ return [s];
491
+ }
492
+ const chars2 = [...s];
493
+ const width_2 = chars2.length;
494
+ const result2 = [];
495
+ let currentSegment2 = chars2[0];
496
+ let previousIsUpper2 = chars2[0] === chars2[0].toLocaleUpperCase(locale);
497
+ for (let index = 1; index < width_2; index++) {
498
+ const char = chars2[index];
499
+ const isUpper = char === char.toLocaleUpperCase(locale);
500
+ if (RE_UZBEK_LATIN_MODIFIER.test(char) || RE_UZBEK_LATIN_MODIFIER.test(chars2[index - 1])) {
501
+ currentSegment2 += char;
502
+ continue;
503
+ }
504
+ if (!previousIsUpper2 && isUpper) {
505
+ result2.push(currentSegment2);
506
+ currentSegment2 = char;
507
+ } else {
508
+ currentSegment2 += char;
509
+ }
510
+ previousIsUpper2 = isUpper;
511
+ }
512
+ if (currentSegment2 && currentSegment2.length > 0) {
513
+ result2.push(currentSegment2);
514
+ }
515
+ return result2;
516
+ }
517
+ const chars = [...s];
518
+ const width_ = chars.length;
519
+ const result = [];
520
+ let currentSegment = chars[0];
521
+ let previousIsUpper = chars[0] === chars[0].toLocaleUpperCase(locale);
522
+ for (const acronym of knownAcronyms) {
523
+ if (s.startsWith(acronym)) {
524
+ result.push(acronym);
525
+ currentSegment = chars[acronym.length];
526
+ previousIsUpper = currentSegment === currentSegment.toLocaleUpperCase(locale);
527
+ break;
528
+ }
529
+ }
530
+ for (let index = 1; index < width_; index++) {
531
+ const char = chars[index];
532
+ const isUpper = char === char.toLocaleUpperCase(locale);
533
+ let isAcronym = false;
534
+ for (const acronym of knownAcronyms) {
535
+ if (s.startsWith(acronym, index)) {
536
+ result.push(currentSegment, acronym);
537
+ index += acronym.length - 1;
538
+ currentSegment = "";
539
+ isAcronym = true;
540
+ break;
541
+ }
542
+ }
543
+ if (isAcronym) {
544
+ continue;
545
+ }
546
+ if (!previousIsUpper && isUpper) {
547
+ result.push(currentSegment);
548
+ currentSegment = char;
549
+ } else {
550
+ currentSegment += char;
551
+ }
552
+ previousIsUpper = isUpper;
553
+ }
554
+ if (currentSegment) {
555
+ result.push(currentSegment);
556
+ }
557
+ return result;
558
+ }, "splitCamelCaseLocale");
559
+ const processTextWithAnsiEmoji = /* @__PURE__ */ __name((text, locale, knownAcronyms) => {
560
+ const result = [];
561
+ const segments = RE_FAST_ANSI.test(text) ? text.split(RE_FAST_ANSI).filter(Boolean) : [text];
562
+ for (const seg of segments) {
563
+ if (RE_FAST_ANSI.test(seg)) {
564
+ result.push(seg);
565
+ } else {
566
+ const subs = RE_EMOJI.test(seg) ? splitByEmoji(seg).filter(Boolean) : [seg];
567
+ for (const sub of subs) {
568
+ if (RE_EMOJI.test(sub)) {
569
+ result.push(sub);
570
+ } else {
571
+ if (locale) {
572
+ const normalizedLocale = locale.toLowerCase().split("-")[0];
573
+ result.push(...splitCamelCaseLocale(sub, normalizedLocale, knownAcronyms));
574
+ } else {
575
+ result.push(...splitCamelCaseFast(sub, knownAcronyms));
576
+ }
577
+ }
578
+ }
579
+ }
580
+ }
581
+ return result;
582
+ }, "processTextWithAnsiEmoji");
583
+ const splitByCase = /* @__PURE__ */ __name((input, options = {}) => {
584
+ if (!input || typeof input !== "string") {
585
+ return [];
586
+ }
587
+ const {
588
+ handleAnsi = false,
589
+ handleEmoji = false,
590
+ knownAcronyms = [],
591
+ locale,
592
+ normalize = false,
593
+ separators,
594
+ stripAnsi: stripAnsiOption = false,
595
+ stripEmoji: stripEmojiOption = false
596
+ } = options;
597
+ const acronymSet = new Set([...knownAcronyms].sort((a, b) => b.length - a.length));
598
+ let cleanedInput = input;
599
+ if (stripAnsiOption) {
600
+ cleanedInput = stripVTControlCharacters(cleanedInput);
601
+ }
602
+ if (stripEmojiOption) {
603
+ cleanedInput = stripEmoji(cleanedInput);
604
+ }
605
+ const separatorRegex = Array.isArray(separators) ? getSeparatorsRegex(separators) : separators instanceof RegExp ? separators : RE_SEPARATORS;
606
+ const parts = cleanedInput.split(separatorRegex).filter(Boolean);
607
+ let tokens = [];
608
+ for (const part of parts) {
609
+ if (handleAnsi || handleEmoji) {
610
+ tokens.push(...processTextWithAnsiEmoji(part, locale, acronymSet));
611
+ } else if (locale) {
612
+ tokens.push(...splitCamelCaseLocale(part, locale, acronymSet));
613
+ } else {
614
+ tokens.push(...splitCamelCaseFast(part, acronymSet));
615
+ }
616
+ }
617
+ if (normalize) {
618
+ tokens = tokens.map((token) => {
619
+ if (acronymSet.has(token)) {
620
+ return token;
621
+ }
622
+ if (locale && token === token.toLocaleUpperCase(locale)) {
623
+ return token[0] + token.slice(1).toLocaleLowerCase(locale);
624
+ }
625
+ if (token.toUpperCase() === token && !acronymSet.has(token)) {
626
+ return token.slice(0, 1) + token.slice(1).toLowerCase();
627
+ }
628
+ return token;
629
+ });
630
+ }
631
+ return tokens;
632
+ }, "splitByCase");
633
+
634
+ export { splitByCase };
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ const LRUCache = require('../packem_shared/LRUCache-Crb-m7cw.cjs');
4
+ const case_splitByCase = require('./split-by-case.cjs');
5
+ const case_upperFirst = require('./upper-first.cjs');
6
+ const generateCacheKey = require('../packem_shared/generate-cache-key-D8f1auDB.cjs');
7
+ const normalizeGermanEszett = require('../packem_shared/normalize-german-eszett-DJK0S2qj.cjs');
8
+
9
+ var __defProp = Object.defineProperty;
10
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
11
+ const defaultCacheStore = new LRUCache(1e3);
12
+ function titleCase(value, options) {
13
+ if (typeof value !== "string") {
14
+ return "";
15
+ }
16
+ const shouldCache = options?.cache ?? false;
17
+ const cacheStore = options?.cacheStore ?? defaultCacheStore;
18
+ let cacheKey;
19
+ if (shouldCache) {
20
+ cacheKey = generateCacheKey.generateCacheKey(value, options);
21
+ }
22
+ if (shouldCache && cacheKey && cacheStore.has(cacheKey)) {
23
+ return cacheStore.get(cacheKey);
24
+ }
25
+ const result = case_splitByCase.splitByCase(value, {
26
+ handleAnsi: options?.handleAnsi,
27
+ handleEmoji: options?.handleEmoji,
28
+ knownAcronyms: options?.knownAcronyms,
29
+ locale: options?.locale,
30
+ normalize: options?.normalize,
31
+ separators: void 0,
32
+ stripAnsi: options?.stripAnsi,
33
+ stripEmoji: options?.stripEmoji
34
+ }).map((word) => {
35
+ if (options?.locale?.startsWith("de")) {
36
+ word = normalizeGermanEszett.normalizeGermanEszett(word);
37
+ }
38
+ return case_upperFirst(options?.locale ? word.toLocaleLowerCase(options.locale) : word.toLowerCase(), { locale: options?.locale });
39
+ }).join(" ");
40
+ if (shouldCache && cacheKey) {
41
+ cacheStore.set(cacheKey, result);
42
+ }
43
+ return result;
44
+ }
45
+ __name(titleCase, "titleCase");
46
+
47
+ module.exports = titleCase;
@@ -0,0 +1,7 @@
1
+ import { b as CaseOptions, T as TitleCase } from '../packem_shared/types-D2-6p7t1.cjs';
2
+ import '../packem_shared/types-BNbQJg02.cjs';
3
+ import '../utils.cjs';
4
+
5
+ declare function titleCase<T extends string = string>(value?: T, options?: CaseOptions): TitleCase<T>;
6
+
7
+ export = titleCase;
@@ -0,0 +1,7 @@
1
+ import { b as CaseOptions, T as TitleCase } from '../packem_shared/types-BAd3WDHo.mjs';
2
+ import '../packem_shared/types-BNbQJg02.mjs';
3
+ import '../utils.mjs';
4
+
5
+ declare function titleCase<T extends string = string>(value?: T, options?: CaseOptions): TitleCase<T>;
6
+
7
+ export { titleCase as default };