@visulima/string 1.1.0 → 1.2.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 (93) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +201 -2
  3. package/dist/case/camel-case.d.cts +3 -3
  4. package/dist/case/camel-case.d.mts +3 -3
  5. package/dist/case/camel-case.d.ts +3 -3
  6. package/dist/case/capital-case.d.cts +3 -3
  7. package/dist/case/capital-case.d.mts +3 -3
  8. package/dist/case/capital-case.d.ts +3 -3
  9. package/dist/case/constant-case.d.cts +3 -3
  10. package/dist/case/constant-case.d.mts +3 -3
  11. package/dist/case/constant-case.d.ts +3 -3
  12. package/dist/case/dot-case.d.cts +3 -3
  13. package/dist/case/dot-case.d.mts +3 -3
  14. package/dist/case/dot-case.d.ts +3 -3
  15. package/dist/case/flat-case.d.cts +3 -3
  16. package/dist/case/flat-case.d.mts +3 -3
  17. package/dist/case/flat-case.d.ts +3 -3
  18. package/dist/case/flip-case.d.cts +3 -3
  19. package/dist/case/flip-case.d.mts +3 -3
  20. package/dist/case/flip-case.d.ts +3 -3
  21. package/dist/case/identify-case.d.cts +3 -3
  22. package/dist/case/identify-case.d.mts +3 -3
  23. package/dist/case/identify-case.d.ts +3 -3
  24. package/dist/case/index.d.cts +3 -3
  25. package/dist/case/index.d.mts +3 -3
  26. package/dist/case/index.d.ts +3 -3
  27. package/dist/case/kebab-case.d.cts +3 -3
  28. package/dist/case/kebab-case.d.mts +3 -3
  29. package/dist/case/kebab-case.d.ts +3 -3
  30. package/dist/case/lower-first.d.cts +3 -3
  31. package/dist/case/lower-first.d.mts +3 -3
  32. package/dist/case/lower-first.d.ts +3 -3
  33. package/dist/case/no-case.d.cts +3 -3
  34. package/dist/case/no-case.d.mts +3 -3
  35. package/dist/case/no-case.d.ts +3 -3
  36. package/dist/case/pascal-case.d.cts +3 -3
  37. package/dist/case/pascal-case.d.mts +3 -3
  38. package/dist/case/pascal-case.d.ts +3 -3
  39. package/dist/case/pascal-snake-case.d.cts +3 -3
  40. package/dist/case/pascal-snake-case.d.mts +3 -3
  41. package/dist/case/pascal-snake-case.d.ts +3 -3
  42. package/dist/case/path-case.d.cts +3 -3
  43. package/dist/case/path-case.d.mts +3 -3
  44. package/dist/case/path-case.d.ts +3 -3
  45. package/dist/case/sentence-case.d.cts +3 -3
  46. package/dist/case/sentence-case.d.mts +3 -3
  47. package/dist/case/sentence-case.d.ts +3 -3
  48. package/dist/case/snake-case.d.cts +3 -3
  49. package/dist/case/snake-case.d.mts +3 -3
  50. package/dist/case/snake-case.d.ts +3 -3
  51. package/dist/case/split-by-case.d.cts +3 -3
  52. package/dist/case/split-by-case.d.mts +3 -3
  53. package/dist/case/split-by-case.d.ts +3 -3
  54. package/dist/case/title-case.d.cts +3 -3
  55. package/dist/case/title-case.d.mts +3 -3
  56. package/dist/case/title-case.d.ts +3 -3
  57. package/dist/case/train-case.d.cts +3 -3
  58. package/dist/case/train-case.d.mts +3 -3
  59. package/dist/case/train-case.d.ts +3 -3
  60. package/dist/case/upper-first.d.cts +3 -3
  61. package/dist/case/upper-first.d.mts +3 -3
  62. package/dist/case/upper-first.d.ts +3 -3
  63. package/dist/index.cjs +6 -0
  64. package/dist/index.d.cts +11 -4
  65. package/dist/index.d.mts +11 -4
  66. package/dist/index.d.ts +11 -4
  67. package/dist/index.mjs +3 -0
  68. package/dist/native-string-types.d.cts +1 -1
  69. package/dist/native-string-types.d.mts +1 -1
  70. package/dist/native-string-types.d.ts +1 -1
  71. package/dist/packem_shared/lru-cache-B_t27XwI.d.cts +14 -0
  72. package/dist/packem_shared/lru-cache-B_t27XwI.d.mts +14 -0
  73. package/dist/packem_shared/lru-cache-B_t27XwI.d.ts +14 -0
  74. package/dist/packem_shared/replaceString-C7Dp5vAg.mjs +200 -0
  75. package/dist/packem_shared/replaceString-iYo1cDfZ.cjs +202 -0
  76. package/dist/packem_shared/slugify-B9zJ8G7m.cjs +50 -0
  77. package/dist/packem_shared/slugify-C7by01BU.mjs +48 -0
  78. package/dist/packem_shared/transliterate-BUI0uSNe.cjs +46092 -0
  79. package/dist/packem_shared/transliterate-DPctxBml.mjs +46090 -0
  80. package/dist/packem_shared/{types-BttWSSIk.d.ts → types-C5Pk8B8Q.d.cts} +3 -3
  81. package/dist/packem_shared/{types-BAd3WDHo.d.mts → types-DcGtApe2.d.ts} +3 -3
  82. package/dist/packem_shared/{types-BNbQJg02.d.cts → types-DmfKbIaI.d.cts} +23 -1
  83. package/dist/packem_shared/{types-BNbQJg02.d.mts → types-DmfKbIaI.d.mts} +23 -1
  84. package/dist/packem_shared/{types-BNbQJg02.d.ts → types-DmfKbIaI.d.ts} +23 -1
  85. package/dist/packem_shared/{types-D2-6p7t1.d.cts → types-_jqW_ZOt.d.mts} +3 -3
  86. package/dist/truncate.cjs +1 -0
  87. package/dist/truncate.mjs +1 -0
  88. package/dist/utils.cjs +57 -1
  89. package/dist/utils.d.cts +9 -13
  90. package/dist/utils.d.mts +9 -13
  91. package/dist/utils.d.ts +9 -13
  92. package/dist/utils.mjs +55 -0
  93. package/package.json +4 -4
