@visulima/string 2.0.3 → 2.0.5

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 (56) hide show
  1. package/CHANGELOG.md +31 -0
  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/native-string-types.d.ts +3 -1
  29. package/dist/outdent.js +117 -1
  30. package/dist/packem_shared/LRUCache-3r3SovvR.js +46 -0
  31. package/dist/packem_shared/closest-IHuSvnSn.js +139 -0
  32. package/dist/packem_shared/closestN-BREy4E7C.js +19 -0
  33. package/dist/packem_shared/constants-CTzC6Gjg.js +95 -0
  34. package/dist/packem_shared/generate-cache-key-DdayDfjV.js +6 -0
  35. package/dist/packem_shared/joinSegments-CuU8RGpP.js +44 -0
  36. package/dist/packem_shared/normalize-german-eszett-DEB8-ZPT.js +7 -0
  37. package/dist/packem_shared/replaceString-vYvRBMfC.js +190 -0
  38. package/dist/packem_shared/transliterate-CYnKKT8f.js +47758 -0
  39. package/dist/slice.js +413 -1
  40. package/dist/slugify.js +46 -1
  41. package/dist/test/utils.js +88 -13
  42. package/dist/test/vitest.js +5 -1
  43. package/dist/truncate.js +89 -1
  44. package/dist/utilities.js +54 -1
  45. package/dist/word-similarity-sort.js +22 -1
  46. package/dist/word-wrap.js +637 -8
  47. package/package.json +1 -1
  48. package/dist/packem_shared/LRUCache-Bjo6gsbC.js +0 -1
  49. package/dist/packem_shared/closest-uarbVSbs.js +0 -1
  50. package/dist/packem_shared/closestN-DjNxwK0t.js +0 -1
  51. package/dist/packem_shared/constants-CDcaCZKC.js +0 -1
  52. package/dist/packem_shared/generate-cache-key-DPByFaMH.js +0 -1
  53. package/dist/packem_shared/joinSegments-DTGeJBZG.js +0 -1
  54. package/dist/packem_shared/normalize-german-eszett-4k1qRtEP.js +0 -1
  55. package/dist/packem_shared/replaceString-DwIZyvoL.js +0 -1
  56. package/dist/packem_shared/transliterate-CxVHmZUa.js +0 -5
