@visulima/string 2.0.2 → 2.0.4

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