@@ -0,0 +1,200 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ const mergeIntervals = /* @__PURE__ */ __name((intervals) => {
4
+ if (intervals.length === 0) {
5
+ return [];
6
+ }
7
+ const merged = [];
8
+ let currentMerge = [...intervals[0]];
9
+ for (let index = 1; index < intervals.length; index++) {
10
+ const next = intervals[index];
11
+ if (next && next[0] <= currentMerge[1] + 1) {
12
+ currentMerge[1] = Math.max(currentMerge[1], next[1]);
13
+ } else {
14
+ merged.push(currentMerge);
15
+ currentMerge = [...next];
16
+ }
17
+ }
18
+ merged.push(currentMerge);
19
+ return merged;
20
+ }, "mergeIntervals");
21
+ const replaceString = /* @__PURE__ */ __name((source, searches, ignoreRanges) => {
22
+ if (!source) {
23
+ return "";
24
+ }
25
+ const potentialMatches = [];
26
+ let matchIdCounter = 0;
27
+ for (const item of searches) {
28
+ if (!item || item.length < 2) {
29
+ continue;
30
+ }
31
+ const [searchKey, replacementValue] = item;
32
+ if (replacementValue === void 0) {
33
+ continue;
34
+ }
35
+ try {
36
+ if (searchKey instanceof RegExp) {
37
+ const searchPattern = new RegExp(searchKey.source, `${searchKey.flags.replace("g", "")}g`);
38
+ let match;
39
+ while ((match = searchPattern.exec(source)) !== null) {
40
+ const start = match.index;
41
+ const original = match[0];
42
+ if (original.length === 0 && searchPattern.lastIndex === match.index) {
43
+ searchPattern.lastIndex++;
44
+ }
45
+ const end = start + original.length - 1;
46
+ const finalReplacement = replacementValue.replaceAll(/\$([\d&$`'])/g, (substringFound, capturedSymbolOrDigits) => {
47
+ if (capturedSymbolOrDigits === "&") {
48
+ return original;
49
+ }
50
+ if (capturedSymbolOrDigits === "$") {
51
+ return "$";
52
+ }
53
+ if (capturedSymbolOrDigits === "`") {
54
+ return source.substring(0, start);
55
+ }
56
+ if (capturedSymbolOrDigits === "'") {
57
+ return source.substring(start + original.length);
58
+ }
59
+ const groupIndex = Number.parseInt(capturedSymbolOrDigits, 10);
60
+ if (match && groupIndex > 0 && groupIndex < match.length) {
61
+ return match[groupIndex] ?? "";
62
+ }
63
+ return substringFound;
64
+ });
65
+ potentialMatches.push({ end, id: matchIdCounter++, original, replacement: finalReplacement, start });
66
+ if (original.length === 0 && searchPattern.lastIndex === start) {
67
+ searchPattern.lastIndex++;
68
+ }
69
+ }
70
+ } else if (typeof searchKey === "string" && searchKey.length > 0) {
71
+ for (let index = 0; (index = source.indexOf(searchKey, index)) !== -1; index++) {
72
+ const start = index;
73
+ const original = searchKey;
74
+ const end = start + original.length - 1;
75
+ const mockMatch = Object.assign([original], { index: start, input: source });
76
+ const finalReplacement = replacementValue.replaceAll(/\$(\d+|&|\$)/g, (substringFound, capturedSymbolOrDigits) => {
77
+ if (capturedSymbolOrDigits === "&") {
78
+ return original;
79
+ }
80
+ if (capturedSymbolOrDigits === "$") {
81
+ return "$";
82
+ }
83
+ const groupIndex = Number.parseInt(capturedSymbolOrDigits, 10);
84
+ if (mockMatch && groupIndex > 0 && groupIndex < mockMatch.length) {
85
+ return mockMatch[groupIndex] ?? "";
86
+ }
87
+ return substringFound;
88
+ });
89
+ potentialMatches.push({ end, id: matchIdCounter++, original, replacement: finalReplacement, start });
90
+ }
91
+ } else {
92
+ continue;
93
+ }
94
+ } catch {
95
+ continue;
96
+ }
97
+ }
98
+ potentialMatches.sort((a, b) => {
99
+ if (a.start !== b.start) {
100
+ return a.start - b.start;
101
+ }
102
+ return b.end - a.end;
103
+ });
104
+ const sortedIgnores = [...ignoreRanges].sort((a, b) => a[0] - b[0]);
105
+ const mergedIgnores = mergeIntervals(sortedIgnores);
106
+ const processedChars = source.split("").map((char, index) => {
107
+ return {
108
+ appliedMatchId: null,
109
+ char,
110
+ index,
111
+ insertBeforeReplacement: null,
112
+ isIgnored: false,
113
+ isMatchStart: false,
114
+ matchReplacement: null
115
+ };
116
+ });
117
+ for (const range of mergedIgnores) {
118
+ for (let index = range[0]; index <= range[1]; index++) {
119
+ if (processedChars[index]) {
120
+ processedChars[index].isIgnored = true;
121
+ }
122
+ }
123
+ }
124
+ let insertionAfterEnd = "";
125
+ for (const match of potentialMatches) {
126
+ if (match.original.length === 0 && match.start >= 0 && match.start <= processedChars.length) {
127
+ const targetIndex = match.start;
128
+ if (processedChars[targetIndex]) {
129
+ const targetChar = processedChars[targetIndex];
130
+ if (!targetChar.isIgnored) {
131
+ targetChar.insertBeforeReplacement = (targetChar.insertBeforeReplacement ?? "") + match.replacement;
132
+ }
133
+ } else if (targetIndex === processedChars.length) {
134
+ insertionAfterEnd += match.replacement;
135
+ }
136
+ }
137
+ }
138
+ for (const match of potentialMatches) {
139
+ if (match.original.length === 0) {
140
+ continue;
141
+ }
142
+ let canApply = true;
143
+ for (let index = match.start; index <= match.end; index++) {
144
+ if (
145
+ // eslint-disable-next-line security/detect-object-injection
146
+ !processedChars[index] || // Out of bounds
147
+ // eslint-disable-next-line security/detect-object-injection
148
+ processedChars[index].isIgnored || // Overlaps ignore
149
+ // eslint-disable-next-line security/detect-object-injection
150
+ processedChars[index].appliedMatchId !== null
151
+ ) {
152
+ canApply = false;
153
+ break;
154
+ }
155
+ }
156
+ if (canApply && // Apply this valid match
157
+ match.start >= 0 && match.start < processedChars.length) {
158
+ for (let index = match.start; index <= match.end; index++) {
159
+ if (processedChars[index]) {
160
+ processedChars[index].appliedMatchId = match.id;
161
+ }
162
+ }
163
+ if (processedChars[match.start]) {
164
+ processedChars[match.start].isMatchStart = true;
165
+ processedChars[match.start].matchReplacement = match.replacement;
166
+ }
167
+ }
168
+ }
169
+ let result = "";
170
+ let currentIndex = 0;
171
+ while (currentIndex < processedChars.length) {
172
+ const pChar = processedChars[currentIndex];
173
+ if (pChar.insertBeforeReplacement !== null) {
174
+ result += pChar.insertBeforeReplacement;
175
+ }
176
+ if (pChar.isMatchStart && pChar.appliedMatchId !== null) {
177
+ result += pChar.matchReplacement ?? "";
178
+ let matchEndIndex = currentIndex;
179
+ for (let index = currentIndex + 1; index < processedChars.length; index++) {
180
+ if (processedChars[index]?.appliedMatchId === pChar.appliedMatchId) {
181
+ matchEndIndex = index;
182
+ } else {
183
+ break;
184
+ }
185
+ }
186
+ currentIndex = matchEndIndex + 1;
187
+ } else if (pChar.appliedMatchId === null) {
188
+ result += pChar.char;
189
+ currentIndex++;
190
+ } else {
191
+ currentIndex++;
192
+ }
193
+ }
194
+ if (insertionAfterEnd.length > 0) {
195
+ result += insertionAfterEnd;
196
+ }
197
+ return result;
198
+ }, "replaceString");
199
+
200
+ export { replaceString as default };
@@ -0,0 +1,202 @@
1
+ 'use strict';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
+ const mergeIntervals = /* @__PURE__ */ __name((intervals) => {
6
+ if (intervals.length === 0) {
7
+ return [];
8
+ }
9
+ const merged = [];
10
+ let currentMerge = [...intervals[0]];
11
+ for (let index = 1; index < intervals.length; index++) {
12
+ const next = intervals[index];
13
+ if (next && next[0] <= currentMerge[1] + 1) {
14
+ currentMerge[1] = Math.max(currentMerge[1], next[1]);
15
+ } else {
16
+ merged.push(currentMerge);
17
+ currentMerge = [...next];
18
+ }
19
+ }
20
+ merged.push(currentMerge);
21
+ return merged;
22
+ }, "mergeIntervals");
23
+ const replaceString = /* @__PURE__ */ __name((source, searches, ignoreRanges) => {
24
+ if (!source) {
25
+ return "";
26
+ }
27
+ const potentialMatches = [];
28
+ let matchIdCounter = 0;
29
+ for (const item of searches) {
30
+ if (!item || item.length < 2) {
31
+ continue;
32
+ }
33
+ const [searchKey, replacementValue] = item;
34
+ if (replacementValue === void 0) {
35
+ continue;
36
+ }
37
+ try {
38
+ if (searchKey instanceof RegExp) {
39
+ const searchPattern = new RegExp(searchKey.source, `${searchKey.flags.replace("g", "")}g`);
40
+ let match;
41
+ while ((match = searchPattern.exec(source)) !== null) {
42
+ const start = match.index;
43
+ const original = match[0];
44
+ if (original.length === 0 && searchPattern.lastIndex === match.index) {
45
+ searchPattern.lastIndex++;
46
+ }
47
+ const end = start + original.length - 1;
48
+ const finalReplacement = replacementValue.replaceAll(/\$([\d&$`'])/g, (substringFound, capturedSymbolOrDigits) => {
49
+ if (capturedSymbolOrDigits === "&") {
50
+ return original;
51
+ }
52
+ if (capturedSymbolOrDigits === "$") {
53
+ return "$";
54
+ }
55
+ if (capturedSymbolOrDigits === "`") {
56
+ return source.substring(0, start);
57
+ }
58
+ if (capturedSymbolOrDigits === "'") {
59
+ return source.substring(start + original.length);
60
+ }
61
+ const groupIndex = Number.parseInt(capturedSymbolOrDigits, 10);
62
+ if (match && groupIndex > 0 && groupIndex < match.length) {
63
+ return match[groupIndex] ?? "";
64
+ }
65
+ return substringFound;
66
+ });
67
+ potentialMatches.push({ end, id: matchIdCounter++, original, replacement: finalReplacement, start });
68
+ if (original.length === 0 && searchPattern.lastIndex === start) {
69
+ searchPattern.lastIndex++;
70
+ }
71
+ }
72
+ } else if (typeof searchKey === "string" && searchKey.length > 0) {
73
+ for (let index = 0; (index = source.indexOf(searchKey, index)) !== -1; index++) {
74
+ const start = index;
75
+ const original = searchKey;
76
+ const end = start + original.length - 1;
77
+ const mockMatch = Object.assign([original], { index: start, input: source });
78
+ const finalReplacement = replacementValue.replaceAll(/\$(\d+|&|\$)/g, (substringFound, capturedSymbolOrDigits) => {
79
+ if (capturedSymbolOrDigits === "&") {
80
+ return original;
81
+ }
82
+ if (capturedSymbolOrDigits === "$") {
83
+ return "$";
84
+ }
85
+ const groupIndex = Number.parseInt(capturedSymbolOrDigits, 10);
86
+ if (mockMatch && groupIndex > 0 && groupIndex < mockMatch.length) {
87
+ return mockMatch[groupIndex] ?? "";
88
+ }
89
+ return substringFound;
90
+ });
91
+ potentialMatches.push({ end, id: matchIdCounter++, original, replacement: finalReplacement, start });
92
+ }
93
+ } else {
94
+ continue;
95
+ }
96
+ } catch {
97
+ continue;
98
+ }
99
+ }
100
+ potentialMatches.sort((a, b) => {
101
+ if (a.start !== b.start) {
102
+ return a.start - b.start;
103
+ }
104
+ return b.end - a.end;
105
+ });
106
+ const sortedIgnores = [...ignoreRanges].sort((a, b) => a[0] - b[0]);
107
+ const mergedIgnores = mergeIntervals(sortedIgnores);
108
+ const processedChars = source.split("").map((char, index) => {
109
+ return {
110
+ appliedMatchId: null,
111
+ char,
112
+ index,
113
+ insertBeforeReplacement: null,
114
+ isIgnored: false,
115
+ isMatchStart: false,
116
+ matchReplacement: null
117
+ };
118
+ });
119
+ for (const range of mergedIgnores) {
120
+ for (let index = range[0]; index <= range[1]; index++) {
121
+ if (processedChars[index]) {
122
+ processedChars[index].isIgnored = true;
123
+ }
124
+ }
125
+ }
126
+ let insertionAfterEnd = "";
127
+ for (const match of potentialMatches) {
128
+ if (match.original.length === 0 && match.start >= 0 && match.start <= processedChars.length) {
129
+ const targetIndex = match.start;
130
+ if (processedChars[targetIndex]) {
131
+ const targetChar = processedChars[targetIndex];
132
+ if (!targetChar.isIgnored) {
133
+ targetChar.insertBeforeReplacement = (targetChar.insertBeforeReplacement ?? "") + match.replacement;
134
+ }
135
+ } else if (targetIndex === processedChars.length) {
136
+ insertionAfterEnd += match.replacement;
137
+ }
138
+ }
139
+ }
140
+ for (const match of potentialMatches) {
141
+ if (match.original.length === 0) {
142
+ continue;
143
+ }
144
+ let canApply = true;
145
+ for (let index = match.start; index <= match.end; index++) {
146
+ if (
147
+ // eslint-disable-next-line security/detect-object-injection
148
+ !processedChars[index] || // Out of bounds
149
+ // eslint-disable-next-line security/detect-object-injection
150
+ processedChars[index].isIgnored || // Overlaps ignore
151
+ // eslint-disable-next-line security/detect-object-injection
152
+ processedChars[index].appliedMatchId !== null
153
+ ) {
154
+ canApply = false;
155
+ break;
156
+ }
157
+ }
158
+ if (canApply && // Apply this valid match
159
+ match.start >= 0 && match.start < processedChars.length) {
160
+ for (let index = match.start; index <= match.end; index++) {
161
+ if (processedChars[index]) {
162
+ processedChars[index].appliedMatchId = match.id;
163
+ }
164
+ }
165
+ if (processedChars[match.start]) {
166
+ processedChars[match.start].isMatchStart = true;
167
+ processedChars[match.start].matchReplacement = match.replacement;
168
+ }
169
+ }
170
+ }
171
+ let result = "";
172
+ let currentIndex = 0;
173
+ while (currentIndex < processedChars.length) {
174
+ const pChar = processedChars[currentIndex];
175
+ if (pChar.insertBeforeReplacement !== null) {
176
+ result += pChar.insertBeforeReplacement;
177
+ }
178
+ if (pChar.isMatchStart && pChar.appliedMatchId !== null) {
179
+ result += pChar.matchReplacement ?? "";
180
+ let matchEndIndex = currentIndex;
181
+ for (let index = currentIndex + 1; index < processedChars.length; index++) {
182
+ if (processedChars[index]?.appliedMatchId === pChar.appliedMatchId) {
183
+ matchEndIndex = index;
184
+ } else {
185
+ break;
186
+ }
187
+ }
188
+ currentIndex = matchEndIndex + 1;
189
+ } else if (pChar.appliedMatchId === null) {
190
+ result += pChar.char;
191
+ currentIndex++;
192
+ } else {
193
+ currentIndex++;
194
+ }
195
+ }
196
+ if (insertionAfterEnd.length > 0) {
197
+ result += insertionAfterEnd;
198
+ }
199
+ return result;
200
+ }, "replaceString");
201
+
202
+ module.exports = replaceString;
@@ -0,0 +1,50 @@
1
+ 'use strict';
2
+
3
+ const transliterate = require('./transliterate-BUI0uSNe.cjs');
4
+ const utils = require('../utils.cjs');
5
+
6
+ var __defProp = Object.defineProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ const removeDisallowedChars = /* @__PURE__ */ __name((input, allowedChars, separator) => {
9
+ const escapedChars = utils.escapeRegExp(allowedChars).replaceAll("\\-", "-");
10
+ const pattern = new RegExp(`[^${escapedChars}]`, "g");
11
+ return input.replaceAll(pattern, separator);
12
+ }, "removeDisallowedChars");
13
+ const slugify = /* @__PURE__ */ __name((input, options) => {
14
+ const config = {
15
+ allowedChars: "a-zA-Z0-9-_.~",
16
+ fixChineseSpacing: true,
17
+ ignore: [],
18
+ lowercase: true,
19
+ replaceAfter: [],
20
+ replaceBefore: [],
21
+ separator: "-",
22
+ transliterate: true,
23
+ trim: false,
24
+ unknown: "",
25
+ uppercase: false,
26
+ ...options
27
+ };
28
+ if (config.lowercase && config.uppercase) {
29
+ console.warn("slugify: Both lowercase and uppercase options are true. Defaulting to lowercase.");
30
+ config.uppercase = false;
31
+ }
32
+ let slug = config.transliterate ? transliterate(input, config) : input.normalize("NFC");
33
+ if (config.lowercase) {
34
+ slug = slug.toLowerCase();
35
+ } else if (config.uppercase) {
36
+ slug = slug.toUpperCase();
37
+ }
38
+ slug = removeDisallowedChars(slug, config.allowedChars, config.separator);
39
+ const escapedSeparator = utils.escapeRegExp(config.separator);
40
+ if (escapedSeparator) {
41
+ const separatorRegex = new RegExp(`${escapedSeparator}+`, "g");
42
+ slug = slug.replace(separatorRegex, config.separator);
43
+ }
44
+ if (escapedSeparator) {
45
+ return slug.replaceAll(new RegExp(`^${escapedSeparator}+|${escapedSeparator}+$`, "g"), "");
46
+ }
47
+ return slug;
48
+ }, "slugify");
49
+
50
+ module.exports = slugify;
@@ -0,0 +1,48 @@
1
+ import transliterate from './transliterate-DPctxBml.mjs';
2
+ import { escapeRegExp } from '../utils.mjs';
3
+
4
+ var __defProp = Object.defineProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ const removeDisallowedChars = /* @__PURE__ */ __name((input, allowedChars, separator) => {
7
+ const escapedChars = escapeRegExp(allowedChars).replaceAll("\\-", "-");
8
+ const pattern = new RegExp(`[^${escapedChars}]`, "g");
9
+ return input.replaceAll(pattern, separator);
10
+ }, "removeDisallowedChars");
11
+ const slugify = /* @__PURE__ */ __name((input, options) => {
12
+ const config = {
13
+ allowedChars: "a-zA-Z0-9-_.~",
14
+ fixChineseSpacing: true,
15
+ ignore: [],
16
+ lowercase: true,
17
+ replaceAfter: [],
18
+ replaceBefore: [],
19
+ separator: "-",
20
+ transliterate: true,
21
+ trim: false,
22
+ unknown: "",
23
+ uppercase: false,
24
+ ...options
25
+ };
26
+ if (config.lowercase && config.uppercase) {
27
+ console.warn("slugify: Both lowercase and uppercase options are true. Defaulting to lowercase.");
28
+ config.uppercase = false;
29
+ }
30
+ let slug = config.transliterate ? transliterate(input, config) : input.normalize("NFC");
31
+ if (config.lowercase) {
32
+ slug = slug.toLowerCase();
33
+ } else if (config.uppercase) {
34
+ slug = slug.toUpperCase();
35
+ }
36
+ slug = removeDisallowedChars(slug, config.allowedChars, config.separator);
37
+ const escapedSeparator = escapeRegExp(config.separator);
38
+ if (escapedSeparator) {
39
+ const separatorRegex = new RegExp(`${escapedSeparator}+`, "g");
40
+ slug = slug.replace(separatorRegex, config.separator);
41
+ }
42
+ if (escapedSeparator) {
43
+ return slug.replaceAll(new RegExp(`^${escapedSeparator}+|${escapedSeparator}+$`, "g"), "");
44
+ }
45
+ return slug;
46
+ }, "slugify");
47
+
48
+ export { slugify as default };