package/dist/outdent.js CHANGED
@@ -1 +1,117 @@
1
- var L=Object.defineProperty;var h=(e,n)=>L(e,"name",{value:n,configurable:!0});import{d as R,e as S,f as m,g as W,h as y,i as O}from"./packem_shared/constants-CDcaCZKC.js";var d=Object.defineProperty,g=h((e,n)=>d(e,"name",{value:n,configurable:!0}),"c");const x=Object.prototype.hasOwnProperty,A=g((e,n)=>x.call(e,n),"has"),T=g((e,n)=>{for(const r in n)A(n,r)&&(e[r]=n[r]);return e},"extend"),p=g((e,n,r)=>{if(e.length===0)return[];let t=0;const a=O.exec(e[0]);a&&(t=a[1].length);const i=`(\\r\\n|\\r|\\n).{0,${t}}`,c=new RegExp(i,"g");n&&(e=e.slice(1));const{newline:l,trimLeadingNewline:_,trimTrailingNewline:N}=r,o=typeof l=="string",E=e.length,f=Array.from({length:E});for(let u=0;u<E;u++){let s=e[u];s=s.replace(c,"$1"),u===0&&_&&(s=s.replace(m,"")),u===E-1&&N&&(s=s.replace(W,"")),o&&(s=s.replaceAll(y,l)),f[u]=s}return f},"internalOutdentArray"),b=g((e,n)=>{const r=Array.from({length:e.length+n.length});let t=0;const a=e.length;for(;t<a-1;t++)r[t*2]=e[t],r[t*2+1]=String(n[t]);return r[t*2]=e[t],r.join("")},"concatStringsAndValues"),v=g(e=>A(e,"raw")&&A(e,"length"),"isTemplateStringsArray"),H=new WeakMap,I=g(e=>{const n=e.cache!==!1,r=n?e.cacheStore??H:null,t=e.newline!==void 0;function a(i,...c){if(v(i)){const l=i,_=c.length;if(l.length===1&&l[0]==="")return"";if(_===0){if(n&&r&&!t){const f=r.get(l);if(f)return f[0]}const E=p(l,!1,e);return n&&r&&r.set(l,E),E[0]}const N=(c[0]===a||c[0]===w)&&R.test(l[0])&&S.test(l[1]);let o;return n&&r&&!t&&(o=r.get(l)),o||(o=p(l,N,e),n&&r&&r.set(l,o)),b(o,N?c.slice(1):c)}return I(T(T({},e),i))}return h(a,"g"),g(a,"outdent"),T(a,{string(i){return i===""||!i?"":p([i],!1,e)[0]}})},"createInstance"),w=I({cache:!0,newline:null,trimLeadingNewline:!0,trimTrailingNewline:!0}),C=w;export{C as outdent};
1
+ import { d as RE_LEADING_NEWLINE, e as RE_TRAILING_NEWLINE, f as RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE, g as RE_STARTS_WITH_NEWLINE_OR_IS_EMPTY, h as RE_DETECT_INDENTATION, i as RE_MATCH_NEWLINES } from './packem_shared/constants-CTzC6Gjg.js';
2
+
3
+ const hop = Object.prototype.hasOwnProperty;
4
+ const has = (object, property) => hop.call(object, property);
5
+ const extend = (target, source) => {
6
+ for (const property of Object.keys(source)) {
7
+ target[property] = source[property];
8
+ }
9
+ return target;
10
+ };
11
+ const internalOutdentArray = (strings, firstInterpolatedValueSetsIndentationLevel, options) => {
12
+ if (strings.length === 0) {
13
+ return [];
14
+ }
15
+ let indentationLevel = 0;
16
+ const match = RE_DETECT_INDENTATION.exec(strings[0]);
17
+ if (match) {
18
+ indentationLevel = match[1].length;
19
+ }
20
+ const reSource = `(\\r\\n|\\r|\\n).{0,${indentationLevel}}`;
21
+ const reMatchIndent = new RegExp(reSource, "g");
22
+ if (firstInterpolatedValueSetsIndentationLevel) {
23
+ strings = strings.slice(1);
24
+ }
25
+ const { newline, trimLeadingNewline, trimTrailingNewline } = options;
26
+ const normalizeNewlines = typeof newline === "string";
27
+ const l = strings.length;
28
+ const outdentedStrings = Array.from({ length: l });
29
+ for (let index = 0; index < l; index++) {
30
+ let v = strings[index];
31
+ v = v.replace(reMatchIndent, "$1");
32
+ if (index === 0 && trimLeadingNewline) {
33
+ v = v.replace(RE_LEADING_NEWLINE, "");
34
+ }
35
+ if (index === l - 1 && trimTrailingNewline) {
36
+ v = v.replace(RE_TRAILING_NEWLINE, "");
37
+ }
38
+ if (normalizeNewlines) {
39
+ v = v.replaceAll(RE_MATCH_NEWLINES, newline);
40
+ }
41
+ outdentedStrings[index] = v;
42
+ }
43
+ return outdentedStrings;
44
+ };
45
+ const concatStringsAndValues = (strings, values) => {
46
+ const chunks = Array.from({ length: strings.length + values.length });
47
+ let index = 0;
48
+ const l = strings.length;
49
+ for (; index < l - 1; index++) {
50
+ chunks[index * 2] = strings[index];
51
+ chunks[index * 2 + 1] = String(values[index]);
52
+ }
53
+ chunks[index * 2] = strings[index];
54
+ return chunks.join("");
55
+ };
56
+ const isTemplateStringsArray = (v) => has(v, "raw") && has(v, "length");
57
+ const templateCache = /* @__PURE__ */ new WeakMap();
58
+ const createInstance = (options) => {
59
+ const enableCache = options.cache !== false;
60
+ const cache = enableCache ? options.cacheStore ?? templateCache : null;
61
+ const hasNewlineOption = options.newline !== void 0;
62
+ function outdent2(stringsOrOptions, ...values) {
63
+ if (isTemplateStringsArray(stringsOrOptions)) {
64
+ const strings = stringsOrOptions;
65
+ const valuesLength = values.length;
66
+ if (strings.length === 1 && strings[0] === "") {
67
+ return "";
68
+ }
69
+ if (valuesLength === 0) {
70
+ if (enableCache && cache && !hasNewlineOption) {
71
+ const cached = cache.get(strings);
72
+ if (cached) {
73
+ return cached[0];
74
+ }
75
+ }
76
+ const result = internalOutdentArray(strings, false, options);
77
+ if (enableCache && cache) {
78
+ cache.set(strings, result);
79
+ }
80
+ return result[0];
81
+ }
82
+ const firstValueIsOutdent = values[0] === outdent2 || values[0] === defaultOutdent;
83
+ const firstInterpolatedValueSetsIndentationLevel = firstValueIsOutdent && RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE.test(strings[0]) && RE_STARTS_WITH_NEWLINE_OR_IS_EMPTY.test(strings[1]);
84
+ let renderedArray;
85
+ if (enableCache && cache && !hasNewlineOption) {
86
+ renderedArray = cache.get(strings);
87
+ }
88
+ if (!renderedArray) {
89
+ renderedArray = internalOutdentArray(strings, firstInterpolatedValueSetsIndentationLevel, options);
90
+ if (enableCache && cache) {
91
+ cache.set(strings, renderedArray);
92
+ }
93
+ }
94
+ return concatStringsAndValues(renderedArray, firstInterpolatedValueSetsIndentationLevel ? values.slice(1) : values);
95
+ }
96
+ return createInstance(extend(extend({}, options), stringsOrOptions));
97
+ }
98
+ return extend(outdent2, {
99
+ string(string_) {
100
+ if (string_ === "" || !string_) {
101
+ return "";
102
+ }
103
+ return internalOutdentArray([string_], false, options)[0];
104
+ }
105
+ });
106
+ };
107
+ const defaultOutdent = createInstance({
108
+ cache: true,
109
+ // Enable caching by default
110
+ // eslint-disable-next-line unicorn/no-null
111
+ newline: null,
112
+ trimLeadingNewline: true,
113
+ trimTrailingNewline: true
114
+ });
115
+ const outdent = defaultOutdent;
116
+
117
+ export { outdent };
@@ -0,0 +1,46 @@
1
+ class LRUCache {
2
+ capacity;
3
+ cache;
4
+ keyOrder;
5
+ constructor(capacity) {
6
+ this.capacity = capacity;
7
+ this.cache = /* @__PURE__ */ new Map();
8
+ this.keyOrder = [];
9
+ }
10
+ get(key) {
11
+ if (!this.cache.has(key)) {
12
+ return void 0;
13
+ }
14
+ this.keyOrder = this.keyOrder.filter((k) => k !== key);
15
+ this.keyOrder.push(key);
16
+ return this.cache.get(key);
17
+ }
18
+ has(key) {
19
+ return this.cache.has(key);
20
+ }
21
+ set(key, value) {
22
+ if (this.cache.has(key)) {
23
+ this.keyOrder = this.keyOrder.filter((k) => k !== key);
24
+ } else if (this.cache.size >= this.capacity) {
25
+ const lruKey = this.keyOrder.shift();
26
+ if (lruKey !== void 0) {
27
+ this.cache.delete(lruKey);
28
+ }
29
+ }
30
+ this.cache.set(key, value);
31
+ this.keyOrder.push(key);
32
+ }
33
+ delete(key) {
34
+ this.cache.delete(key);
35
+ this.keyOrder = this.keyOrder.filter((k) => k !== key);
36
+ }
37
+ clear() {
38
+ this.cache.clear();
39
+ this.keyOrder = [];
40
+ }
41
+ size() {
42
+ return this.cache.size;
43
+ }
44
+ }
45
+
46
+ export { LRUCache as default };
@@ -0,0 +1,139 @@
1
+ const peq = new Uint32Array(65536);
2
+ const myers_32 = (a, b) => {
3
+ const n = a.length;
4
+ const m = b.length;
5
+ const lst = 1 << n - 1;
6
+ let pv = -1;
7
+ let mv = 0;
8
+ let sc = n;
9
+ let i = n;
10
+ while (i--) {
11
+ peq[a.charCodeAt(i)] |= 1 << i;
12
+ }
13
+ for (i = 0; i < m; i++) {
14
+ let eq = peq[b.charCodeAt(i)];
15
+ const xv = eq | mv;
16
+ eq |= (eq & pv) + pv ^ pv;
17
+ mv |= ~(eq | pv);
18
+ pv &= eq;
19
+ if (mv & lst) {
20
+ sc++;
21
+ }
22
+ if (pv & lst) {
23
+ sc--;
24
+ }
25
+ mv = mv << 1 | 1;
26
+ pv = pv << 1 | ~(xv | mv);
27
+ mv &= xv;
28
+ }
29
+ i = n;
30
+ while (i--) {
31
+ peq[a.charCodeAt(i)] = 0;
32
+ }
33
+ return sc;
34
+ };
35
+ const myers_x = (b, a) => {
36
+ const n = a.length;
37
+ const m = b.length;
38
+ const mhc = [];
39
+ const phc = [];
40
+ const hsize = Math.ceil(n / 32);
41
+ const vsize = Math.ceil(m / 32);
42
+ for (let i = 0; i < hsize; i++) {
43
+ phc[i] = -1;
44
+ mhc[i] = 0;
45
+ }
46
+ let j = 0;
47
+ for (; j < vsize - 1; j++) {
48
+ let mv2 = 0;
49
+ let pv2 = -1;
50
+ const start2 = j * 32;
51
+ const vlen2 = Math.min(32, m) + start2;
52
+ for (let k = start2; k < vlen2; k++) {
53
+ peq[b.charCodeAt(k)] |= 1 << k;
54
+ }
55
+ for (let i = 0; i < n; i++) {
56
+ const eq = peq[a.charCodeAt(i)];
57
+ const pb = phc[i / 32 | 0] >>> i & 1;
58
+ const mb = mhc[i / 32 | 0] >>> i & 1;
59
+ const xv = eq | mv2;
60
+ const xh = ((eq | mb) & pv2) + pv2 ^ pv2 | eq | mb;
61
+ let ph = mv2 | ~(xh | pv2);
62
+ let mh = pv2 & xh;
63
+ if (ph >>> 31 ^ pb) {
64
+ phc[i / 32 | 0] ^= 1 << i;
65
+ }
66
+ if (mh >>> 31 ^ mb) {
67
+ mhc[i / 32 | 0] ^= 1 << i;
68
+ }
69
+ ph = ph << 1 | pb;
70
+ mh = mh << 1 | mb;
71
+ pv2 = mh | ~(xv | ph);
72
+ mv2 = ph & xv;
73
+ }
74
+ for (let k = start2; k < vlen2; k++) {
75
+ peq[b.charCodeAt(k)] = 0;
76
+ }
77
+ }
78
+ let mv = 0;
79
+ let pv = -1;
80
+ const start = j * 32;
81
+ const vlen = Math.min(32, m - start) + start;
82
+ for (let k = start; k < vlen; k++) {
83
+ peq[b.charCodeAt(k)] |= 1 << k;
84
+ }
85
+ let score = m;
86
+ for (let i = 0; i < n; i++) {
87
+ const eq = peq[a.charCodeAt(i)];
88
+ const pb = phc[i / 32 | 0] >>> i & 1;
89
+ const mb = mhc[i / 32 | 0] >>> i & 1;
90
+ const xv = eq | mv;
91
+ const xh = ((eq | mb) & pv) + pv ^ pv | eq | mb;
92
+ let ph = mv | ~(xh | pv);
93
+ let mh = pv & xh;
94
+ score += ph >>> m - 1 & 1;
95
+ score -= mh >>> m - 1 & 1;
96
+ if (ph >>> 31 ^ pb) {
97
+ phc[i / 32 | 0] ^= 1 << i;
98
+ }
99
+ if (mh >>> 31 ^ mb) {
100
+ mhc[i / 32 | 0] ^= 1 << i;
101
+ }
102
+ ph = ph << 1 | pb;
103
+ mh = mh << 1 | mb;
104
+ pv = mh | ~(xv | ph);
105
+ mv = ph & xv;
106
+ }
107
+ for (let k = start; k < vlen; k++) {
108
+ peq[b.charCodeAt(k)] = 0;
109
+ }
110
+ return score;
111
+ };
112
+ const distance = (a, b) => {
113
+ if (a.length < b.length) {
114
+ const tmp = b;
115
+ b = a;
116
+ a = tmp;
117
+ }
118
+ if (b.length === 0) {
119
+ return a.length;
120
+ }
121
+ if (a.length <= 32) {
122
+ return myers_32(a, b);
123
+ }
124
+ return myers_x(a, b);
125
+ };
126
+ const closest = (str, arr) => {
127
+ let min_distance = Infinity;
128
+ let min_index = 0;
129
+ for (let i = 0; i < arr.length; i++) {
130
+ const dist = distance(str, arr[i]);
131
+ if (dist < min_distance) {
132
+ min_distance = dist;
133
+ min_index = i;
134
+ }
135
+ }
136
+ return arr[min_index];
137
+ };
138
+
139
+ export { closest, distance };
@@ -0,0 +1,19 @@
1
+ import { distance } from './closest-IHuSvnSn.js';
2
+ export { closest } from './closest-IHuSvnSn.js';
3
+
4
+ const closestN = (string_, array, n) => {
5
+ const distances = new Array(n).fill(Infinity);
6
+ const values = new Array(n).fill(null);
7
+ for (let value of array) {
8
+ let distribution = distance(string_, value);
9
+ for (let index = 0; index < n; index++) {
10
+ if (distribution < distances[index]) {
11
+ [distribution, distances[index]] = [distances[index], distribution];
12
+ [value, values[index]] = [values[index], value];
13
+ }
14
+ }
15
+ }
16
+ return values;
17
+ };
18
+
19
+ export { closestN, distance };
@@ -0,0 +1,95 @@
1
+ const r = String.raw;
2
+ const e = r`\p{Emoji}(?:\p{EMod}|[\u{E0020}-\u{E007E}]+\u{E007F}|\uFE0F?\u20E3?)`;
3
+ const emojiRegex = () => new RegExp(r`\p{RI}{2}|(?![#*\d](?!\uFE0F?\u20E3))${e}(?:\u200D${e})*`, "gu");
4
+
5
+ const ESCAPES = /* @__PURE__ */ new Set(["\x1B", "›"]);
6
+ const ANSI_ESCAPE_BELL = "\x07";
7
+ const ANSI_CSI = "[";
8
+ const ANSI_SGR_TERMINATOR = "m";
9
+ const ANSI_ESCAPE_LINK = `]8;;`;
10
+ const END_CODE = 39;
11
+ const RE_ZERO_WIDTH = /[\u200B\uFEFF\u2060-\u2064]/g;
12
+ const RE_ESCAPE_PATTERN = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`);
13
+ const ANSI_RESET_CODES = Object.freeze(
14
+ /* @__PURE__ */ new Map([
15
+ [0, 0],
16
+ // Reset all
17
+ [1, 22],
18
+ // Bold → Not bold
19
+ [2, 22],
20
+ // Dim → Not bold
21
+ [3, 23],
22
+ // Italic → Not italic
23
+ [4, 24],
24
+ // Underline → Not underline
25
+ [7, 27],
26
+ // Inverse → Not inverse
27
+ [8, 28],
28
+ // Hidden → Not hidden
29
+ [9, 29],
30
+ // Strikethrough → Not strikethrough
31
+ [30, 39],
32
+ // Foreground colors → Default foreground
33
+ [31, 39],
34
+ [32, 39],
35
+ [33, 39],
36
+ [34, 39],
37
+ [35, 39],
38
+ [36, 39],
39
+ [37, 39],
40
+ [40, 49],
41
+ // Background colors → Default background
42
+ [41, 49],
43
+ [42, 49],
44
+ [43, 49],
45
+ [44, 49],
46
+ [45, 49],
47
+ [46, 49],
48
+ [47, 49],
49
+ [90, 39]
50
+ // Bright foreground → Default foreground
51
+ ])
52
+ );
53
+ const RE_LEADING_NEWLINE = /^[ \t]*(?:\r\n|\r|\n)/;
54
+ const RE_TRAILING_NEWLINE = /(?:\r\n|\r|\n)[ \t]*$/;
55
+ const RE_STARTS_WITH_NEWLINE_OR_IS_EMPTY = /^(?:[\r\n]|$)/;
56
+ const RE_DETECT_INDENTATION = /(?:\r\n|\r|\n)([ \t]*)(?:[^ \t\r\n]|$)/;
57
+ const RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE = /^[ \t]*[\r\n][ \t\r\n]*$/;
58
+ const RE_MATCH_NEWLINES = /\r\n|\n|\r/g;
59
+ const RE_ANSI = /[\u001B\u009B](?:[[()#;?]{0,10}(?:\d{1,4}(?:;\d{0,4})*)?[0-9A-ORZcf-nqry=><]|\]8;;[^\u0007\u001B]{0,100}(?:\u0007|\u001B\\))/g;
60
+ const RE_VALID_ANSI_PAIRS = /\u001B\[(\d+(?:;\d+)*)?m[^\u001B]*(?:\u001B\[(?:\d+(?:;\d+)*)?m|$)/g;
61
+ const RE_VALID_HYPERLINKS = /\u001B\]8;[^\u0007\u001B]*(?:\u0007|\u001B\\)(.*?)\u001B\]8;;(?:\u0007|\u001B\\)/g;
62
+ const RE_CONTROL = /[\u0000-\u0008\n-\u001F\u007F-\u009F]{1,1000}/y;
63
+ const RE_EMOJI = emojiRegex();
64
+ const RE_SEPARATORS = /[-_./\s]+/g;
65
+ const RE_FAST_ANSI = /(\u001B\[[0-9;]*[a-z])/i;
66
+ const RE_ARABIC = new RegExp("\\p{Script=Arabic}", "u");
67
+ const RE_BENGALI = new RegExp("\\p{Script=Bengali}", "u");
68
+ const RE_CYRILLIC = new RegExp("\\p{Script=Cyrillic}", "u");
69
+ const RE_DEVANAGARI = new RegExp("\\p{Script=Devanagari}", "u");
70
+ const RE_ETHIOPIC = new RegExp("\\p{Script=Ethiopic}", "u");
71
+ const RE_GREEK = new RegExp("\\p{Script=Greek}", "u");
72
+ const RE_GREEK_LATIN_SPLIT = new RegExp("\\p{Script=Greek}+|\\p{Script=Latin}+|[^\\p{Script=Greek}\\p{Script=Latin}]+", "gu");
73
+ const RE_GUJARATI = new RegExp("\\p{Script=Gujarati}", "u");
74
+ const RE_GURMUKHI = new RegExp("\\p{Script=Gurmukhi}", "u");
75
+ const RE_HANGUL = new RegExp("\\p{Script=Hangul}", "u");
76
+ const RE_HEBREW = new RegExp("\\p{Script=Hebrew}", "u");
77
+ const RE_HIRAGANA = new RegExp("\\p{Script=Hiragana}", "u");
78
+ const RE_KANJI = new RegExp("\\p{Script=Han}", "u");
79
+ const RE_KANNADA = new RegExp("\\p{Script=Kannada}", "u");
80
+ const RE_KATAKANA = new RegExp("\\p{Script=Katakana}", "u");
81
+ const RE_KHMER = new RegExp("\\p{Script=Khmer}", "u");
82
+ const RE_LAO = new RegExp("\\p{Script=Lao}", "u");
83
+ const RE_LATIN = new RegExp("\\p{Script=Latin}", "u");
84
+ const RE_MALAYALAM = new RegExp("\\p{Script=Malayalam}", "u");
85
+ const RE_MYANMAR = new RegExp("\\p{Script=Myanmar}", "u");
86
+ const RE_ORIYA = new RegExp("\\p{Script=Oriya}", "u");
87
+ const RE_SINHALA = new RegExp("\\p{Script=Sinhala}", "u");
88
+ const RE_TAMIL = new RegExp("\\p{Script=Tamil}", "u");
89
+ const RE_TELUGU = new RegExp("\\p{Script=Telugu}", "u");
90
+ const RE_THAI = new RegExp("\\p{Script=Thai}", "u");
91
+ const RE_TIBETAN = new RegExp("\\p{Script=Tibetan}", "u");
92
+ const RE_UZBEK_LATIN_MODIFIER = /[\u02BB\u02BC\u0027]/u;
93
+ const stripEmoji = (stringValue) => stringValue.replace(RE_EMOJI, "");
94
+
95
+ export { RE_GURMUKHI as A, RE_KANNADA as B, RE_TAMIL as C, RE_TELUGU as D, RE_MALAYALAM as E, RE_SINHALA as F, RE_THAI as G, RE_LAO as H, RE_TIBETAN as I, RE_MYANMAR as J, RE_ETHIOPIC as K, RE_KHMER as L, RE_ORIYA as M, RE_CONTROL as N, ESCAPES as O, ANSI_ESCAPE_LINK as P, ANSI_SGR_TERMINATOR as Q, RE_FAST_ANSI as R, ANSI_ESCAPE_BELL as S, ANSI_CSI as T, RE_ESCAPE_PATTERN as U, ANSI_RESET_CODES as V, END_CODE as W, RE_ZERO_WIDTH as X, RE_VALID_ANSI_PAIRS as a, RE_VALID_HYPERLINKS as b, RE_ANSI as c, RE_LEADING_NEWLINE as d, RE_TRAILING_NEWLINE as e, RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE as f, RE_STARTS_WITH_NEWLINE_OR_IS_EMPTY as g, RE_DETECT_INDENTATION as h, RE_MATCH_NEWLINES as i, RE_EMOJI as j, RE_SEPARATORS as k, RE_CYRILLIC as l, RE_LATIN as m, RE_GREEK as n, RE_GREEK_LATIN_SPLIT as o, RE_UZBEK_LATIN_MODIFIER as p, RE_KATAKANA as q, RE_KANJI as r, stripEmoji as s, RE_HIRAGANA as t, RE_HANGUL as u, RE_HEBREW as v, RE_ARABIC as w, RE_DEVANAGARI as x, RE_BENGALI as y, RE_GUJARATI as z };
@@ -0,0 +1,6 @@
1
+ const generateCacheKey = (value, options) => (
2
+ // Only include options that affect the output
3
+ `${value}::${options?.joiner ?? ""}::${options?.locale ?? ""}::${options?.knownAcronyms?.join(",") ?? ""}::${options?.normalize ? "true" : "false"}`
4
+ );
5
+
6
+ export { generateCacheKey as g };
@@ -0,0 +1,44 @@
1
+ import { R as RE_FAST_ANSI } from './constants-CTzC6Gjg.js';
2
+
3
+ const joinSegments = (segments, joiner) => {
4
+ const { length } = segments;
5
+ if (length === 0) {
6
+ return "";
7
+ }
8
+ if (length === 1) {
9
+ return segments[0];
10
+ }
11
+ const result = [];
12
+ let ansiStart = "";
13
+ let currentContent = "";
14
+ for (let index = 0; index < length; index++) {
15
+ const segment = segments[index];
16
+ if (RE_FAST_ANSI.test(segment)) {
17
+ if (ansiStart) {
18
+ result.push(ansiStart + currentContent + segment);
19
+ ansiStart = "";
20
+ currentContent = "";
21
+ } else {
22
+ if (result.length > 0) {
23
+ result.push(joiner);
24
+ }
25
+ ansiStart = segment;
26
+ }
27
+ continue;
28
+ }
29
+ if (ansiStart) {
30
+ if (currentContent) {
31
+ currentContent += joiner;
32
+ }
33
+ currentContent += segment;
34
+ } else {
35
+ if (result.length > 0) {
36
+ result.push(joiner);
37
+ }
38
+ result.push(segment);
39
+ }
40
+ }
41
+ return result.join("");
42
+ };
43
+
44
+ export { joinSegments as default };
@@ -0,0 +1,7 @@
1
+ const normalizeGermanEszett = (value) => (
2
+ // Replace "SS" with "ß" only when both letters are uppercase
3
+ // This uses a positive lookbehind to ensure we don't convert "ss" or "Ss"
4
+ value.replaceAll(/(?<![a-zß])SS(?![a-z])/g, "ß")
5
+ );
6
+
7
+ export { normalizeGermanEszett as n };
@@ -0,0 +1,190 @@
1
+ const mergeIntervals = (intervals) => {
2
+ if (intervals.length === 0) {
3
+ return [];
4
+ }
5
+ const merged = [];
6
+ let currentMerge = [...intervals[0]];
7
+ for (let index = 1; index < intervals.length; index++) {
8
+ const next = intervals[index];
9
+ if (next && next[0] <= currentMerge[1] + 1) {
10
+ currentMerge[1] = Math.max(currentMerge[1], next[1]);
11
+ } else {
12
+ merged.push(currentMerge);
13
+ currentMerge = [...next];
14
+ }
15
+ }
16
+ merged.push(currentMerge);
17
+ return merged;
18
+ };
19
+ const replaceString = (source, searches, ignoreRanges) => {
20
+ if (!source) {
21
+ return "";
22
+ }
23
+ const potentialMatches = [];
24
+ let matchIdCounter = 0;
25
+ for (const item of searches) {
26
+ if (!item || item.length < 2) {
27
+ continue;
28
+ }
29
+ const [searchKey, replacementValue] = item;
30
+ if (replacementValue === void 0) {
31
+ continue;
32
+ }
33
+ try {
34
+ if (searchKey instanceof RegExp) {
35
+ const searchPattern = new RegExp(searchKey.source, `${searchKey.flags.replace("g", "")}g`);
36
+ let match;
37
+ while ((match = searchPattern.exec(source)) !== null) {
38
+ const start = match.index;
39
+ const original = match[0];
40
+ if (original.length === 0 && searchPattern.lastIndex === match.index) {
41
+ searchPattern.lastIndex += 1;
42
+ }
43
+ const end = start + original.length - 1;
44
+ const finalReplacement = replacementValue.replaceAll(/\$([\d&$`'])/g, (substringFound, capturedSymbolOrDigits) => {
45
+ if (capturedSymbolOrDigits === "&") {
46
+ return original;
47
+ }
48
+ if (capturedSymbolOrDigits === "$") {
49
+ return "$";
50
+ }
51
+ if (capturedSymbolOrDigits === "`") {
52
+ return source.slice(0, Math.max(0, start));
53
+ }
54
+ if (capturedSymbolOrDigits === "'") {
55
+ return source.slice(Math.max(0, start + original.length));
56
+ }
57
+ const groupIndex = Number.parseInt(capturedSymbolOrDigits, 10);
58
+ if (match && groupIndex > 0 && groupIndex < match.length) {
59
+ return match[groupIndex] ?? "";
60
+ }
61
+ return substringFound;
62
+ });
63
+ potentialMatches.push({ end, id: matchIdCounter++, original, replacement: finalReplacement, start });
64
+ if (original.length === 0 && searchPattern.lastIndex === start) {
65
+ searchPattern.lastIndex += 1;
66
+ }
67
+ }
68
+ } else if (typeof searchKey === "string" && searchKey.length > 0) {
69
+ for (let index = 0; (index = source.indexOf(searchKey, index)) !== -1; index++) {
70
+ const start = index;
71
+ const original = searchKey;
72
+ const end = start + original.length - 1;
73
+ const mockMatch = Object.assign([original], { index: start, input: source });
74
+ const finalReplacement = replacementValue.replaceAll(/\$(\d+|&|\$)/g, (substringFound, capturedSymbolOrDigits) => {
75
+ if (capturedSymbolOrDigits === "&") {
76
+ return original;
77
+ }
78
+ if (capturedSymbolOrDigits === "$") {
79
+ return "$";
80
+ }
81
+ const groupIndex = Number.parseInt(capturedSymbolOrDigits, 10);
82
+ if (mockMatch && groupIndex > 0 && groupIndex < mockMatch.length) {
83
+ return mockMatch[groupIndex] ?? "";
84
+ }
85
+ return substringFound;
86
+ });
87
+ potentialMatches.push({ end, id: matchIdCounter++, original, replacement: finalReplacement, start });
88
+ }
89
+ } else {
90
+ continue;
91
+ }
92
+ } catch {
93
+ continue;
94
+ }
95
+ }
96
+ potentialMatches.sort((a, b) => {
97
+ if (a.start !== b.start) {
98
+ return a.start - b.start;
99
+ }
100
+ return b.end - a.end;
101
+ });
102
+ const sortedIgnores = [...ignoreRanges].sort((a, b) => a[0] - b[0]);
103
+ const mergedIgnores = mergeIntervals(sortedIgnores);
104
+ const processedChars = source.split("").map((char, index) => {
105
+ return {
106
+ appliedMatchId: null,
107
+ char,
108
+ index,
109
+ insertBeforeReplacement: null,
110
+ isIgnored: false,
111
+ isMatchStart: false,
112
+ matchReplacement: null
113
+ };
114
+ });
115
+ for (const range of mergedIgnores) {
116
+ for (let index = range[0]; index <= range[1]; index++) {
117
+ if (processedChars[index]) {
118
+ processedChars[index].isIgnored = true;
119
+ }
120
+ }
121
+ }
122
+ let insertionAfterEnd = "";
123
+ for (const match of potentialMatches) {
124
+ if (match.original.length === 0 && match.start >= 0 && match.start <= processedChars.length) {
125
+ const targetIndex = match.start;
126
+ if (processedChars[targetIndex]) {
127
+ const targetChar = processedChars[targetIndex];
128
+ if (!targetChar.isIgnored) {
129
+ targetChar.insertBeforeReplacement = (targetChar.insertBeforeReplacement ?? "") + match.replacement;
130
+ }
131
+ } else if (targetIndex === processedChars.length) {
132
+ insertionAfterEnd += match.replacement;
133
+ }
134
+ }
135
+ }
136
+ for (const match of potentialMatches) {
137
+ if (match.original.length === 0) {
138
+ continue;
139
+ }
140
+ let canApply = true;
141
+ for (let index = match.start; index <= match.end; index++) {
142
+ if (!processedChars[index] || processedChars[index].isIgnored || processedChars[index].appliedMatchId !== null) {
143
+ canApply = false;
144
+ break;
145
+ }
146
+ }
147
+ if (canApply && match.start >= 0 && match.start < processedChars.length) {
148
+ for (let index = match.start; index <= match.end; index++) {
149
+ if (processedChars[index]) {
150
+ processedChars[index].appliedMatchId = match.id;
151
+ }
152
+ }
153
+ if (processedChars[match.start]) {
154
+ processedChars[match.start].isMatchStart = true;
155
+ processedChars[match.start].matchReplacement = match.replacement;
156
+ }
157
+ }
158
+ }
159
+ let result = "";
160
+ let currentIndex = 0;
161
+ while (currentIndex < processedChars.length) {
162
+ const pChar = processedChars[currentIndex];
163
+ if (pChar.insertBeforeReplacement !== null) {
164
+ result += pChar.insertBeforeReplacement;
165
+ }
166
+ if (pChar.isMatchStart && pChar.appliedMatchId !== null) {
167
+ result += pChar.matchReplacement ?? "";
168
+ let matchEndIndex = currentIndex;
169
+ for (let index = currentIndex + 1; index < processedChars.length; index++) {
170
+ if (processedChars[index]?.appliedMatchId === pChar.appliedMatchId) {
171
+ matchEndIndex = index;
172
+ } else {
173
+ break;
174
+ }
175
+ }
176
+ currentIndex = matchEndIndex + 1;
177
+ } else if (pChar.appliedMatchId === null) {
178
+ result += pChar.char;
179
+ currentIndex += 1;
180
+ } else {
181
+ currentIndex += 1;
182
+ }
183
+ }
184
+ if (insertionAfterEnd.length > 0) {
185
+ result += insertionAfterEnd;
186
+ }
187
+ return result;
188
+ };
189
+
190
+ export { replaceString as default };