@sdkwork/sdk-common 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/README.md +89 -0
  2. package/dist/auth/index.d.ts +3 -0
  3. package/dist/auth/index.d.ts.map +1 -0
  4. package/dist/auth/token-manager.cjs +127 -0
  5. package/dist/auth/token-manager.cjs.map +1 -0
  6. package/dist/auth/token-manager.d.ts +80 -0
  7. package/dist/auth/token-manager.d.ts.map +1 -0
  8. package/dist/auth/token-manager.js +127 -0
  9. package/dist/auth/token-manager.js.map +1 -0
  10. package/dist/auth.cjs +9 -0
  11. package/dist/auth.cjs.map +1 -0
  12. package/dist/auth.js +9 -0
  13. package/dist/auth.js.map +1 -0
  14. package/dist/core/index.d.ts +3 -0
  15. package/dist/core/index.d.ts.map +1 -0
  16. package/dist/core/types.cjs +54 -0
  17. package/dist/core/types.cjs.map +1 -0
  18. package/dist/core/types.d.ts +187 -0
  19. package/dist/core/types.d.ts.map +1 -0
  20. package/dist/core/types.js +54 -0
  21. package/dist/core/types.js.map +1 -0
  22. package/dist/core.cjs +11 -0
  23. package/dist/core.cjs.map +1 -0
  24. package/dist/core.js +11 -0
  25. package/dist/core.js.map +1 -0
  26. package/dist/errors/index.d.ts +103 -0
  27. package/dist/errors/index.d.ts.map +1 -0
  28. package/dist/errors.cjs +286 -0
  29. package/dist/errors.cjs.map +1 -0
  30. package/dist/errors.js +286 -0
  31. package/dist/errors.js.map +1 -0
  32. package/dist/http/base-client.cjs +485 -0
  33. package/dist/http/base-client.cjs.map +1 -0
  34. package/dist/http/base-client.d.ts +98 -0
  35. package/dist/http/base-client.d.ts.map +1 -0
  36. package/dist/http/base-client.js +485 -0
  37. package/dist/http/base-client.js.map +1 -0
  38. package/dist/http/index.d.ts +2 -0
  39. package/dist/http/index.d.ts.map +1 -0
  40. package/dist/http.cjs +6 -0
  41. package/dist/http.cjs.map +1 -0
  42. package/dist/http.js +6 -0
  43. package/dist/http.js.map +1 -0
  44. package/dist/index.cjs +48 -0
  45. package/dist/index.cjs.map +1 -0
  46. package/dist/index.d.ts +11 -0
  47. package/dist/index.d.ts.map +1 -0
  48. package/dist/index.js +48 -0
  49. package/dist/index.js.map +1 -0
  50. package/dist/utils/array.d.ts +146 -0
  51. package/dist/utils/array.d.ts.map +1 -0
  52. package/dist/utils/cache.cjs +80 -0
  53. package/dist/utils/cache.cjs.map +1 -0
  54. package/dist/utils/cache.d.ts +25 -0
  55. package/dist/utils/cache.d.ts.map +1 -0
  56. package/dist/utils/cache.js +80 -0
  57. package/dist/utils/cache.js.map +1 -0
  58. package/dist/utils/date.cjs +25 -0
  59. package/dist/utils/date.cjs.map +1 -0
  60. package/dist/utils/date.d.ts +127 -0
  61. package/dist/utils/date.d.ts.map +1 -0
  62. package/dist/utils/date.js +25 -0
  63. package/dist/utils/date.js.map +1 -0
  64. package/dist/utils/encoding.cjs +678 -0
  65. package/dist/utils/encoding.cjs.map +1 -0
  66. package/dist/utils/encoding.d.ts +107 -0
  67. package/dist/utils/encoding.d.ts.map +1 -0
  68. package/dist/utils/encoding.js +679 -0
  69. package/dist/utils/encoding.js.map +1 -0
  70. package/dist/utils/index.d.ts +11 -0
  71. package/dist/utils/index.d.ts.map +1 -0
  72. package/dist/utils/logger.cjs +110 -0
  73. package/dist/utils/logger.cjs.map +1 -0
  74. package/dist/utils/logger.d.ts +28 -0
  75. package/dist/utils/logger.d.ts.map +1 -0
  76. package/dist/utils/logger.js +110 -0
  77. package/dist/utils/logger.js.map +1 -0
  78. package/dist/utils/object.d.ts +131 -0
  79. package/dist/utils/object.d.ts.map +1 -0
  80. package/dist/utils/retry.cjs +73 -0
  81. package/dist/utils/retry.cjs.map +1 -0
  82. package/dist/utils/retry.d.ts +9 -0
  83. package/dist/utils/retry.d.ts.map +1 -0
  84. package/dist/utils/retry.js +73 -0
  85. package/dist/utils/retry.js.map +1 -0
  86. package/dist/utils/string.cjs +820 -0
  87. package/dist/utils/string.cjs.map +1 -0
  88. package/dist/utils/string.d.ts +160 -0
  89. package/dist/utils/string.d.ts.map +1 -0
  90. package/dist/utils/string.js +821 -0
  91. package/dist/utils/string.js.map +1 -0
  92. package/dist/utils/url.d.ts +106 -0
  93. package/dist/utils/url.d.ts.map +1 -0
  94. package/dist/utils/validation.d.ts +157 -0
  95. package/dist/utils/validation.d.ts.map +1 -0
  96. package/dist/utils.cjs +52 -0
  97. package/dist/utils.cjs.map +1 -0
  98. package/dist/utils.js +46 -0
  99. package/dist/utils.js.map +1 -0
  100. package/package.json +80 -0
