@visulima/string 3.0.0-alpha.8 → 3.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 (121) hide show
  1. package/CHANGELOG.md +326 -0
  2. package/LICENSE.md +119 -0
  3. package/README.md +88 -4
  4. package/dist/align-text.d.ts +35 -0
  5. package/dist/align-text.js +2 -32
  6. package/dist/case/camel-case.d.ts +17 -3
  7. package/dist/case/camel-case.js +1 -55
  8. package/dist/case/capital-case.d.ts +14 -3
  9. package/dist/case/capital-case.js +1 -47
  10. package/dist/case/constant-case.d.ts +14 -3
  11. package/dist/case/constant-case.js +1 -7
  12. package/dist/case/dot-case.d.ts +14 -3
  13. package/dist/case/dot-case.js +1 -7
  14. package/dist/case/flat-case.d.ts +12 -3
  15. package/dist/case/flat-case.js +1 -7
  16. package/dist/case/flip-case.d.ts +16 -3
  17. package/dist/case/flip-case.js +1 -82
  18. package/dist/case/identify-case.d.ts +15 -3
  19. package/dist/case/identify-case.js +1 -65
  20. package/dist/case/index.d.ts +9 -4
  21. package/dist/case/index.js +1 -20
  22. package/dist/case/kebab-case.d.ts +25 -3
  23. package/dist/case/kebab-case.js +1 -55
  24. package/dist/case/lower-first.d.ts +13 -3
  25. package/dist/case/lower-first.js +1 -9
  26. package/dist/case/no-case.d.ts +14 -3
  27. package/dist/case/no-case.js +1 -7
  28. package/dist/case/pascal-case.d.ts +17 -3
  29. package/dist/case/pascal-case.js +1 -48
  30. package/dist/case/pascal-snake-case.d.ts +14 -3
  31. package/dist/case/pascal-snake-case.js +1 -28
  32. package/dist/case/path-case.d.ts +14 -3
  33. package/dist/case/path-case.js +1 -7
  34. package/dist/case/sentence-case.d.ts +14 -3
  35. package/dist/case/sentence-case.js +1 -54
  36. package/dist/case/snake-case.d.ts +14 -3
  37. package/dist/case/snake-case.js +1 -7
  38. package/dist/case/split-by-case.d.ts +29 -3
  39. package/dist/case/split-by-case.js +1 -747
  40. package/dist/case/title-case.d.ts +12 -3
  41. package/dist/case/title-case.js +1 -42
  42. package/dist/case/train-case.d.ts +14 -3
  43. package/dist/case/train-case.js +1 -40
  44. package/dist/case/upper-first.d.ts +13 -3
  45. package/dist/case/upper-first.js +1 -9
  46. package/dist/closest-string.d.ts +32 -0
  47. package/dist/closest-string.js +1 -23
  48. package/dist/compare-similarity.d.ts +37 -0
  49. package/dist/compare-similarity.js +1 -12
  50. package/dist/count-occurrences.d.ts +9 -0
  51. package/dist/count-occurrences.js +1 -0
  52. package/dist/direction.d.ts +7 -0
  53. package/dist/direction.js +1 -0
  54. package/dist/east-asian-width.d.ts +52 -0
  55. package/dist/east-asian-width.js +1 -0
  56. package/dist/excerpt.d.ts +25 -0
  57. package/dist/excerpt.js +53 -0
  58. package/dist/get-string-truncated-width.d.ts +151 -0
  59. package/dist/get-string-truncated-width.js +1 -444
  60. package/dist/get-string-width.d.ts +58 -0
  61. package/dist/get-string-width.js +1 -5
  62. package/dist/indent.d.ts +87 -0
  63. package/dist/indent.js +1 -0
  64. package/dist/index.d.ts +12 -15
  65. package/dist/index.js +1 -39
  66. package/dist/is-fullwidth-code-point.d.ts +7 -0
  67. package/dist/is-fullwidth-code-point.js +1 -0
  68. package/dist/levenshtein.d.ts +25 -0
  69. package/dist/levenshtein.js +1 -0
  70. package/dist/native-string-types.d.ts +239 -0
  71. package/dist/outdent.d.ts +74 -0
  72. package/dist/outdent.js +1 -117
  73. package/dist/packem_shared/_isFullWidth-Dqc3MWgl.js +1 -0
  74. package/dist/packem_shared/closest-C6YDQs4m.js +1 -0
  75. package/dist/packem_shared/constants-aPzGW29R.js +1 -0
  76. package/dist/packem_shared/dedent-CPjAYUXh.js +1 -0
  77. package/dist/packem_shared/eastAsianWidth-DJV8Kqd-.js +1 -0
  78. package/dist/packem_shared/generate-cache-key-BqU1Cqwm.js +1 -0
  79. package/dist/packem_shared/indent-cz8WMI0e.js +1 -0
  80. package/dist/packem_shared/joinSegments-CaHT-45s.js +1 -0
  81. package/dist/packem_shared/lru-cache-BtMSrYQJ.js +1 -0
  82. package/dist/packem_shared/normalize-german-eszett-hNMwtGjd.js +1 -0
  83. package/dist/packem_shared/redent-ByOoJ6fN.js +1 -0
  84. package/dist/packem_shared/types.d-CmNvyl4l.d.ts +360 -0
  85. package/dist/packem_shared/types.d-fhe030jX.d.ts +402 -0
  86. package/dist/replace-string.d.ts +10 -0
  87. package/dist/replace-string.js +1 -0
  88. package/dist/slice.d.ts +42 -0
  89. package/dist/slice.js +1 -413
  90. package/dist/slugify.d.ts +10 -1
  91. package/dist/slugify.js +1 -46
  92. package/dist/test/utils.d.ts +17 -0
  93. package/dist/test/utils.js +13 -88
  94. package/dist/test/vitest.d.ts +3 -0
  95. package/dist/test/vitest.js +1 -5
  96. package/dist/transliterate.d.ts +10 -0
  97. package/dist/transliterate.js +5 -0
  98. package/dist/truncate.d.ts +43 -0
  99. package/dist/truncate.js +1 -114
  100. package/dist/utilities.d.ts +28 -2
  101. package/dist/utilities.js +1 -54
  102. package/dist/word-similarity-sort.d.ts +34 -0
  103. package/dist/word-similarity-sort.js +1 -22
  104. package/dist/word-wrap.d.ts +44 -0
  105. package/dist/word-wrap.js +8 -637
  106. package/package.json +70 -39
  107. package/dist/packem_shared/LRUCache-3r3SovvR.js +0 -46
  108. package/dist/packem_shared/closest-IHuSvnSn.js +0 -139
  109. package/dist/packem_shared/closestN-Cvsw0Fue.js +0 -24
  110. package/dist/packem_shared/constants-D5qaproB.js +0 -95
  111. package/dist/packem_shared/countOccurrences-CS9XprQN.js +0 -22
  112. package/dist/packem_shared/direction-BVhR8MOQ.js +0 -10
  113. package/dist/packem_shared/excerpt-COsVNttN.js +0 -1502
  114. package/dist/packem_shared/generate-cache-key-DdayDfjV.js +0 -6
  115. package/dist/packem_shared/joinSegments-BStLas0c.js +0 -44
  116. package/dist/packem_shared/lru-cache.d-BsP6kbVJ.d.ts +0 -13
  117. package/dist/packem_shared/normalize-german-eszett-DEB8-ZPT.js +0 -7
  118. package/dist/packem_shared/replaceString-BVlxk27d.js +0 -190
  119. package/dist/packem_shared/transliterate-DGlx-woj.js +0 -47756
  120. package/dist/packem_shared/types.d-BVNv675q.d.ts +0 -61
  121. package/dist/packem_shared/types.d-DfgbcNKh.d.ts +0 -57
