@lee-zg/melange 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.
- package/LICENSE +21 -0
- package/README.md +256 -0
- package/dist/chunk-2PXWQDZC.js +659 -0
- package/dist/chunk-2PXWQDZC.js.map +1 -0
- package/dist/chunk-352XNR3C.js +716 -0
- package/dist/chunk-352XNR3C.js.map +1 -0
- package/dist/chunk-7QVYU63E.js +6 -0
- package/dist/chunk-7QVYU63E.js.map +1 -0
- package/dist/chunk-ALBD5XC5.js +285 -0
- package/dist/chunk-ALBD5XC5.js.map +1 -0
- package/dist/chunk-O7K662J5.cjs +842 -0
- package/dist/chunk-O7K662J5.cjs.map +1 -0
- package/dist/chunk-PK6SKIKE.cjs +8 -0
- package/dist/chunk-PK6SKIKE.cjs.map +1 -0
- package/dist/chunk-Q73NOVWX.cjs +789 -0
- package/dist/chunk-Q73NOVWX.cjs.map +1 -0
- package/dist/chunk-Q7XG6YN6.cjs +682 -0
- package/dist/chunk-Q7XG6YN6.cjs.map +1 -0
- package/dist/chunk-YGMBCZJQ.js +833 -0
- package/dist/chunk-YGMBCZJQ.js.map +1 -0
- package/dist/chunk-ZT6HVG4G.cjs +330 -0
- package/dist/chunk-ZT6HVG4G.cjs.map +1 -0
- package/dist/core/index.cjs +97 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +718 -0
- package/dist/core/index.d.ts +718 -0
- package/dist/core/index.js +4 -0
- package/dist/core/index.js.map +1 -0
- package/dist/fp/index.cjs +185 -0
- package/dist/fp/index.cjs.map +1 -0
- package/dist/fp/index.d.cts +913 -0
- package/dist/fp/index.d.ts +913 -0
- package/dist/fp/index.js +4 -0
- package/dist/fp/index.js.map +1 -0
- package/dist/index.cjs +608 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +39 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/index.cjs +41 -0
- package/dist/plugins/index.cjs.map +1 -0
- package/dist/plugins/index.d.cts +643 -0
- package/dist/plugins/index.d.ts +643 -0
- package/dist/plugins/index.js +4 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/types-BtOUCLB-.d.cts +293 -0
- package/dist/types-BtOUCLB-.d.ts +293 -0
- package/dist/utils/index.cjs +297 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +1179 -0
- package/dist/utils/index.d.ts +1179 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +132 -0
|
@@ -0,0 +1,716 @@
|
|
|
1
|
+
import { __name } from './chunk-7QVYU63E.js';
|
|
2
|
+
|
|
3
|
+
// src/utils/object.ts
|
|
4
|
+
function deepClone(value) {
|
|
5
|
+
if (value === null || typeof value !== "object") {
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
if (value instanceof Date) {
|
|
9
|
+
return new Date(value.getTime());
|
|
10
|
+
}
|
|
11
|
+
if (value instanceof RegExp) {
|
|
12
|
+
return new RegExp(value.source, value.flags);
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
return value.map((item) => deepClone(item));
|
|
16
|
+
}
|
|
17
|
+
if (value instanceof Map) {
|
|
18
|
+
const result2 = /* @__PURE__ */ new Map();
|
|
19
|
+
value.forEach((v, k) => {
|
|
20
|
+
result2.set(deepClone(k), deepClone(v));
|
|
21
|
+
});
|
|
22
|
+
return result2;
|
|
23
|
+
}
|
|
24
|
+
if (value instanceof Set) {
|
|
25
|
+
const result2 = /* @__PURE__ */ new Set();
|
|
26
|
+
value.forEach((v) => {
|
|
27
|
+
result2.add(deepClone(v));
|
|
28
|
+
});
|
|
29
|
+
return result2;
|
|
30
|
+
}
|
|
31
|
+
const result = {};
|
|
32
|
+
for (const key of Object.keys(value)) {
|
|
33
|
+
result[key] = deepClone(value[key]);
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
__name(deepClone, "deepClone");
|
|
38
|
+
function deepMerge(...objects) {
|
|
39
|
+
const result = {};
|
|
40
|
+
for (const obj of objects) {
|
|
41
|
+
if (!obj) continue;
|
|
42
|
+
for (const key of Object.keys(obj)) {
|
|
43
|
+
const targetValue = result[key];
|
|
44
|
+
const sourceValue = obj[key];
|
|
45
|
+
if (isPlainObject(targetValue) && isPlainObject(sourceValue)) {
|
|
46
|
+
result[key] = deepMerge(
|
|
47
|
+
targetValue,
|
|
48
|
+
sourceValue
|
|
49
|
+
);
|
|
50
|
+
} else {
|
|
51
|
+
result[key] = deepClone(sourceValue);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
__name(deepMerge, "deepMerge");
|
|
58
|
+
function pick(obj, keys) {
|
|
59
|
+
const result = {};
|
|
60
|
+
for (const key of keys) {
|
|
61
|
+
if (key in obj) {
|
|
62
|
+
result[key] = obj[key];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
__name(pick, "pick");
|
|
68
|
+
function omit(obj, keys) {
|
|
69
|
+
const keysSet = new Set(keys);
|
|
70
|
+
const result = {};
|
|
71
|
+
for (const key of Object.keys(obj)) {
|
|
72
|
+
if (!keysSet.has(key)) {
|
|
73
|
+
result[key] = obj[key];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
__name(omit, "omit");
|
|
79
|
+
function get(obj, path, defaultValue) {
|
|
80
|
+
const keys = typeof path === "string" ? path.split(".") : path;
|
|
81
|
+
let result = obj;
|
|
82
|
+
for (const key of keys) {
|
|
83
|
+
if (result == null || typeof result !== "object") {
|
|
84
|
+
return defaultValue;
|
|
85
|
+
}
|
|
86
|
+
result = result[key];
|
|
87
|
+
}
|
|
88
|
+
return result === void 0 ? defaultValue : result;
|
|
89
|
+
}
|
|
90
|
+
__name(get, "get");
|
|
91
|
+
function set(obj, path, value) {
|
|
92
|
+
const keys = typeof path === "string" ? path.split(".") : path;
|
|
93
|
+
let current = obj;
|
|
94
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
95
|
+
const key = keys[i];
|
|
96
|
+
if (key === void 0) continue;
|
|
97
|
+
if (current[key] == null || typeof current[key] !== "object") {
|
|
98
|
+
current[key] = {};
|
|
99
|
+
}
|
|
100
|
+
current = current[key];
|
|
101
|
+
}
|
|
102
|
+
const lastKey = keys[keys.length - 1];
|
|
103
|
+
if (lastKey !== void 0) {
|
|
104
|
+
current[lastKey] = value;
|
|
105
|
+
}
|
|
106
|
+
return obj;
|
|
107
|
+
}
|
|
108
|
+
__name(set, "set");
|
|
109
|
+
function has(obj, path) {
|
|
110
|
+
const keys = typeof path === "string" ? path.split(".") : path;
|
|
111
|
+
let current = obj;
|
|
112
|
+
for (const key of keys) {
|
|
113
|
+
if (current == null || typeof current !== "object") {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
if (!(key in current)) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
current = current[key];
|
|
120
|
+
}
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
__name(has, "has");
|
|
124
|
+
function isPlainObject(value) {
|
|
125
|
+
if (typeof value !== "object" || value === null) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
const proto = Object.getPrototypeOf(value);
|
|
129
|
+
return proto === Object.prototype || proto === null;
|
|
130
|
+
}
|
|
131
|
+
__name(isPlainObject, "isPlainObject");
|
|
132
|
+
function fromEntries(entries) {
|
|
133
|
+
const result = {};
|
|
134
|
+
for (const [key, value] of entries) {
|
|
135
|
+
result[key] = value;
|
|
136
|
+
}
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
__name(fromEntries, "fromEntries");
|
|
140
|
+
function mapValues(obj, fn) {
|
|
141
|
+
const result = {};
|
|
142
|
+
for (const key of Object.keys(obj)) {
|
|
143
|
+
const value = obj[key];
|
|
144
|
+
if (value !== void 0) {
|
|
145
|
+
result[key] = fn(value, key);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
__name(mapValues, "mapValues");
|
|
151
|
+
function filterObject(obj, predicate) {
|
|
152
|
+
const result = {};
|
|
153
|
+
for (const key of Object.keys(obj)) {
|
|
154
|
+
const value = obj[key];
|
|
155
|
+
if (value !== void 0 && predicate(value, key)) {
|
|
156
|
+
result[key] = value;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
__name(filterObject, "filterObject");
|
|
162
|
+
|
|
163
|
+
// src/utils/array.ts
|
|
164
|
+
function chunk(array, size) {
|
|
165
|
+
if (size <= 0) {
|
|
166
|
+
throw new Error("Chunk size must be positive");
|
|
167
|
+
}
|
|
168
|
+
const result = [];
|
|
169
|
+
for (let i = 0; i < array.length; i += size) {
|
|
170
|
+
result.push(array.slice(i, i + size));
|
|
171
|
+
}
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
__name(chunk, "chunk");
|
|
175
|
+
function flatten(array) {
|
|
176
|
+
const result = [];
|
|
177
|
+
for (const item of array) {
|
|
178
|
+
if (Array.isArray(item)) {
|
|
179
|
+
result.push(...item);
|
|
180
|
+
} else {
|
|
181
|
+
result.push(item);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
__name(flatten, "flatten");
|
|
187
|
+
function flattenDeep(array) {
|
|
188
|
+
const result = [];
|
|
189
|
+
function flattenHelper(arr) {
|
|
190
|
+
for (const item of arr) {
|
|
191
|
+
if (Array.isArray(item)) {
|
|
192
|
+
flattenHelper(item);
|
|
193
|
+
} else {
|
|
194
|
+
result.push(item);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
__name(flattenHelper, "flattenHelper");
|
|
199
|
+
flattenHelper(array);
|
|
200
|
+
return result;
|
|
201
|
+
}
|
|
202
|
+
__name(flattenDeep, "flattenDeep");
|
|
203
|
+
function unique(array, keyFn) {
|
|
204
|
+
if (!keyFn) {
|
|
205
|
+
return [...new Set(array)];
|
|
206
|
+
}
|
|
207
|
+
const seen = /* @__PURE__ */ new Set();
|
|
208
|
+
const result = [];
|
|
209
|
+
for (const item of array) {
|
|
210
|
+
const key = keyFn(item);
|
|
211
|
+
if (!seen.has(key)) {
|
|
212
|
+
seen.add(key);
|
|
213
|
+
result.push(item);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return result;
|
|
217
|
+
}
|
|
218
|
+
__name(unique, "unique");
|
|
219
|
+
function groupBy(array, keyFn) {
|
|
220
|
+
const result = {};
|
|
221
|
+
for (const item of array) {
|
|
222
|
+
const key = keyFn(item);
|
|
223
|
+
if (!result[key]) {
|
|
224
|
+
result[key] = [];
|
|
225
|
+
}
|
|
226
|
+
result[key].push(item);
|
|
227
|
+
}
|
|
228
|
+
return result;
|
|
229
|
+
}
|
|
230
|
+
__name(groupBy, "groupBy");
|
|
231
|
+
function sortBy(array, keyFn, order = "asc") {
|
|
232
|
+
const multiplier = order === "asc" ? 1 : -1;
|
|
233
|
+
return [...array].sort((a, b) => {
|
|
234
|
+
const keyA = keyFn(a);
|
|
235
|
+
const keyB = keyFn(b);
|
|
236
|
+
if (keyA < keyB) return -1 * multiplier;
|
|
237
|
+
if (keyA > keyB) return 1 * multiplier;
|
|
238
|
+
return 0;
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
__name(sortBy, "sortBy");
|
|
242
|
+
function partition(array, predicate) {
|
|
243
|
+
const pass = [];
|
|
244
|
+
const fail = [];
|
|
245
|
+
for (const item of array) {
|
|
246
|
+
if (predicate(item)) {
|
|
247
|
+
pass.push(item);
|
|
248
|
+
} else {
|
|
249
|
+
fail.push(item);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return [pass, fail];
|
|
253
|
+
}
|
|
254
|
+
__name(partition, "partition");
|
|
255
|
+
function zip(arr1, arr2) {
|
|
256
|
+
const length = Math.min(arr1.length, arr2.length);
|
|
257
|
+
const result = [];
|
|
258
|
+
for (let i = 0; i < length; i++) {
|
|
259
|
+
const first2 = arr1[i];
|
|
260
|
+
const second = arr2[i];
|
|
261
|
+
if (first2 !== void 0 && second !== void 0) {
|
|
262
|
+
result.push([first2, second]);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return result;
|
|
266
|
+
}
|
|
267
|
+
__name(zip, "zip");
|
|
268
|
+
function first(array) {
|
|
269
|
+
return array[0];
|
|
270
|
+
}
|
|
271
|
+
__name(first, "first");
|
|
272
|
+
function last(array) {
|
|
273
|
+
return array[array.length - 1];
|
|
274
|
+
}
|
|
275
|
+
__name(last, "last");
|
|
276
|
+
function sample(array) {
|
|
277
|
+
if (array.length === 0) return void 0;
|
|
278
|
+
return array[Math.floor(Math.random() * array.length)];
|
|
279
|
+
}
|
|
280
|
+
__name(sample, "sample");
|
|
281
|
+
function shuffle(array) {
|
|
282
|
+
const result = [...array];
|
|
283
|
+
for (let i = result.length - 1; i > 0; i--) {
|
|
284
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
285
|
+
[result[i], result[j]] = [result[j], result[i]];
|
|
286
|
+
}
|
|
287
|
+
return result;
|
|
288
|
+
}
|
|
289
|
+
__name(shuffle, "shuffle");
|
|
290
|
+
function range(startOrEnd, end, step = 1) {
|
|
291
|
+
let start = 0;
|
|
292
|
+
let finalEnd = startOrEnd;
|
|
293
|
+
if (end !== void 0) {
|
|
294
|
+
start = startOrEnd;
|
|
295
|
+
finalEnd = end;
|
|
296
|
+
}
|
|
297
|
+
if (step === 0) {
|
|
298
|
+
throw new Error("Step cannot be zero");
|
|
299
|
+
}
|
|
300
|
+
const result = [];
|
|
301
|
+
if (step > 0) {
|
|
302
|
+
for (let i = start; i < finalEnd; i += step) {
|
|
303
|
+
result.push(i);
|
|
304
|
+
}
|
|
305
|
+
} else {
|
|
306
|
+
for (let i = start; i > finalEnd; i += step) {
|
|
307
|
+
result.push(i);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return result;
|
|
311
|
+
}
|
|
312
|
+
__name(range, "range");
|
|
313
|
+
function intersection(arr1, arr2) {
|
|
314
|
+
const set2 = new Set(arr2);
|
|
315
|
+
return arr1.filter((item) => set2.has(item));
|
|
316
|
+
}
|
|
317
|
+
__name(intersection, "intersection");
|
|
318
|
+
function difference(arr1, arr2) {
|
|
319
|
+
const set2 = new Set(arr2);
|
|
320
|
+
return arr1.filter((item) => !set2.has(item));
|
|
321
|
+
}
|
|
322
|
+
__name(difference, "difference");
|
|
323
|
+
|
|
324
|
+
// src/utils/string.ts
|
|
325
|
+
function capitalize(str) {
|
|
326
|
+
if (str.length === 0) return str;
|
|
327
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
328
|
+
}
|
|
329
|
+
__name(capitalize, "capitalize");
|
|
330
|
+
function camelCase(str) {
|
|
331
|
+
return str.replace(
|
|
332
|
+
/[\s_-]+(.)?/g,
|
|
333
|
+
(_, char) => char ? char.toUpperCase() : ""
|
|
334
|
+
).replace(/^[A-Z]/, (char) => char.toLowerCase());
|
|
335
|
+
}
|
|
336
|
+
__name(camelCase, "camelCase");
|
|
337
|
+
function pascalCase(str) {
|
|
338
|
+
return capitalize(camelCase(str));
|
|
339
|
+
}
|
|
340
|
+
__name(pascalCase, "pascalCase");
|
|
341
|
+
function snakeCase(str) {
|
|
342
|
+
return str.replace(/[\s-]+/g, "_").replace(/([a-z])([A-Z])/g, "$1_$2").replace(/([A-Z])([A-Z][a-z])/g, "$1_$2").toLowerCase();
|
|
343
|
+
}
|
|
344
|
+
__name(snakeCase, "snakeCase");
|
|
345
|
+
function kebabCase(str) {
|
|
346
|
+
return str.replace(/[\s_]+/g, "-").replace(/([a-z])([A-Z])/g, "$1-$2").replace(/([A-Z])([A-Z][a-z])/g, "$1-$2").toLowerCase();
|
|
347
|
+
}
|
|
348
|
+
__name(kebabCase, "kebabCase");
|
|
349
|
+
function constantCase(str) {
|
|
350
|
+
return snakeCase(str).toUpperCase();
|
|
351
|
+
}
|
|
352
|
+
__name(constantCase, "constantCase");
|
|
353
|
+
function truncate(str, maxLength, suffix = "...") {
|
|
354
|
+
if (str.length <= maxLength) return str;
|
|
355
|
+
return str.slice(0, maxLength - suffix.length) + suffix;
|
|
356
|
+
}
|
|
357
|
+
__name(truncate, "truncate");
|
|
358
|
+
function padStart(str, length, padChar = " ") {
|
|
359
|
+
if (str.length >= length) return str;
|
|
360
|
+
const padding = padChar.repeat(Math.ceil((length - str.length) / padChar.length));
|
|
361
|
+
return (padding + str).slice(-length);
|
|
362
|
+
}
|
|
363
|
+
__name(padStart, "padStart");
|
|
364
|
+
function padEnd(str, length, padChar = " ") {
|
|
365
|
+
if (str.length >= length) return str;
|
|
366
|
+
const padding = padChar.repeat(Math.ceil((length - str.length) / padChar.length));
|
|
367
|
+
return (str + padding).slice(0, length);
|
|
368
|
+
}
|
|
369
|
+
__name(padEnd, "padEnd");
|
|
370
|
+
function collapseWhitespace(str) {
|
|
371
|
+
return str.replace(/\s+/g, " ").trim();
|
|
372
|
+
}
|
|
373
|
+
__name(collapseWhitespace, "collapseWhitespace");
|
|
374
|
+
function escapeHtml(str) {
|
|
375
|
+
const htmlEntities = {
|
|
376
|
+
"&": "&",
|
|
377
|
+
"<": "<",
|
|
378
|
+
">": ">",
|
|
379
|
+
'"': """,
|
|
380
|
+
"'": "'"
|
|
381
|
+
};
|
|
382
|
+
return str.replace(/[&<>"']/g, (char) => htmlEntities[char] ?? char);
|
|
383
|
+
}
|
|
384
|
+
__name(escapeHtml, "escapeHtml");
|
|
385
|
+
function unescapeHtml(str) {
|
|
386
|
+
const htmlEntities = {
|
|
387
|
+
"&": "&",
|
|
388
|
+
"<": "<",
|
|
389
|
+
">": ">",
|
|
390
|
+
""": '"',
|
|
391
|
+
"'": "'",
|
|
392
|
+
"'": "'"
|
|
393
|
+
};
|
|
394
|
+
return str.replace(
|
|
395
|
+
/&(?:amp|lt|gt|quot|#39|apos);/g,
|
|
396
|
+
(entity) => htmlEntities[entity] ?? entity
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
__name(unescapeHtml, "unescapeHtml");
|
|
400
|
+
function randomString(length, chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") {
|
|
401
|
+
let result = "";
|
|
402
|
+
for (let i = 0; i < length; i++) {
|
|
403
|
+
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
404
|
+
}
|
|
405
|
+
return result;
|
|
406
|
+
}
|
|
407
|
+
__name(randomString, "randomString");
|
|
408
|
+
function words(str) {
|
|
409
|
+
return str.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[\s_-]+/g, " ").trim().split(" ").filter((word) => word.length > 0);
|
|
410
|
+
}
|
|
411
|
+
__name(words, "words");
|
|
412
|
+
function titleCase(str) {
|
|
413
|
+
return words(str).map((word) => capitalize(word.toLowerCase())).join(" ");
|
|
414
|
+
}
|
|
415
|
+
__name(titleCase, "titleCase");
|
|
416
|
+
function reverse(str) {
|
|
417
|
+
return [...str].reverse().join("");
|
|
418
|
+
}
|
|
419
|
+
__name(reverse, "reverse");
|
|
420
|
+
function countOccurrences(str, substr) {
|
|
421
|
+
if (substr.length === 0) return 0;
|
|
422
|
+
let count = 0;
|
|
423
|
+
let pos = 0;
|
|
424
|
+
while ((pos = str.indexOf(substr, pos)) !== -1) {
|
|
425
|
+
count++;
|
|
426
|
+
pos += substr.length;
|
|
427
|
+
}
|
|
428
|
+
return count;
|
|
429
|
+
}
|
|
430
|
+
__name(countOccurrences, "countOccurrences");
|
|
431
|
+
|
|
432
|
+
// src/utils/timing.ts
|
|
433
|
+
function debounce(fn, wait, options) {
|
|
434
|
+
const { leading = false, trailing = true } = options ?? {};
|
|
435
|
+
let timeoutId = null;
|
|
436
|
+
let lastArgs = null;
|
|
437
|
+
let lastThis = null;
|
|
438
|
+
let result;
|
|
439
|
+
function invokeFunc() {
|
|
440
|
+
if (lastArgs !== null) {
|
|
441
|
+
result = fn.apply(lastThis, lastArgs);
|
|
442
|
+
lastArgs = null;
|
|
443
|
+
lastThis = null;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
__name(invokeFunc, "invokeFunc");
|
|
447
|
+
function debounced(...args) {
|
|
448
|
+
lastArgs = args;
|
|
449
|
+
lastThis = this;
|
|
450
|
+
if (leading && timeoutId === null) {
|
|
451
|
+
invokeFunc();
|
|
452
|
+
}
|
|
453
|
+
if (timeoutId !== null) {
|
|
454
|
+
clearTimeout(timeoutId);
|
|
455
|
+
}
|
|
456
|
+
timeoutId = setTimeout(() => {
|
|
457
|
+
if (trailing) {
|
|
458
|
+
invokeFunc();
|
|
459
|
+
}
|
|
460
|
+
timeoutId = null;
|
|
461
|
+
}, wait);
|
|
462
|
+
return result;
|
|
463
|
+
}
|
|
464
|
+
__name(debounced, "debounced");
|
|
465
|
+
debounced.cancel = () => {
|
|
466
|
+
if (timeoutId !== null) {
|
|
467
|
+
clearTimeout(timeoutId);
|
|
468
|
+
timeoutId = null;
|
|
469
|
+
}
|
|
470
|
+
lastArgs = null;
|
|
471
|
+
lastThis = null;
|
|
472
|
+
};
|
|
473
|
+
debounced.flush = () => {
|
|
474
|
+
if (timeoutId !== null) {
|
|
475
|
+
clearTimeout(timeoutId);
|
|
476
|
+
timeoutId = null;
|
|
477
|
+
if (trailing) {
|
|
478
|
+
invokeFunc();
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
return debounced;
|
|
483
|
+
}
|
|
484
|
+
__name(debounce, "debounce");
|
|
485
|
+
function throttle(fn, limit) {
|
|
486
|
+
let lastCall = 0;
|
|
487
|
+
let timeoutId = null;
|
|
488
|
+
let lastArgs = null;
|
|
489
|
+
let lastThis = null;
|
|
490
|
+
function throttled(...args) {
|
|
491
|
+
const now = Date.now();
|
|
492
|
+
const remaining = limit - (now - lastCall);
|
|
493
|
+
lastArgs = args;
|
|
494
|
+
lastThis = this;
|
|
495
|
+
if (remaining <= 0) {
|
|
496
|
+
if (timeoutId !== null) {
|
|
497
|
+
clearTimeout(timeoutId);
|
|
498
|
+
timeoutId = null;
|
|
499
|
+
}
|
|
500
|
+
lastCall = now;
|
|
501
|
+
return fn.apply(this, args);
|
|
502
|
+
}
|
|
503
|
+
if (timeoutId === null) {
|
|
504
|
+
timeoutId = setTimeout(() => {
|
|
505
|
+
lastCall = Date.now();
|
|
506
|
+
timeoutId = null;
|
|
507
|
+
if (lastArgs !== null) {
|
|
508
|
+
fn.apply(lastThis, lastArgs);
|
|
509
|
+
lastArgs = null;
|
|
510
|
+
lastThis = null;
|
|
511
|
+
}
|
|
512
|
+
}, remaining);
|
|
513
|
+
}
|
|
514
|
+
return void 0;
|
|
515
|
+
}
|
|
516
|
+
__name(throttled, "throttled");
|
|
517
|
+
throttled.cancel = () => {
|
|
518
|
+
if (timeoutId !== null) {
|
|
519
|
+
clearTimeout(timeoutId);
|
|
520
|
+
timeoutId = null;
|
|
521
|
+
}
|
|
522
|
+
lastArgs = null;
|
|
523
|
+
lastThis = null;
|
|
524
|
+
};
|
|
525
|
+
return throttled;
|
|
526
|
+
}
|
|
527
|
+
__name(throttle, "throttle");
|
|
528
|
+
function delay(ms, value) {
|
|
529
|
+
return new Promise((resolve) => setTimeout(() => resolve(value), ms));
|
|
530
|
+
}
|
|
531
|
+
__name(delay, "delay");
|
|
532
|
+
async function retry(fn, options) {
|
|
533
|
+
const {
|
|
534
|
+
maxRetries = 3,
|
|
535
|
+
delay: retryDelay = 1e3,
|
|
536
|
+
backoff = "none",
|
|
537
|
+
onRetry
|
|
538
|
+
} = options ?? {};
|
|
539
|
+
let lastError;
|
|
540
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
541
|
+
try {
|
|
542
|
+
return await fn();
|
|
543
|
+
} catch (error) {
|
|
544
|
+
lastError = error;
|
|
545
|
+
if (attempt < maxRetries) {
|
|
546
|
+
onRetry?.(error, attempt + 1);
|
|
547
|
+
let waitTime = retryDelay;
|
|
548
|
+
if (backoff === "linear") {
|
|
549
|
+
waitTime = retryDelay * (attempt + 1);
|
|
550
|
+
} else if (backoff === "exponential") {
|
|
551
|
+
waitTime = retryDelay * Math.pow(2, attempt);
|
|
552
|
+
}
|
|
553
|
+
await delay(waitTime);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
throw lastError;
|
|
558
|
+
}
|
|
559
|
+
__name(retry, "retry");
|
|
560
|
+
function timeout(promise, ms, errorMessage) {
|
|
561
|
+
let timeoutId;
|
|
562
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
563
|
+
timeoutId = setTimeout(() => {
|
|
564
|
+
reject(new Error(errorMessage ?? `Operation timed out after ${ms}ms`));
|
|
565
|
+
}, ms);
|
|
566
|
+
});
|
|
567
|
+
return Promise.race([promise, timeoutPromise]).finally(() => {
|
|
568
|
+
clearTimeout(timeoutId);
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
__name(timeout, "timeout");
|
|
572
|
+
function createDeferred() {
|
|
573
|
+
let resolve;
|
|
574
|
+
let reject;
|
|
575
|
+
const promise = new Promise((res, rej) => {
|
|
576
|
+
resolve = res;
|
|
577
|
+
reject = rej;
|
|
578
|
+
});
|
|
579
|
+
return { promise, resolve, reject };
|
|
580
|
+
}
|
|
581
|
+
__name(createDeferred, "createDeferred");
|
|
582
|
+
async function parallel(tasks, options) {
|
|
583
|
+
const { concurrency = Infinity } = options ?? {};
|
|
584
|
+
const results = new Array(tasks.length);
|
|
585
|
+
let currentIndex = 0;
|
|
586
|
+
async function runNext() {
|
|
587
|
+
while (currentIndex < tasks.length) {
|
|
588
|
+
const index = currentIndex++;
|
|
589
|
+
const task = tasks[index];
|
|
590
|
+
if (task) {
|
|
591
|
+
results[index] = await task();
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
__name(runNext, "runNext");
|
|
596
|
+
const workers = Array.from(
|
|
597
|
+
{ length: Math.min(concurrency, tasks.length) },
|
|
598
|
+
() => runNext()
|
|
599
|
+
);
|
|
600
|
+
await Promise.all(workers);
|
|
601
|
+
return results;
|
|
602
|
+
}
|
|
603
|
+
__name(parallel, "parallel");
|
|
604
|
+
async function sequence(tasks) {
|
|
605
|
+
const results = [];
|
|
606
|
+
for (const task of tasks) {
|
|
607
|
+
results.push(await task());
|
|
608
|
+
}
|
|
609
|
+
return results;
|
|
610
|
+
}
|
|
611
|
+
__name(sequence, "sequence");
|
|
612
|
+
|
|
613
|
+
// src/utils/guards.ts
|
|
614
|
+
function isString(value) {
|
|
615
|
+
return typeof value === "string";
|
|
616
|
+
}
|
|
617
|
+
__name(isString, "isString");
|
|
618
|
+
function isNumber(value) {
|
|
619
|
+
return typeof value === "number" && !Number.isNaN(value);
|
|
620
|
+
}
|
|
621
|
+
__name(isNumber, "isNumber");
|
|
622
|
+
function isBoolean(value) {
|
|
623
|
+
return typeof value === "boolean";
|
|
624
|
+
}
|
|
625
|
+
__name(isBoolean, "isBoolean");
|
|
626
|
+
function isObject(value) {
|
|
627
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
628
|
+
}
|
|
629
|
+
__name(isObject, "isObject");
|
|
630
|
+
function isArray(value) {
|
|
631
|
+
return Array.isArray(value);
|
|
632
|
+
}
|
|
633
|
+
__name(isArray, "isArray");
|
|
634
|
+
function isFunction(value) {
|
|
635
|
+
return typeof value === "function";
|
|
636
|
+
}
|
|
637
|
+
__name(isFunction, "isFunction");
|
|
638
|
+
function isNil(value) {
|
|
639
|
+
return value === null || value === void 0;
|
|
640
|
+
}
|
|
641
|
+
__name(isNil, "isNil");
|
|
642
|
+
function isNotNil(value) {
|
|
643
|
+
return value !== null && value !== void 0;
|
|
644
|
+
}
|
|
645
|
+
__name(isNotNil, "isNotNil");
|
|
646
|
+
function isEmpty(value) {
|
|
647
|
+
if (isNil(value)) return true;
|
|
648
|
+
if (typeof value === "string") return value.length === 0;
|
|
649
|
+
if (Array.isArray(value)) return value.length === 0;
|
|
650
|
+
if (value instanceof Map || value instanceof Set) return value.size === 0;
|
|
651
|
+
if (typeof value === "object" && value !== null) return Object.keys(value).length === 0;
|
|
652
|
+
return false;
|
|
653
|
+
}
|
|
654
|
+
__name(isEmpty, "isEmpty");
|
|
655
|
+
function isNotEmpty(value) {
|
|
656
|
+
return !isEmpty(value);
|
|
657
|
+
}
|
|
658
|
+
__name(isNotEmpty, "isNotEmpty");
|
|
659
|
+
function isDate(value) {
|
|
660
|
+
return value instanceof Date && !Number.isNaN(value.getTime());
|
|
661
|
+
}
|
|
662
|
+
__name(isDate, "isDate");
|
|
663
|
+
function isPromise(value) {
|
|
664
|
+
return value instanceof Promise || value !== null && typeof value === "object" && typeof value.then === "function";
|
|
665
|
+
}
|
|
666
|
+
__name(isPromise, "isPromise");
|
|
667
|
+
function isSymbol(value) {
|
|
668
|
+
return typeof value === "symbol";
|
|
669
|
+
}
|
|
670
|
+
__name(isSymbol, "isSymbol");
|
|
671
|
+
function isBigInt(value) {
|
|
672
|
+
return typeof value === "bigint";
|
|
673
|
+
}
|
|
674
|
+
__name(isBigInt, "isBigInt");
|
|
675
|
+
function isEmail(value) {
|
|
676
|
+
if (!isString(value)) return false;
|
|
677
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
678
|
+
return emailRegex.test(value);
|
|
679
|
+
}
|
|
680
|
+
__name(isEmail, "isEmail");
|
|
681
|
+
function isUUID(value) {
|
|
682
|
+
if (!isString(value)) return false;
|
|
683
|
+
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
684
|
+
return uuidRegex.test(value);
|
|
685
|
+
}
|
|
686
|
+
__name(isUUID, "isUUID");
|
|
687
|
+
function isURL(value) {
|
|
688
|
+
if (!isString(value)) return false;
|
|
689
|
+
try {
|
|
690
|
+
new URL(value);
|
|
691
|
+
return true;
|
|
692
|
+
} catch {
|
|
693
|
+
return false;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
__name(isURL, "isURL");
|
|
697
|
+
function isInteger(value) {
|
|
698
|
+
return isNumber(value) && Number.isInteger(value);
|
|
699
|
+
}
|
|
700
|
+
__name(isInteger, "isInteger");
|
|
701
|
+
function isPositive(value) {
|
|
702
|
+
return isNumber(value) && value > 0;
|
|
703
|
+
}
|
|
704
|
+
__name(isPositive, "isPositive");
|
|
705
|
+
function isNegative(value) {
|
|
706
|
+
return isNumber(value) && value < 0;
|
|
707
|
+
}
|
|
708
|
+
__name(isNegative, "isNegative");
|
|
709
|
+
function isInRange(value, min, max) {
|
|
710
|
+
return isNumber(value) && value >= min && value <= max;
|
|
711
|
+
}
|
|
712
|
+
__name(isInRange, "isInRange");
|
|
713
|
+
|
|
714
|
+
export { camelCase, capitalize, chunk, collapseWhitespace, constantCase, countOccurrences, createDeferred, debounce, deepClone, deepMerge, delay, difference, escapeHtml, filterObject, first, flatten, flattenDeep, fromEntries, get, groupBy, has, intersection, isArray, isBigInt, isBoolean, isDate, isEmail, isEmpty, isFunction, isInRange, isInteger, isNegative, isNil, isNotEmpty, isNotNil, isNumber, isObject, isPlainObject, isPositive, isPromise, isString, isSymbol, isURL, isUUID, kebabCase, last, mapValues, omit, padEnd, padStart, parallel, partition, pascalCase, pick, randomString, range, retry, reverse, sample, sequence, set, shuffle, snakeCase, sortBy, throttle, timeout, titleCase, truncate, unescapeHtml, unique, words, zip };
|
|
715
|
+
//# sourceMappingURL=chunk-352XNR3C.js.map
|
|
716
|
+
//# sourceMappingURL=chunk-352XNR3C.js.map
|