@@ -0,0 +1,821 @@
1
+ const EMPTY_STRING = "";
2
+ const SPACE = " ";
3
+ const DASH = "-";
4
+ const UNDERSCORE = "_";
5
+ const DOT = ".";
6
+ const SLASH = "/";
7
+ const BACKSLASH = "\\";
8
+ const NEWLINE = "\n";
9
+ const CARRIAGE_RETURN = "\r";
10
+ const TAB = " ";
11
+ var StringUtils;
12
+ ((StringUtils2) => {
13
+ function isEmpty(value) {
14
+ return value === null || value === void 0 || value === "";
15
+ }
16
+ StringUtils2.isEmpty = isEmpty;
17
+ function isNotEmpty(value) {
18
+ return !isEmpty(value);
19
+ }
20
+ StringUtils2.isNotEmpty = isNotEmpty;
21
+ function isBlank(value) {
22
+ if (isEmpty(value)) return true;
23
+ if (typeof value !== "string") return false;
24
+ return value.trim().length === 0;
25
+ }
26
+ StringUtils2.isBlank = isBlank;
27
+ function isNotBlank(value) {
28
+ return !isBlank(value);
29
+ }
30
+ StringUtils2.isNotBlank = isNotBlank;
31
+ function trim(value) {
32
+ return (value == null ? void 0 : value.trim()) ?? "";
33
+ }
34
+ StringUtils2.trim = trim;
35
+ function trimStart(value) {
36
+ return (value == null ? void 0 : value.trimStart()) ?? "";
37
+ }
38
+ StringUtils2.trimStart = trimStart;
39
+ function trimEnd(value) {
40
+ return (value == null ? void 0 : value.trimEnd()) ?? "";
41
+ }
42
+ StringUtils2.trimEnd = trimEnd;
43
+ function toLowerCase(value) {
44
+ return (value == null ? void 0 : value.toLowerCase()) ?? "";
45
+ }
46
+ StringUtils2.toLowerCase = toLowerCase;
47
+ function toUpperCase(value) {
48
+ return (value == null ? void 0 : value.toUpperCase()) ?? "";
49
+ }
50
+ StringUtils2.toUpperCase = toUpperCase;
51
+ function capitalize(value) {
52
+ if (isEmpty(value)) return "";
53
+ return value.charAt(0).toUpperCase() + value.slice(1).toLowerCase();
54
+ }
55
+ StringUtils2.capitalize = capitalize;
56
+ function capitalizeWords(value) {
57
+ if (isEmpty(value)) return "";
58
+ return value.split(/\s+/).map(capitalize).join(" ");
59
+ }
60
+ StringUtils2.capitalizeWords = capitalizeWords;
61
+ function camelCase(value) {
62
+ if (isEmpty(value)) return "";
63
+ return value.replace(/[-_\s]+(.)?/g, (_, char) => char ? char.toUpperCase() : "").replace(/^(.)/, (char) => char.toLowerCase());
64
+ }
65
+ StringUtils2.camelCase = camelCase;
66
+ function pascalCase(value) {
67
+ if (isEmpty(value)) return "";
68
+ const camel = camelCase(value);
69
+ return camel.charAt(0).toUpperCase() + camel.slice(1);
70
+ }
71
+ StringUtils2.pascalCase = pascalCase;
72
+ function kebabCase(value) {
73
+ if (isEmpty(value)) return "";
74
+ return value.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
75
+ }
76
+ StringUtils2.kebabCase = kebabCase;
77
+ function snakeCase(value) {
78
+ if (isEmpty(value)) return "";
79
+ return value.replace(/([a-z])([A-Z])/g, "$1_$2").replace(/[\s-]+/g, "_").toLowerCase();
80
+ }
81
+ StringUtils2.snakeCase = snakeCase;
82
+ function constantCase(value) {
83
+ return snakeCase(value).toUpperCase();
84
+ }
85
+ StringUtils2.constantCase = constantCase;
86
+ function truncate(value, length, suffix = "...") {
87
+ if (isEmpty(value) || value.length <= length) return value ?? "";
88
+ return value.slice(0, length - suffix.length) + suffix;
89
+ }
90
+ StringUtils2.truncate = truncate;
91
+ function truncateWords(value, wordCount2, suffix = "...") {
92
+ if (isEmpty(value)) return "";
93
+ const words2 = value.split(/\s+/);
94
+ if (words2.length <= wordCount2) return value;
95
+ return words2.slice(0, wordCount2).join(" ") + suffix;
96
+ }
97
+ StringUtils2.truncateWords = truncateWords;
98
+ function padStart(value, length, padChar = " ") {
99
+ return (value == null ? void 0 : value.padStart(length, padChar)) ?? "";
100
+ }
101
+ StringUtils2.padStart = padStart;
102
+ function padEnd(value, length, padChar = " ") {
103
+ return (value == null ? void 0 : value.padEnd(length, padChar)) ?? "";
104
+ }
105
+ StringUtils2.padEnd = padEnd;
106
+ function repeat(value, count) {
107
+ if (isEmpty(value) || count <= 0) return "";
108
+ return value.repeat(count);
109
+ }
110
+ StringUtils2.repeat = repeat;
111
+ function reverse(value) {
112
+ if (isEmpty(value)) return "";
113
+ return value.split("").reverse().join("");
114
+ }
115
+ StringUtils2.reverse = reverse;
116
+ function startsWith(value, prefix) {
117
+ return (value == null ? void 0 : value.startsWith(prefix)) ?? false;
118
+ }
119
+ StringUtils2.startsWith = startsWith;
120
+ function endsWith(value, suffix) {
121
+ return (value == null ? void 0 : value.endsWith(suffix)) ?? false;
122
+ }
123
+ StringUtils2.endsWith = endsWith;
124
+ function contains(value, search) {
125
+ return (value == null ? void 0 : value.includes(search)) ?? false;
126
+ }
127
+ StringUtils2.contains = contains;
128
+ function containsIgnoreCase(value, search) {
129
+ return (value == null ? void 0 : value.toLowerCase().includes(search.toLowerCase())) ?? false;
130
+ }
131
+ StringUtils2.containsIgnoreCase = containsIgnoreCase;
132
+ function indexOf(value, search) {
133
+ return (value == null ? void 0 : value.indexOf(search)) ?? -1;
134
+ }
135
+ StringUtils2.indexOf = indexOf;
136
+ function lastIndexOf(value, search) {
137
+ return (value == null ? void 0 : value.lastIndexOf(search)) ?? -1;
138
+ }
139
+ StringUtils2.lastIndexOf = lastIndexOf;
140
+ function substring(value, start, end) {
141
+ if (isEmpty(value)) return "";
142
+ return end !== void 0 ? value.slice(start, end) : value.slice(start);
143
+ }
144
+ StringUtils2.substring = substring;
145
+ function slice(value, start, end) {
146
+ return substring(value, start, end);
147
+ }
148
+ StringUtils2.slice = slice;
149
+ function split(value, separator, limit) {
150
+ if (isEmpty(value)) return [];
151
+ return value.split(separator, limit);
152
+ }
153
+ StringUtils2.split = split;
154
+ function join(values, separator = "") {
155
+ return (values == null ? void 0 : values.join(separator)) ?? "";
156
+ }
157
+ StringUtils2.join = join;
158
+ function replace(value, search, replacement) {
159
+ return (value == null ? void 0 : value.replace(search, replacement)) ?? "";
160
+ }
161
+ StringUtils2.replace = replace;
162
+ function replaceAll(value, search, replacement) {
163
+ return (value == null ? void 0 : value.replaceAll(search, replacement)) ?? "";
164
+ }
165
+ StringUtils2.replaceAll = replaceAll;
166
+ function remove(value, search) {
167
+ return (value == null ? void 0 : value.replace(search, "")) ?? "";
168
+ }
169
+ StringUtils2.remove = remove;
170
+ function removeAll(value, search) {
171
+ const regex = typeof search === "string" ? new RegExp(search, "g") : new RegExp(search.source, `${search.flags}g`);
172
+ return (value == null ? void 0 : value.replace(regex, "")) ?? "";
173
+ }
174
+ StringUtils2.removeAll = removeAll;
175
+ function countOccurrences(value, search) {
176
+ if (isEmpty(value) || isEmpty(search)) return 0;
177
+ return (value.match(new RegExp(escapeRegex(search), "g")) || []).length;
178
+ }
179
+ StringUtils2.countOccurrences = countOccurrences;
180
+ function escapeHtml(value) {
181
+ const htmlEntities = {
182
+ "&": "&amp;",
183
+ "<": "&lt;",
184
+ ">": "&gt;",
185
+ '"': "&quot;",
186
+ "'": "&#39;"
187
+ };
188
+ return (value == null ? void 0 : value.replace(/[&<>"']/g, (char) => htmlEntities[char] || char)) ?? "";
189
+ }
190
+ StringUtils2.escapeHtml = escapeHtml;
191
+ function unescapeHtml(value) {
192
+ const htmlEntities = {
193
+ "&amp;": "&",
194
+ "&lt;": "<",
195
+ "&gt;": ">",
196
+ "&quot;": '"',
197
+ "&#39;": "'",
198
+ "&#x27;": "'",
199
+ "&apos;": "'"
200
+ };
201
+ return (value == null ? void 0 : value.replace(/&(?:amp|lt|gt|quot|#39|#x27|apos);/g, (entity) => htmlEntities[entity] || entity)) ?? "";
202
+ }
203
+ StringUtils2.unescapeHtml = unescapeHtml;
204
+ function escapeRegex(value) {
205
+ return (value == null ? void 0 : value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")) ?? "";
206
+ }
207
+ StringUtils2.escapeRegex = escapeRegex;
208
+ function isNumeric(value) {
209
+ if (isEmpty(value)) return false;
210
+ return !isNaN(Number(value)) && !isNaN(parseFloat(value));
211
+ }
212
+ StringUtils2.isNumeric = isNumeric;
213
+ function isAlpha(value) {
214
+ if (isEmpty(value)) return false;
215
+ return /^[a-zA-Z]+$/.test(value);
216
+ }
217
+ StringUtils2.isAlpha = isAlpha;
218
+ function isAlphanumeric(value) {
219
+ if (isEmpty(value)) return false;
220
+ return /^[a-zA-Z0-9]+$/.test(value);
221
+ }
222
+ StringUtils2.isAlphanumeric = isAlphanumeric;
223
+ function isHex(value) {
224
+ if (isEmpty(value)) return false;
225
+ return /^[0-9a-fA-F]+$/.test(value);
226
+ }
227
+ StringUtils2.isHex = isHex;
228
+ function isUuid(value) {
229
+ if (isEmpty(value)) return false;
230
+ return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value);
231
+ }
232
+ StringUtils2.isUuid = isUuid;
233
+ function isEmail(value) {
234
+ if (isEmpty(value)) return false;
235
+ return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
236
+ }
237
+ StringUtils2.isEmail = isEmail;
238
+ function isUrl(value) {
239
+ if (isEmpty(value)) return false;
240
+ try {
241
+ new URL(value);
242
+ return true;
243
+ } catch {
244
+ return false;
245
+ }
246
+ }
247
+ StringUtils2.isUrl = isUrl;
248
+ function isPhoneNumber(value) {
249
+ if (isEmpty(value)) return false;
250
+ return /^\+?[\d\s-()]{10,}$/.test(value);
251
+ }
252
+ StringUtils2.isPhoneNumber = isPhoneNumber;
253
+ function mask(value, start, end, maskChar = "*") {
254
+ if (isEmpty(value)) return "";
255
+ const actualStart = Math.max(0, start);
256
+ const actualEnd = Math.min(value.length, end);
257
+ if (actualStart >= actualEnd) return value;
258
+ const masked = maskChar.repeat(actualEnd - actualStart);
259
+ return value.slice(0, actualStart) + masked + value.slice(actualEnd);
260
+ }
261
+ StringUtils2.mask = mask;
262
+ function maskEmail(value) {
263
+ if (!isEmail(value)) return value;
264
+ const parts = value.split("@");
265
+ const localPart = parts[0];
266
+ const domain = parts[1];
267
+ if (!localPart || !domain) return value;
268
+ const maskedLocal = mask(localPart, 2, localPart.length - 2);
269
+ return `${maskedLocal}@${domain}`;
270
+ }
271
+ StringUtils2.maskEmail = maskEmail;
272
+ function maskPhone(value) {
273
+ if (isEmpty(value)) return value;
274
+ const digits = value.replace(/\D/g, "");
275
+ if (digits.length < 7) return value;
276
+ return mask(digits, 3, digits.length - 4);
277
+ }
278
+ StringUtils2.maskPhone = maskPhone;
279
+ function maskCreditCard(value) {
280
+ if (isEmpty(value)) return value;
281
+ const digits = value.replace(/\D/g, "");
282
+ if (digits.length < 8) return value;
283
+ return mask(digits, 4, digits.length - 4);
284
+ }
285
+ StringUtils2.maskCreditCard = maskCreditCard;
286
+ function formatNumber(value, options) {
287
+ const num = typeof value === "string" ? parseFloat(value) : value;
288
+ if (isNaN(num)) return "";
289
+ return num.toLocaleString(void 0, options);
290
+ }
291
+ StringUtils2.formatNumber = formatNumber;
292
+ function formatCurrency(value, currency = "USD", locale) {
293
+ const num = typeof value === "string" ? parseFloat(value) : value;
294
+ if (isNaN(num)) return "";
295
+ return num.toLocaleString(locale, { style: "currency", currency });
296
+ }
297
+ StringUtils2.formatCurrency = formatCurrency;
298
+ function formatPercentage(value, decimals = 0) {
299
+ const num = typeof value === "string" ? parseFloat(value) : value;
300
+ if (isNaN(num)) return "";
301
+ return `${(num * 100).toFixed(decimals)}%`;
302
+ }
303
+ StringUtils2.formatPercentage = formatPercentage;
304
+ function formatBytes(bytes, decimals = 2) {
305
+ if (bytes === 0) return "0 Bytes";
306
+ const k = 1024;
307
+ const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB"];
308
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
309
+ return `${parseFloat((bytes / Math.pow(k, i)).toFixed(decimals))} ${sizes[i]}`;
310
+ }
311
+ StringUtils2.formatBytes = formatBytes;
312
+ function random(length = 16, charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") {
313
+ let result = "";
314
+ for (let i = 0; i < length; i++) {
315
+ result += charset.charAt(Math.floor(Math.random() * charset.length));
316
+ }
317
+ return result;
318
+ }
319
+ StringUtils2.random = random;
320
+ function uuid() {
321
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
322
+ const r = Math.random() * 16 | 0;
323
+ const v = c === "x" ? r : r & 3 | 8;
324
+ return v.toString(16);
325
+ });
326
+ }
327
+ StringUtils2.uuid = uuid;
328
+ function slugify(value) {
329
+ return (value == null ? void 0 : value.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "")) ?? "";
330
+ }
331
+ StringUtils2.slugify = slugify;
332
+ function unslugify(value) {
333
+ return (value == null ? void 0 : value.replace(/-/g, " ").replace(/\b\w/g, (char) => char.toUpperCase())) ?? "";
334
+ }
335
+ StringUtils2.unslugify = unslugify;
336
+ function levenshteinDistance(a, b) {
337
+ const matrix = [];
338
+ for (let i = 0; i <= b.length; i++) {
339
+ matrix[i] = [i];
340
+ }
341
+ for (let j = 0; j <= a.length; j++) {
342
+ if (matrix[0]) matrix[0][j] = j;
343
+ }
344
+ for (let i = 1; i <= b.length; i++) {
345
+ for (let j = 1; j <= a.length; j++) {
346
+ if (b.charAt(i - 1) === a.charAt(j - 1)) {
347
+ matrix[i][j] = matrix[i - 1][j - 1];
348
+ } else {
349
+ matrix[i][j] = Math.min(
350
+ matrix[i - 1][j - 1] + 1,
351
+ matrix[i][j - 1] + 1,
352
+ matrix[i - 1][j] + 1
353
+ );
354
+ }
355
+ }
356
+ }
357
+ return matrix[b.length][a.length];
358
+ }
359
+ StringUtils2.levenshteinDistance = levenshteinDistance;
360
+ function similarity(a, b) {
361
+ if (isEmpty(a) && isEmpty(b)) return 1;
362
+ if (isEmpty(a) || isEmpty(b)) return 0;
363
+ const distance = levenshteinDistance(a, b);
364
+ const maxLength = Math.max(a.length, b.length);
365
+ return 1 - distance / maxLength;
366
+ }
367
+ StringUtils2.similarity = similarity;
368
+ function fuzzyMatch(text, pattern, threshold = 0.6) {
369
+ return similarity(text, pattern) >= threshold;
370
+ }
371
+ StringUtils2.fuzzyMatch = fuzzyMatch;
372
+ function equals(a, b, ignoreCase = false) {
373
+ if (ignoreCase) {
374
+ return (a == null ? void 0 : a.toLowerCase()) === (b == null ? void 0 : b.toLowerCase());
375
+ }
376
+ return a === b;
377
+ }
378
+ StringUtils2.equals = equals;
379
+ function equalsIgnoreCase(a, b) {
380
+ return equals(a, b, true);
381
+ }
382
+ StringUtils2.equalsIgnoreCase = equalsIgnoreCase;
383
+ function wordCount(value) {
384
+ if (isEmpty(value)) return 0;
385
+ return value.trim().split(/\s+/).filter(Boolean).length;
386
+ }
387
+ StringUtils2.wordCount = wordCount;
388
+ function characterCount(value, includeSpaces = true) {
389
+ if (isEmpty(value)) return 0;
390
+ return includeSpaces ? value.length : value.replace(/\s/g, "").length;
391
+ }
392
+ StringUtils2.characterCount = characterCount;
393
+ function lineCount(value) {
394
+ if (isEmpty(value)) return 0;
395
+ return value.split(/\r?\n/).length;
396
+ }
397
+ StringUtils2.lineCount = lineCount;
398
+ function splitLines(value) {
399
+ if (isEmpty(value)) return [];
400
+ return value.split(/\r?\n/);
401
+ }
402
+ StringUtils2.splitLines = splitLines;
403
+ function words(value) {
404
+ if (isEmpty(value)) return [];
405
+ return value.trim().split(/\s+/).filter(Boolean);
406
+ }
407
+ StringUtils2.words = words;
408
+ function charAt(value, index) {
409
+ return (value == null ? void 0 : value.charAt(index)) ?? "";
410
+ }
411
+ StringUtils2.charAt = charAt;
412
+ function charCodeAt(value, index) {
413
+ return (value == null ? void 0 : value.charCodeAt(index)) ?? NaN;
414
+ }
415
+ StringUtils2.charCodeAt = charCodeAt;
416
+ function fromCharCode(...codes) {
417
+ return String.fromCharCode(...codes);
418
+ }
419
+ StringUtils2.fromCharCode = fromCharCode;
420
+ function insert(value, index, insertValue) {
421
+ if (isEmpty(value)) return insertValue;
422
+ return value.slice(0, index) + insertValue + value.slice(index);
423
+ }
424
+ StringUtils2.insert = insert;
425
+ function swapCase(value) {
426
+ return (value == null ? void 0 : value.replace(/[a-zA-Z]/g, (char) => {
427
+ return char === char.toUpperCase() ? char.toLowerCase() : char.toUpperCase();
428
+ })) ?? "";
429
+ }
430
+ StringUtils2.swapCase = swapCase;
431
+ function surround(value, wrapper) {
432
+ return `${wrapper}${value}${wrapper}`;
433
+ }
434
+ StringUtils2.surround = surround;
435
+ function quote(value, quoteChar = '"') {
436
+ return `${quoteChar}${value}${quoteChar}`;
437
+ }
438
+ StringUtils2.quote = quote;
439
+ function unquote(value) {
440
+ if (isEmpty(value)) return "";
441
+ if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'") || value.startsWith("`") && value.endsWith("`")) {
442
+ return value.slice(1, -1);
443
+ }
444
+ return value;
445
+ }
446
+ StringUtils2.unquote = unquote;
447
+ function wrap(value, prefix, suffix = prefix) {
448
+ return `${prefix}${value}${suffix}`;
449
+ }
450
+ StringUtils2.wrap = wrap;
451
+ function unwrap(value, prefix, suffix = prefix) {
452
+ if (isEmpty(value)) return "";
453
+ if (value.startsWith(prefix) && value.endsWith(suffix)) {
454
+ return value.slice(prefix.length, -suffix.length);
455
+ }
456
+ return value;
457
+ }
458
+ StringUtils2.unwrap = unwrap;
459
+ function template(templateStr, values) {
460
+ return (templateStr == null ? void 0 : templateStr.replace(/\{\{(\w+)\}\}/g, (_, key) => String(values[key] ?? ""))) ?? "";
461
+ }
462
+ StringUtils2.template = template;
463
+ function interpolate(templateStr, values) {
464
+ return template(templateStr, values);
465
+ }
466
+ StringUtils2.interpolate = interpolate;
467
+ function dedent(value) {
468
+ const lines = value.split("\n");
469
+ const minIndent = Math.min(
470
+ ...lines.filter((line) => line.trim().length > 0).map((line) => {
471
+ var _a;
472
+ return ((_a = line.match(/^\s*/)) == null ? void 0 : _a[0].length) ?? 0;
473
+ })
474
+ );
475
+ return lines.map((line) => line.slice(minIndent)).join("\n");
476
+ }
477
+ StringUtils2.dedent = dedent;
478
+ function indent(value, spaces = 2) {
479
+ const indentation = " ".repeat(spaces);
480
+ return value.split("\n").map((line) => indentation + line).join("\n");
481
+ }
482
+ StringUtils2.indent = indent;
483
+ function center(value, width, padChar = " ") {
484
+ if (isEmpty(value) || value.length >= width) return value ?? "";
485
+ const padding = width - value.length;
486
+ const leftPad = Math.floor(padding / 2);
487
+ const rightPad = padding - leftPad;
488
+ return padChar.repeat(leftPad) + value + padChar.repeat(rightPad);
489
+ }
490
+ StringUtils2.center = center;
491
+ function alignLeft(value, width, padChar = " ") {
492
+ return padEnd(value, width, padChar);
493
+ }
494
+ StringUtils2.alignLeft = alignLeft;
495
+ function alignRight(value, width, padChar = " ") {
496
+ return padStart(value, width, padChar);
497
+ }
498
+ StringUtils2.alignRight = alignRight;
499
+ function alignCenter(value, width, padChar = " ") {
500
+ return center(value, width, padChar);
501
+ }
502
+ StringUtils2.alignCenter = alignCenter;
503
+ function toBoolean(value) {
504
+ const truthy = ["true", "1", "yes", "on", "y"];
505
+ return truthy.includes(value == null ? void 0 : value.toLowerCase().trim());
506
+ }
507
+ StringUtils2.toBoolean = toBoolean;
508
+ function toNumber(value, defaultValue = 0) {
509
+ const num = parseFloat(value);
510
+ return isNaN(num) ? defaultValue : num;
511
+ }
512
+ StringUtils2.toNumber = toNumber;
513
+ function toArray(value, separator = ",") {
514
+ return split(value, separator);
515
+ }
516
+ StringUtils2.toArray = toArray;
517
+ function hashCode(value) {
518
+ let hash = 0;
519
+ for (let i = 0; i < value.length; i++) {
520
+ const char = value.charCodeAt(i);
521
+ hash = (hash << 5) - hash + char;
522
+ hash = hash & hash;
523
+ }
524
+ return hash;
525
+ }
526
+ StringUtils2.hashCode = hashCode;
527
+ function isPalindrome(value) {
528
+ const cleaned = value.toLowerCase().replace(/[^a-z0-9]/g, "");
529
+ return cleaned === cleaned.split("").reverse().join("");
530
+ }
531
+ StringUtils2.isPalindrome = isPalindrome;
532
+ function isAnagram(a, b) {
533
+ const normalize = (s) => s.toLowerCase().replace(/[^a-z0-9]/g, "").split("").sort().join("");
534
+ return normalize(a) === normalize(b);
535
+ }
536
+ StringUtils2.isAnagram = isAnagram;
537
+ function reverseWords(value) {
538
+ return (value == null ? void 0 : value.split(/\s+/).reverse().join(" ")) ?? "";
539
+ }
540
+ StringUtils2.reverseWords = reverseWords;
541
+ function sortCharacters(value) {
542
+ return (value == null ? void 0 : value.split("").sort().join("")) ?? "";
543
+ }
544
+ StringUtils2.sortCharacters = sortCharacters;
545
+ function uniqueCharacters(value) {
546
+ return [...new Set(value)].join("");
547
+ }
548
+ StringUtils2.uniqueCharacters = uniqueCharacters;
549
+ function removeDuplicates(value) {
550
+ return (value == null ? void 0 : value.split("").filter((char, index, arr) => arr.indexOf(char) === index).join("")) ?? "";
551
+ }
552
+ StringUtils2.removeDuplicates = removeDuplicates;
553
+ function longestCommonSubstring(a, b) {
554
+ if (isEmpty(a) || isEmpty(b)) return "";
555
+ const matrix = Array(a.length + 1).fill(null).map(() => Array(b.length + 1).fill(0));
556
+ let maxLength = 0;
557
+ let endIndex = 0;
558
+ for (let i = 1; i <= a.length; i++) {
559
+ for (let j = 1; j <= b.length; j++) {
560
+ if (a[i - 1] === b[j - 1]) {
561
+ matrix[i][j] = matrix[i - 1][j - 1] + 1;
562
+ if (matrix[i][j] > maxLength) {
563
+ maxLength = matrix[i][j];
564
+ endIndex = i;
565
+ }
566
+ }
567
+ }
568
+ }
569
+ return a.slice(endIndex - maxLength, endIndex);
570
+ }
571
+ StringUtils2.longestCommonSubstring = longestCommonSubstring;
572
+ function longestCommonPrefix(strings) {
573
+ if (strings.length === 0) return "";
574
+ if (strings.length === 1) return strings[0] ?? "";
575
+ const sorted = [...strings].sort();
576
+ const first = sorted[0] ?? "";
577
+ const last = sorted[sorted.length - 1] ?? "";
578
+ let i = 0;
579
+ while (i < first.length && first[i] === last[i]) {
580
+ i++;
581
+ }
582
+ return first.slice(0, i);
583
+ }
584
+ StringUtils2.longestCommonPrefix = longestCommonPrefix;
585
+ function longestCommonSuffix(strings) {
586
+ const reversed = strings.map((s) => (s == null ? void 0 : s.split("").reverse().join("")) ?? "");
587
+ return longestCommonPrefix(reversed).split("").reverse().join("");
588
+ }
589
+ StringUtils2.longestCommonSuffix = longestCommonSuffix;
590
+ function truncateMiddle(value, maxLength, separator = "...") {
591
+ if (isEmpty(value) || value.length <= maxLength) return value ?? "";
592
+ const sepLen = separator.length;
593
+ const charsToShow = maxLength - sepLen;
594
+ const frontChars = Math.ceil(charsToShow / 2);
595
+ const backChars = Math.floor(charsToShow / 2);
596
+ return value.slice(0, frontChars) + separator + value.slice(-backChars);
597
+ }
598
+ StringUtils2.truncateMiddle = truncateMiddle;
599
+ function ellipsis(value, maxLength) {
600
+ return truncate(value, maxLength, "...");
601
+ }
602
+ StringUtils2.ellipsis = ellipsis;
603
+ function ellipsisMiddle(value, maxLength) {
604
+ return truncateMiddle(value, maxLength, "...");
605
+ }
606
+ StringUtils2.ellipsisMiddle = ellipsisMiddle;
607
+ function pad(value, length, padChar = " ") {
608
+ return center(value, length, padChar);
609
+ }
610
+ StringUtils2.pad = pad;
611
+ function padCenter(value, length, padChar = " ") {
612
+ return center(value, length, padChar);
613
+ }
614
+ StringUtils2.padCenter = padCenter;
615
+ function isAscii(value) {
616
+ return /^[\x00-\x7F]*$/.test(value);
617
+ }
618
+ StringUtils2.isAscii = isAscii;
619
+ function isLowerCase(value) {
620
+ return value === value.toLowerCase();
621
+ }
622
+ StringUtils2.isLowerCase = isLowerCase;
623
+ function isUpperCase(value) {
624
+ return value === value.toUpperCase();
625
+ }
626
+ StringUtils2.isUpperCase = isUpperCase;
627
+ function isCapitalized(value) {
628
+ return value.charAt(0) === value.charAt(0).toUpperCase();
629
+ }
630
+ StringUtils2.isCapitalized = isCapitalized;
631
+ function swapPrefix(value, oldPrefix, newPrefix) {
632
+ if (value.startsWith(oldPrefix)) {
633
+ return newPrefix + value.slice(oldPrefix.length);
634
+ }
635
+ return value;
636
+ }
637
+ StringUtils2.swapPrefix = swapPrefix;
638
+ function swapSuffix(value, oldSuffix, newSuffix) {
639
+ if (value.endsWith(oldSuffix)) {
640
+ return value.slice(0, -oldSuffix.length) + newSuffix;
641
+ }
642
+ return value;
643
+ }
644
+ StringUtils2.swapSuffix = swapSuffix;
645
+ function ensurePrefix(value, prefix) {
646
+ return value.startsWith(prefix) ? value : prefix + value;
647
+ }
648
+ StringUtils2.ensurePrefix = ensurePrefix;
649
+ function ensureSuffix(value, suffix) {
650
+ return value.endsWith(suffix) ? value : value + suffix;
651
+ }
652
+ StringUtils2.ensureSuffix = ensureSuffix;
653
+ function removePrefix(value, prefix) {
654
+ return value.startsWith(prefix) ? value.slice(prefix.length) : value;
655
+ }
656
+ StringUtils2.removePrefix = removePrefix;
657
+ function removeSuffix(value, suffix) {
658
+ return value.endsWith(suffix) ? value.slice(0, -suffix.length) : value;
659
+ }
660
+ StringUtils2.removeSuffix = removeSuffix;
661
+ function take(value, n) {
662
+ return (value == null ? void 0 : value.slice(0, n)) ?? "";
663
+ }
664
+ StringUtils2.take = take;
665
+ function takeRight(value, n) {
666
+ return (value == null ? void 0 : value.slice(-n)) ?? "";
667
+ }
668
+ StringUtils2.takeRight = takeRight;
669
+ function takeWhile(value, predicate) {
670
+ let result = "";
671
+ for (const char of value ?? "") {
672
+ if (!predicate(char)) break;
673
+ result += char;
674
+ }
675
+ return result;
676
+ }
677
+ StringUtils2.takeWhile = takeWhile;
678
+ function takeRightWhile(value, predicate) {
679
+ let result = "";
680
+ for (let i = ((value == null ? void 0 : value.length) ?? 0) - 1; i >= 0; i--) {
681
+ const char = (value == null ? void 0 : value.charAt(i)) ?? "";
682
+ if (!predicate(char)) break;
683
+ result = char + result;
684
+ }
685
+ return result;
686
+ }
687
+ StringUtils2.takeRightWhile = takeRightWhile;
688
+ function drop(value, n) {
689
+ return (value == null ? void 0 : value.slice(n)) ?? "";
690
+ }
691
+ StringUtils2.drop = drop;
692
+ function dropRight(value, n) {
693
+ return (value == null ? void 0 : value.slice(0, -n)) ?? "";
694
+ }
695
+ StringUtils2.dropRight = dropRight;
696
+ function dropWhile(value, predicate) {
697
+ let i = 0;
698
+ for (const char of value ?? "") {
699
+ if (!predicate(char)) break;
700
+ i++;
701
+ }
702
+ return (value == null ? void 0 : value.slice(i)) ?? "";
703
+ }
704
+ StringUtils2.dropWhile = dropWhile;
705
+ function dropRightWhile(value, predicate) {
706
+ let i = ((value == null ? void 0 : value.length) ?? 0) - 1;
707
+ while (i >= 0 && predicate((value == null ? void 0 : value.charAt(i)) ?? "")) {
708
+ i--;
709
+ }
710
+ return (value == null ? void 0 : value.slice(0, i + 1)) ?? "";
711
+ }
712
+ StringUtils2.dropRightWhile = dropRightWhile;
713
+ function countLines(value) {
714
+ return lineCount(value);
715
+ }
716
+ StringUtils2.countLines = countLines;
717
+ function getLine(value, lineNumber) {
718
+ const lines = splitLines(value);
719
+ return lines[lineNumber] ?? "";
720
+ }
721
+ StringUtils2.getLine = getLine;
722
+ function getLines(value) {
723
+ return splitLines(value);
724
+ }
725
+ StringUtils2.getLines = getLines;
726
+ function isSingleLine(value) {
727
+ return !(value == null ? void 0 : value.includes("\n"));
728
+ }
729
+ StringUtils2.isSingleLine = isSingleLine;
730
+ function isMultiLine(value) {
731
+ return (value == null ? void 0 : value.includes("\n")) ?? false;
732
+ }
733
+ StringUtils2.isMultiLine = isMultiLine;
734
+ function normalizeLineEndings(value, lineEnding = "\n") {
735
+ return (value == null ? void 0 : value.replace(/\r\n|\r|\n/g, lineEnding)) ?? "";
736
+ }
737
+ StringUtils2.normalizeLineEndings = normalizeLineEndings;
738
+ function toCamelCase(value) {
739
+ return camelCase(value);
740
+ }
741
+ StringUtils2.toCamelCase = toCamelCase;
742
+ function toKebabCase(value) {
743
+ return kebabCase(value);
744
+ }
745
+ StringUtils2.toKebabCase = toKebabCase;
746
+ function toSnakeCase(value) {
747
+ return snakeCase(value);
748
+ }
749
+ StringUtils2.toSnakeCase = toSnakeCase;
750
+ function toPascalCase(value) {
751
+ return pascalCase(value);
752
+ }
753
+ StringUtils2.toPascalCase = toPascalCase;
754
+ function toConstantCase(value) {
755
+ return constantCase(value);
756
+ }
757
+ StringUtils2.toConstantCase = toConstantCase;
758
+ function toSentenceCase(value) {
759
+ if (isEmpty(value)) return "";
760
+ return value.charAt(0).toUpperCase() + value.slice(1).toLowerCase();
761
+ }
762
+ StringUtils2.toSentenceCase = toSentenceCase;
763
+ function toTitleCase(value) {
764
+ return capitalizeWords(value);
765
+ }
766
+ StringUtils2.toTitleCase = toTitleCase;
767
+ function toCapitalCase(value) {
768
+ return capitalizeWords(value);
769
+ }
770
+ StringUtils2.toCapitalCase = toCapitalCase;
771
+ function toDotCase(value) {
772
+ return (value == null ? void 0 : value.replace(/([a-z])([A-Z])/g, "$1.$2").replace(/[-_\s]+/g, ".").toLowerCase()) ?? "";
773
+ }
774
+ StringUtils2.toDotCase = toDotCase;
775
+ function toPathCase(value) {
776
+ return (value == null ? void 0 : value.replace(/([a-z])([A-Z])/g, "$1/$2").replace(/[-_\s]+/g, "/").toLowerCase()) ?? "";
777
+ }
778
+ StringUtils2.toPathCase = toPathCase;
779
+ function stripTags(value) {
780
+ return (value == null ? void 0 : value.replace(/<[^>]*>/g, "")) ?? "";
781
+ }
782
+ StringUtils2.stripTags = stripTags;
783
+ function stripNumbers(value) {
784
+ return (value == null ? void 0 : value.replace(/\d+/g, "")) ?? "";
785
+ }
786
+ StringUtils2.stripNumbers = stripNumbers;
787
+ function stripWhitespace(value) {
788
+ return (value == null ? void 0 : value.replace(/\s+/g, "")) ?? "";
789
+ }
790
+ StringUtils2.stripWhitespace = stripWhitespace;
791
+ function stripPunctuation(value) {
792
+ return (value == null ? void 0 : value.replace(/[^\w\s]/g, "")) ?? "";
793
+ }
794
+ StringUtils2.stripPunctuation = stripPunctuation;
795
+ function normalizeWhitespace(value) {
796
+ return (value == null ? void 0 : value.replace(/\s+/g, " ").trim()) ?? "";
797
+ }
798
+ StringUtils2.normalizeWhitespace = normalizeWhitespace;
799
+ function includesAll(value, searches) {
800
+ return searches.every((search) => (value == null ? void 0 : value.includes(search)) ?? false);
801
+ }
802
+ StringUtils2.includesAll = includesAll;
803
+ function includesAny(value, searches) {
804
+ return searches.some((search) => (value == null ? void 0 : value.includes(search)) ?? false);
805
+ }
806
+ StringUtils2.includesAny = includesAny;
807
+ })(StringUtils || (StringUtils = {}));
808
+ export {
809
+ BACKSLASH,
810
+ CARRIAGE_RETURN,
811
+ DASH,
812
+ DOT,
813
+ EMPTY_STRING,
814
+ NEWLINE,
815
+ SLASH,
816
+ SPACE,
817
+ StringUtils,
818
+ TAB,
819
+ UNDERSCORE
820
+ };
821
+ //# sourceMappingURL=string.js.map