@@ -1,6 +0,0 @@
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 };
@@ -1,44 +0,0 @@
1
- import { R as RE_FAST_ANSI } from './constants-D5qaproB.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 };
@@ -1,13 +0,0 @@
1
- declare class LRUCache<K, V> {
2
- private readonly capacity;
3
- private readonly cache;
4
- private keyOrder;
5
- constructor(capacity: number);
6
- get(key: K): V | undefined;
7
- has(key: K): boolean;
8
- set(key: K, value: V): void;
9
- delete(key: K): void;
10
- clear(): void;
11
- size(): number;
12
- }
13
- export { LRUCache as L };
@@ -1,7 +0,0 @@
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 };
@@ -1,190 +0,0 @@
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.toSorted((a, b) => a[0] - b[0]);
103
- const mergedIgnores = mergeIntervals(sortedIgnores);
104
- const processedChars = source.split("").map((char, index) => {
105
- return {
106
- appliedMatchId: void 0,
107
- char,
108
- index,
109
- insertBeforeReplacement: void 0,
110
- isIgnored: false,
111
- isMatchStart: false,
112
- matchReplacement: void 0
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 !== void 0) {
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 !== void 0) {
164
- result += pChar.insertBeforeReplacement;
165
- }
166
- if (pChar.isMatchStart && pChar.appliedMatchId !== void 0) {
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 === void 0) {
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 };