radashi 12.1.0-pr11.e33bd36
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.md +22 -0
- package/README.md +96 -0
- package/dist/index.cjs +1254 -0
- package/dist/index.d.cts +746 -0
- package/dist/index.d.ts +746 -0
- package/dist/index.js +1131 -0
- package/package.json +52 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1254 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all2) => {
|
|
7
|
+
for (var name in all2)
|
|
8
|
+
__defProp(target, name, { get: all2[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
AggregateError: () => AggregateError,
|
|
24
|
+
all: () => all,
|
|
25
|
+
alphabetical: () => alphabetical,
|
|
26
|
+
assign: () => assign,
|
|
27
|
+
boil: () => boil,
|
|
28
|
+
callable: () => callable,
|
|
29
|
+
camel: () => camel,
|
|
30
|
+
capitalize: () => capitalize,
|
|
31
|
+
chain: () => chain,
|
|
32
|
+
clone: () => clone,
|
|
33
|
+
cluster: () => cluster,
|
|
34
|
+
compose: () => compose,
|
|
35
|
+
construct: () => construct,
|
|
36
|
+
counting: () => counting,
|
|
37
|
+
crush: () => crush,
|
|
38
|
+
dash: () => dash,
|
|
39
|
+
debounce: () => debounce,
|
|
40
|
+
defer: () => defer,
|
|
41
|
+
diff: () => diff,
|
|
42
|
+
draw: () => draw,
|
|
43
|
+
first: () => first,
|
|
44
|
+
flat: () => flat,
|
|
45
|
+
fork: () => fork,
|
|
46
|
+
get: () => get,
|
|
47
|
+
group: () => group,
|
|
48
|
+
guard: () => guard,
|
|
49
|
+
inRange: () => inRange,
|
|
50
|
+
intersects: () => intersects,
|
|
51
|
+
invert: () => invert,
|
|
52
|
+
isArray: () => isArray,
|
|
53
|
+
isDate: () => isDate,
|
|
54
|
+
isEmpty: () => isEmpty,
|
|
55
|
+
isEqual: () => isEqual,
|
|
56
|
+
isFloat: () => isFloat,
|
|
57
|
+
isFunction: () => isFunction,
|
|
58
|
+
isInt: () => isInt,
|
|
59
|
+
isIntString: () => isIntString,
|
|
60
|
+
isNumber: () => isNumber,
|
|
61
|
+
isObject: () => isObject,
|
|
62
|
+
isPlainObject: () => isPlainObject,
|
|
63
|
+
isPrimitive: () => isPrimitive,
|
|
64
|
+
isPromise: () => isPromise,
|
|
65
|
+
isString: () => isString,
|
|
66
|
+
isSymbol: () => isSymbol,
|
|
67
|
+
iterate: () => iterate,
|
|
68
|
+
keys: () => keys,
|
|
69
|
+
last: () => last,
|
|
70
|
+
list: () => list,
|
|
71
|
+
listify: () => listify,
|
|
72
|
+
lowerize: () => lowerize,
|
|
73
|
+
map: () => map,
|
|
74
|
+
mapEntries: () => mapEntries,
|
|
75
|
+
mapKeys: () => mapKeys,
|
|
76
|
+
mapValues: () => mapValues,
|
|
77
|
+
max: () => max,
|
|
78
|
+
memo: () => memo,
|
|
79
|
+
merge: () => merge,
|
|
80
|
+
min: () => min,
|
|
81
|
+
objectify: () => objectify,
|
|
82
|
+
omit: () => omit,
|
|
83
|
+
parallel: () => parallel,
|
|
84
|
+
partial: () => partial,
|
|
85
|
+
partob: () => partob,
|
|
86
|
+
pascal: () => pascal,
|
|
87
|
+
pick: () => pick,
|
|
88
|
+
proxied: () => proxied,
|
|
89
|
+
random: () => random,
|
|
90
|
+
range: () => range,
|
|
91
|
+
reduce: () => reduce,
|
|
92
|
+
replace: () => replace,
|
|
93
|
+
replaceOrAppend: () => replaceOrAppend,
|
|
94
|
+
retry: () => retry,
|
|
95
|
+
select: () => select,
|
|
96
|
+
series: () => series,
|
|
97
|
+
set: () => set,
|
|
98
|
+
shake: () => shake,
|
|
99
|
+
shift: () => shift,
|
|
100
|
+
shuffle: () => shuffle,
|
|
101
|
+
sift: () => sift,
|
|
102
|
+
sleep: () => sleep,
|
|
103
|
+
snake: () => snake,
|
|
104
|
+
sort: () => sort,
|
|
105
|
+
sum: () => sum,
|
|
106
|
+
template: () => template,
|
|
107
|
+
throttle: () => throttle,
|
|
108
|
+
title: () => title,
|
|
109
|
+
toFloat: () => toFloat,
|
|
110
|
+
toInt: () => toInt,
|
|
111
|
+
toggle: () => toggle,
|
|
112
|
+
trim: () => trim,
|
|
113
|
+
try: () => tryit,
|
|
114
|
+
tryit: () => tryit,
|
|
115
|
+
uid: () => uid,
|
|
116
|
+
unique: () => unique,
|
|
117
|
+
upperize: () => upperize,
|
|
118
|
+
zip: () => zip,
|
|
119
|
+
zipToObject: () => zipToObject
|
|
120
|
+
});
|
|
121
|
+
module.exports = __toCommonJS(src_exports);
|
|
122
|
+
|
|
123
|
+
// src/array/alphabetical.ts
|
|
124
|
+
var alphabetical = (array, getter, dir = "asc") => {
|
|
125
|
+
if (!array) return [];
|
|
126
|
+
const asc = (a, b) => `${getter(a)}`.localeCompare(getter(b));
|
|
127
|
+
const dsc = (a, b) => `${getter(b)}`.localeCompare(getter(a));
|
|
128
|
+
return array.slice().sort(dir === "desc" ? dsc : asc);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// src/array/boil.ts
|
|
132
|
+
var boil = (array, compareFunc) => {
|
|
133
|
+
if (!array || (array.length ?? 0) === 0) return null;
|
|
134
|
+
return array.reduce(compareFunc);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// src/array/cluster.ts
|
|
138
|
+
var cluster = (list2, size = 2) => {
|
|
139
|
+
const clusterCount = Math.ceil(list2.length / size);
|
|
140
|
+
return new Array(clusterCount).fill(null).map((_c, i) => {
|
|
141
|
+
return list2.slice(i * size, i * size + size);
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// src/array/counting.ts
|
|
146
|
+
var counting = (list2, identity) => {
|
|
147
|
+
if (!list2) return {};
|
|
148
|
+
return list2.reduce((acc, item) => {
|
|
149
|
+
const id = identity(item);
|
|
150
|
+
acc[id] = (acc[id] ?? 0) + 1;
|
|
151
|
+
return acc;
|
|
152
|
+
}, {});
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// src/array/diff.ts
|
|
156
|
+
var diff = (root, other, identity = (t) => t) => {
|
|
157
|
+
if (!(root == null ? void 0 : root.length) && !(other == null ? void 0 : other.length)) return [];
|
|
158
|
+
if ((root == null ? void 0 : root.length) === void 0) return [...other];
|
|
159
|
+
if (!(other == null ? void 0 : other.length)) return [...root];
|
|
160
|
+
const bKeys = other.reduce((acc, item) => {
|
|
161
|
+
acc[identity(item)] = true;
|
|
162
|
+
return acc;
|
|
163
|
+
}, {});
|
|
164
|
+
return root.filter((a) => !bKeys[identity(a)]);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// src/array/first.ts
|
|
168
|
+
var first = (array, defaultValue = void 0) => {
|
|
169
|
+
return (array == null ? void 0 : array.length) > 0 ? array[0] : defaultValue;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
// src/array/flat.ts
|
|
173
|
+
var flat = (lists) => {
|
|
174
|
+
return lists.reduce((acc, list2) => {
|
|
175
|
+
acc.push(...list2);
|
|
176
|
+
return acc;
|
|
177
|
+
}, []);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
// src/array/fork.ts
|
|
181
|
+
var fork = (list2, condition) => {
|
|
182
|
+
if (!list2) return [[], []];
|
|
183
|
+
return list2.reduce(
|
|
184
|
+
(acc, item) => {
|
|
185
|
+
const [a, b] = acc;
|
|
186
|
+
if (condition(item)) {
|
|
187
|
+
return [[...a, item], b];
|
|
188
|
+
} else {
|
|
189
|
+
return [a, [...b, item]];
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
[[], []]
|
|
193
|
+
);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
// src/array/group.ts
|
|
197
|
+
var group = (array, getGroupId) => {
|
|
198
|
+
return array.reduce((acc, item) => {
|
|
199
|
+
const groupId = getGroupId(item);
|
|
200
|
+
if (!acc[groupId]) acc[groupId] = [];
|
|
201
|
+
acc[groupId].push(item);
|
|
202
|
+
return acc;
|
|
203
|
+
}, {});
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// src/array/intersects.ts
|
|
207
|
+
var intersects = (listA, listB, identity) => {
|
|
208
|
+
if (!listA || !listB) return false;
|
|
209
|
+
if (identity) {
|
|
210
|
+
const known = new Set(listA.map(identity));
|
|
211
|
+
return listB.some((item) => known.has(identity(item)));
|
|
212
|
+
}
|
|
213
|
+
return listB.some((item) => listA.includes(item));
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
// src/array/iterate.ts
|
|
217
|
+
var iterate = (count, func, initValue) => {
|
|
218
|
+
let value = initValue;
|
|
219
|
+
for (let i = 1; i <= count; i++) {
|
|
220
|
+
value = func(value, i);
|
|
221
|
+
}
|
|
222
|
+
return value;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
// src/array/last.ts
|
|
226
|
+
var last = (array, defaultValue = void 0) => {
|
|
227
|
+
return (array == null ? void 0 : array.length) > 0 ? array[array.length - 1] : defaultValue;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// src/array/list.ts
|
|
231
|
+
var list = (startOrLength, end, valueOrMapper, step) => {
|
|
232
|
+
return Array.from(range(startOrLength, end, valueOrMapper, step));
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
// src/array/max.ts
|
|
236
|
+
function max(array, getter) {
|
|
237
|
+
const get2 = getter ?? ((v) => v);
|
|
238
|
+
return boil(array, (a, b) => get2(a) > get2(b) ? a : b);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// src/array/merge.ts
|
|
242
|
+
var merge = (root, others, matcher) => {
|
|
243
|
+
if (!others && !root) return [];
|
|
244
|
+
if (!others) return root;
|
|
245
|
+
if (!root) return [];
|
|
246
|
+
if (!matcher) return root;
|
|
247
|
+
return root.reduce((acc, r) => {
|
|
248
|
+
const matched = others.find((o) => matcher(r) === matcher(o));
|
|
249
|
+
if (matched) acc.push(matched);
|
|
250
|
+
else acc.push(r);
|
|
251
|
+
return acc;
|
|
252
|
+
}, []);
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
// src/array/min.ts
|
|
256
|
+
function min(array, getter) {
|
|
257
|
+
const get2 = getter ?? ((v) => v);
|
|
258
|
+
return boil(array, (a, b) => get2(a) < get2(b) ? a : b);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// src/array/objectify.ts
|
|
262
|
+
var objectify = (array, getKey, getValue = (item) => item) => {
|
|
263
|
+
return array.reduce((acc, item) => {
|
|
264
|
+
acc[getKey(item)] = getValue(item);
|
|
265
|
+
return acc;
|
|
266
|
+
}, {});
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
// src/array/range.ts
|
|
270
|
+
function* range(startOrLength, end, valueOrMapper = (i) => i, step = 1) {
|
|
271
|
+
const mapper = isFunction(valueOrMapper) ? valueOrMapper : () => valueOrMapper;
|
|
272
|
+
const start = end ? startOrLength : 0;
|
|
273
|
+
const final = end ?? startOrLength;
|
|
274
|
+
for (let i = start; i <= final; i += step) {
|
|
275
|
+
yield mapper(i);
|
|
276
|
+
if (i + step > final) break;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// src/array/replace.ts
|
|
281
|
+
var replace = (list2, newItem, match) => {
|
|
282
|
+
if (!list2) return [];
|
|
283
|
+
if (newItem === void 0) return [...list2];
|
|
284
|
+
for (let idx = 0; idx < list2.length; idx++) {
|
|
285
|
+
const item = list2[idx];
|
|
286
|
+
if (match(item, idx)) {
|
|
287
|
+
return [
|
|
288
|
+
...list2.slice(0, idx),
|
|
289
|
+
newItem,
|
|
290
|
+
...list2.slice(idx + 1, list2.length)
|
|
291
|
+
];
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return [...list2];
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
// src/array/replaceOrAppend.ts
|
|
298
|
+
var replaceOrAppend = (list2, newItem, match) => {
|
|
299
|
+
if (!list2 && !newItem) return [];
|
|
300
|
+
if (!newItem) return [...list2];
|
|
301
|
+
if (!list2) return [newItem];
|
|
302
|
+
for (let idx = 0; idx < list2.length; idx++) {
|
|
303
|
+
const item = list2[idx];
|
|
304
|
+
if (match(item, idx)) {
|
|
305
|
+
return [
|
|
306
|
+
...list2.slice(0, idx),
|
|
307
|
+
newItem,
|
|
308
|
+
...list2.slice(idx + 1, list2.length)
|
|
309
|
+
];
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return [...list2, newItem];
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
// src/array/select.ts
|
|
316
|
+
var select = (array, mapper, condition) => {
|
|
317
|
+
if (!array) return [];
|
|
318
|
+
return array.reduce((acc, item, index) => {
|
|
319
|
+
if (!condition(item, index)) return acc;
|
|
320
|
+
acc.push(mapper(item, index));
|
|
321
|
+
return acc;
|
|
322
|
+
}, []);
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
// src/array/shift.ts
|
|
326
|
+
function shift(arr, n) {
|
|
327
|
+
if (arr.length === 0) return arr;
|
|
328
|
+
const shiftNumber = n % arr.length;
|
|
329
|
+
if (shiftNumber === 0) return arr;
|
|
330
|
+
return [...arr.slice(-shiftNumber, arr.length), ...arr.slice(0, -shiftNumber)];
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// src/array/sift.ts
|
|
334
|
+
var sift = (list2) => {
|
|
335
|
+
return (list2 == null ? void 0 : list2.filter((x) => !!x)) ?? [];
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
// src/array/sort.ts
|
|
339
|
+
var sort = (array, getter, desc = false) => {
|
|
340
|
+
if (!array) return [];
|
|
341
|
+
const asc = (a, b) => getter(a) - getter(b);
|
|
342
|
+
const dsc = (a, b) => getter(b) - getter(a);
|
|
343
|
+
return array.slice().sort(desc === true ? dsc : asc);
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
// src/array/sum.ts
|
|
347
|
+
function sum(array, fn) {
|
|
348
|
+
return (array || []).reduce((acc, item) => acc + (fn ? fn(item) : item), 0);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// src/array/toggle.ts
|
|
352
|
+
var toggle = (list2, item, toKey, options) => {
|
|
353
|
+
if (!list2 && !item) return [];
|
|
354
|
+
if (!list2) return [item];
|
|
355
|
+
if (!item) return [...list2];
|
|
356
|
+
const matcher = toKey ? (x, idx) => toKey(x, idx) === toKey(item, idx) : (x) => x === item;
|
|
357
|
+
const existing = list2.find(matcher);
|
|
358
|
+
if (existing) return list2.filter((x, idx) => !matcher(x, idx));
|
|
359
|
+
const strategy = (options == null ? void 0 : options.strategy) ?? "append";
|
|
360
|
+
if (strategy === "append") return [...list2, item];
|
|
361
|
+
return [item, ...list2];
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
// src/array/unique.ts
|
|
365
|
+
var unique = (array, toKey) => {
|
|
366
|
+
const valueMap = array.reduce((acc, item) => {
|
|
367
|
+
const key = toKey ? toKey(item) : item;
|
|
368
|
+
if (acc[key]) return acc;
|
|
369
|
+
acc[key] = item;
|
|
370
|
+
return acc;
|
|
371
|
+
}, {});
|
|
372
|
+
return Object.values(valueMap);
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
// src/array/zip.ts
|
|
376
|
+
function zip(...arrays) {
|
|
377
|
+
if (!arrays || !arrays.length) return [];
|
|
378
|
+
return new Array(Math.max(...arrays.map(({ length }) => length))).fill([]).map((_, idx) => arrays.map((array) => array[idx]));
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// src/array/zipToObject.ts
|
|
382
|
+
function zipToObject(keys2, values) {
|
|
383
|
+
if (!keys2 || !keys2.length) {
|
|
384
|
+
return {};
|
|
385
|
+
}
|
|
386
|
+
const getValue = isFunction(values) ? values : isArray(values) ? (_k, i) => values[i] : (_k, _i) => values;
|
|
387
|
+
return keys2.reduce((acc, key, idx) => {
|
|
388
|
+
acc[key] = getValue(key, idx);
|
|
389
|
+
return acc;
|
|
390
|
+
}, {});
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// src/async/AggregateError.ts
|
|
394
|
+
var AggregateError = class extends Error {
|
|
395
|
+
errors;
|
|
396
|
+
constructor(errors = []) {
|
|
397
|
+
var _a, _b;
|
|
398
|
+
super();
|
|
399
|
+
const name = ((_a = errors.find((e) => e.name)) == null ? void 0 : _a.name) ?? "";
|
|
400
|
+
this.name = `AggregateError(${name}...)`;
|
|
401
|
+
this.message = `AggregateError with ${errors.length} errors`;
|
|
402
|
+
this.stack = ((_b = errors.find((e) => e.stack)) == null ? void 0 : _b.stack) ?? this.stack;
|
|
403
|
+
this.errors = errors;
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
// src/async/all.ts
|
|
408
|
+
async function all(promises) {
|
|
409
|
+
const entries = isArray(promises) ? promises.map((p) => [null, p]) : Object.entries(promises);
|
|
410
|
+
const results = await Promise.all(
|
|
411
|
+
entries.map(
|
|
412
|
+
([key, value]) => value.then((result) => ({ result, exc: null, key })).catch((exc) => ({ result: null, exc, key }))
|
|
413
|
+
)
|
|
414
|
+
);
|
|
415
|
+
const exceptions = results.filter((r) => r.exc);
|
|
416
|
+
if (exceptions.length > 0) {
|
|
417
|
+
throw new AggregateError(exceptions.map((e) => e.exc));
|
|
418
|
+
}
|
|
419
|
+
if (isArray(promises)) {
|
|
420
|
+
return results.map((r) => r.result);
|
|
421
|
+
}
|
|
422
|
+
return results.reduce(
|
|
423
|
+
(acc, item) => ({
|
|
424
|
+
...acc,
|
|
425
|
+
[item.key]: item.result
|
|
426
|
+
}),
|
|
427
|
+
{}
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// src/async/defer.ts
|
|
432
|
+
var defer = async (func) => {
|
|
433
|
+
const callbacks = [];
|
|
434
|
+
const register = (fn, options) => callbacks.push({
|
|
435
|
+
fn,
|
|
436
|
+
rethrow: (options == null ? void 0 : options.rethrow) ?? false
|
|
437
|
+
});
|
|
438
|
+
const [err, response] = await tryit(func)(register);
|
|
439
|
+
for (const { fn, rethrow } of callbacks) {
|
|
440
|
+
const [rethrown] = await tryit(fn)(err);
|
|
441
|
+
if (rethrown && rethrow) throw rethrown;
|
|
442
|
+
}
|
|
443
|
+
if (err) throw err;
|
|
444
|
+
return response;
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
// src/async/guard.ts
|
|
448
|
+
var guard = (func, shouldGuard) => {
|
|
449
|
+
const _guard = (err) => {
|
|
450
|
+
if (shouldGuard && !shouldGuard(err)) throw err;
|
|
451
|
+
return void 0;
|
|
452
|
+
};
|
|
453
|
+
try {
|
|
454
|
+
const result = func();
|
|
455
|
+
return result instanceof Promise ? result.catch(_guard) : result;
|
|
456
|
+
} catch (err) {
|
|
457
|
+
return _guard(err);
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
// src/async/map.ts
|
|
462
|
+
var map = async (array, asyncMapFunc) => {
|
|
463
|
+
if (!array) return [];
|
|
464
|
+
let result = [];
|
|
465
|
+
let index = 0;
|
|
466
|
+
for (const value of array) {
|
|
467
|
+
const newValue = await asyncMapFunc(value, index++);
|
|
468
|
+
result.push(newValue);
|
|
469
|
+
}
|
|
470
|
+
return result;
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
// src/async/parallel.ts
|
|
474
|
+
var parallel = async (limit, array, func) => {
|
|
475
|
+
const work = array.map((item, index) => ({
|
|
476
|
+
index,
|
|
477
|
+
item
|
|
478
|
+
}));
|
|
479
|
+
const processor = async (res) => {
|
|
480
|
+
const results2 = [];
|
|
481
|
+
while (true) {
|
|
482
|
+
const next = work.pop();
|
|
483
|
+
if (!next) return res(results2);
|
|
484
|
+
const [error, result] = await tryit(func)(next.item);
|
|
485
|
+
results2.push({
|
|
486
|
+
error,
|
|
487
|
+
result,
|
|
488
|
+
index: next.index
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
const queues = list(1, limit).map(() => new Promise(processor));
|
|
493
|
+
const itemResults = await Promise.all(queues);
|
|
494
|
+
const [errors, results] = fork(
|
|
495
|
+
sort(itemResults.flat(), (r) => r.index),
|
|
496
|
+
(x) => !!x.error
|
|
497
|
+
);
|
|
498
|
+
if (errors.length > 0) {
|
|
499
|
+
throw new AggregateError(errors.map((error) => error.error));
|
|
500
|
+
}
|
|
501
|
+
return results.map((r) => r.result);
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
// src/async/reduce.ts
|
|
505
|
+
var reduce = async (array, asyncReducer, initValue) => {
|
|
506
|
+
const initProvided = initValue !== void 0;
|
|
507
|
+
if (!initProvided && (array == null ? void 0 : array.length) < 1) {
|
|
508
|
+
throw new Error("Cannot reduce empty array with no init value");
|
|
509
|
+
}
|
|
510
|
+
const iter = initProvided ? array : array.slice(1);
|
|
511
|
+
let value = initProvided ? initValue : array[0];
|
|
512
|
+
for (const [i, item] of iter.entries()) {
|
|
513
|
+
value = await asyncReducer(value, item, i);
|
|
514
|
+
}
|
|
515
|
+
return value;
|
|
516
|
+
};
|
|
517
|
+
|
|
518
|
+
// src/async/retry.ts
|
|
519
|
+
var retry = async (options, func) => {
|
|
520
|
+
const times = (options == null ? void 0 : options.times) ?? 3;
|
|
521
|
+
const delay = options == null ? void 0 : options.delay;
|
|
522
|
+
const backoff = (options == null ? void 0 : options.backoff) ?? null;
|
|
523
|
+
let i = 0;
|
|
524
|
+
while (true) {
|
|
525
|
+
const [err, result] = await tryit(func)((err2) => {
|
|
526
|
+
throw { _exited: err2 };
|
|
527
|
+
});
|
|
528
|
+
if (!err) return result;
|
|
529
|
+
if (err._exited) throw err._exited;
|
|
530
|
+
if (++i === times) throw err;
|
|
531
|
+
if (delay) await sleep(delay);
|
|
532
|
+
if (backoff) await sleep(backoff(i));
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
// src/async/sleep.ts
|
|
537
|
+
var sleep = (milliseconds) => {
|
|
538
|
+
return new Promise((res) => setTimeout(res, milliseconds));
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
// src/async/tryit.ts
|
|
542
|
+
var tryit = (func) => {
|
|
543
|
+
return (...args) => {
|
|
544
|
+
try {
|
|
545
|
+
const result = func(...args);
|
|
546
|
+
if (isPromise(result)) {
|
|
547
|
+
return result.then((value) => [void 0, value]).catch((err) => [err, void 0]);
|
|
548
|
+
}
|
|
549
|
+
return [void 0, result];
|
|
550
|
+
} catch (err) {
|
|
551
|
+
return [err, void 0];
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
// src/curry/callable.ts
|
|
557
|
+
var callable = (obj, fn) => {
|
|
558
|
+
return new Proxy(Object.assign(fn.bind(null), obj), {
|
|
559
|
+
get: (target, key) => target[key],
|
|
560
|
+
set: (target, key, value) => {
|
|
561
|
+
;
|
|
562
|
+
target[key] = value;
|
|
563
|
+
return true;
|
|
564
|
+
},
|
|
565
|
+
apply: (target, self, args) => fn(Object.assign({}, target))(...args)
|
|
566
|
+
});
|
|
567
|
+
};
|
|
568
|
+
|
|
569
|
+
// src/curry/chain.ts
|
|
570
|
+
function chain(...funcs) {
|
|
571
|
+
return (...args) => {
|
|
572
|
+
return funcs.slice(1).reduce((acc, fn) => fn(acc), funcs[0](...args));
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// src/curry/compose.ts
|
|
577
|
+
function compose(...funcs) {
|
|
578
|
+
return funcs.reverse().reduce((acc, fn) => fn(acc));
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
// src/curry/debounce.ts
|
|
582
|
+
var debounce = ({ delay }, func) => {
|
|
583
|
+
let timer = void 0;
|
|
584
|
+
let active = true;
|
|
585
|
+
const debounced = (...args) => {
|
|
586
|
+
if (active) {
|
|
587
|
+
clearTimeout(timer);
|
|
588
|
+
timer = setTimeout(() => {
|
|
589
|
+
active && func(...args);
|
|
590
|
+
timer = void 0;
|
|
591
|
+
}, delay);
|
|
592
|
+
} else {
|
|
593
|
+
func(...args);
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
debounced.isPending = () => {
|
|
597
|
+
return timer !== void 0;
|
|
598
|
+
};
|
|
599
|
+
debounced.cancel = () => {
|
|
600
|
+
active = false;
|
|
601
|
+
};
|
|
602
|
+
debounced.flush = (...args) => func(...args);
|
|
603
|
+
return debounced;
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
// src/curry/memo.ts
|
|
607
|
+
var memoize = (cache, func, keyFunc, ttl) => {
|
|
608
|
+
return function callWithMemo(...args) {
|
|
609
|
+
const key = keyFunc ? keyFunc(...args) : JSON.stringify({ args });
|
|
610
|
+
const existing = cache[key];
|
|
611
|
+
if (existing !== void 0) {
|
|
612
|
+
if (!existing.exp) return existing.value;
|
|
613
|
+
if (existing.exp > (/* @__PURE__ */ new Date()).getTime()) {
|
|
614
|
+
return existing.value;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
const result = func(...args);
|
|
618
|
+
cache[key] = {
|
|
619
|
+
exp: ttl ? (/* @__PURE__ */ new Date()).getTime() + ttl : null,
|
|
620
|
+
value: result
|
|
621
|
+
};
|
|
622
|
+
return result;
|
|
623
|
+
};
|
|
624
|
+
};
|
|
625
|
+
var memo = (func, options = {}) => {
|
|
626
|
+
return memoize({}, func, options.key ?? null, options.ttl ?? null);
|
|
627
|
+
};
|
|
628
|
+
|
|
629
|
+
// src/curry/partial.ts
|
|
630
|
+
var partial = (fn, ...args) => {
|
|
631
|
+
return (...rest) => fn(...[...args, ...rest]);
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
// src/curry/partob.ts
|
|
635
|
+
var partob = (fn, argobj) => {
|
|
636
|
+
return (restobj) => fn({
|
|
637
|
+
...argobj,
|
|
638
|
+
...restobj
|
|
639
|
+
});
|
|
640
|
+
};
|
|
641
|
+
|
|
642
|
+
// src/curry/proxied.ts
|
|
643
|
+
var proxied = (handler) => {
|
|
644
|
+
return new Proxy(
|
|
645
|
+
{},
|
|
646
|
+
{
|
|
647
|
+
get: (target, propertyName) => handler(propertyName)
|
|
648
|
+
}
|
|
649
|
+
);
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
// src/curry/throttle.ts
|
|
653
|
+
var throttle = ({ interval }, func) => {
|
|
654
|
+
let ready = true;
|
|
655
|
+
let timer = void 0;
|
|
656
|
+
const throttled = (...args) => {
|
|
657
|
+
if (!ready) return;
|
|
658
|
+
func(...args);
|
|
659
|
+
ready = false;
|
|
660
|
+
timer = setTimeout(() => {
|
|
661
|
+
ready = true;
|
|
662
|
+
timer = void 0;
|
|
663
|
+
}, interval);
|
|
664
|
+
};
|
|
665
|
+
throttled.isThrottled = () => {
|
|
666
|
+
return timer !== void 0;
|
|
667
|
+
};
|
|
668
|
+
return throttled;
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
// src/number/inRange.ts
|
|
672
|
+
function inRange(number, start, end) {
|
|
673
|
+
const isTypeSafe = typeof number === "number" && typeof start === "number" && (typeof end === "undefined" || typeof end === "number");
|
|
674
|
+
if (!isTypeSafe) {
|
|
675
|
+
return false;
|
|
676
|
+
}
|
|
677
|
+
if (typeof end === "undefined") {
|
|
678
|
+
end = start;
|
|
679
|
+
start = 0;
|
|
680
|
+
}
|
|
681
|
+
return number >= Math.min(start, end) && number < Math.max(start, end);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
// src/number/toInt.ts
|
|
685
|
+
var toInt = (value, defaultValue) => {
|
|
686
|
+
const def = defaultValue === void 0 ? 0 : defaultValue;
|
|
687
|
+
if (value === null || value === void 0) {
|
|
688
|
+
return def;
|
|
689
|
+
}
|
|
690
|
+
const result = parseInt(value);
|
|
691
|
+
return isNaN(result) ? def : result;
|
|
692
|
+
};
|
|
693
|
+
|
|
694
|
+
// src/number/toFloat.ts
|
|
695
|
+
var toFloat = (value, defaultValue) => {
|
|
696
|
+
const def = defaultValue === void 0 ? 0 : defaultValue;
|
|
697
|
+
if (value === null || value === void 0) {
|
|
698
|
+
return def;
|
|
699
|
+
}
|
|
700
|
+
const result = parseFloat(value);
|
|
701
|
+
return isNaN(result) ? def : result;
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
// src/object/assign.ts
|
|
705
|
+
var assign = (initial, override) => {
|
|
706
|
+
if (!initial || !override) return initial ?? override ?? {};
|
|
707
|
+
const proto = Object.getPrototypeOf(initial);
|
|
708
|
+
const merged = proto ? { ...initial } : Object.assign(Object.create(proto), initial);
|
|
709
|
+
for (const key in override) {
|
|
710
|
+
if (Object.prototype.hasOwnProperty.call(override, key)) {
|
|
711
|
+
merged[key] = isPlainObject(initial[key]) ? assign(initial[key], override[key]) : override[key];
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
return merged;
|
|
715
|
+
};
|
|
716
|
+
|
|
717
|
+
// src/object/clone.ts
|
|
718
|
+
var clone = (obj) => {
|
|
719
|
+
if (isPrimitive(obj)) {
|
|
720
|
+
return obj;
|
|
721
|
+
}
|
|
722
|
+
if (typeof obj === "function") {
|
|
723
|
+
return obj.bind({});
|
|
724
|
+
}
|
|
725
|
+
const proto = Object.getPrototypeOf(obj);
|
|
726
|
+
const newObj = typeof (proto == null ? void 0 : proto.constructor) === "function" ? new proto.constructor() : Object.create(proto);
|
|
727
|
+
Object.getOwnPropertyNames(obj).forEach((key) => {
|
|
728
|
+
newObj[key] = obj[key];
|
|
729
|
+
});
|
|
730
|
+
return newObj;
|
|
731
|
+
};
|
|
732
|
+
|
|
733
|
+
// src/object/construct.ts
|
|
734
|
+
var construct = (obj) => {
|
|
735
|
+
if (!obj) return {};
|
|
736
|
+
return Object.keys(obj).reduce((acc, path) => {
|
|
737
|
+
return set(acc, path, obj[path]);
|
|
738
|
+
}, {});
|
|
739
|
+
};
|
|
740
|
+
|
|
741
|
+
// src/object/crush.ts
|
|
742
|
+
var crush = (value) => {
|
|
743
|
+
if (!value) return {};
|
|
744
|
+
return objectify(
|
|
745
|
+
keys(value),
|
|
746
|
+
(k) => k,
|
|
747
|
+
(k) => get(value, k)
|
|
748
|
+
);
|
|
749
|
+
};
|
|
750
|
+
|
|
751
|
+
// src/object/get.ts
|
|
752
|
+
var get = (value, path, defaultValue) => {
|
|
753
|
+
const segments = path.split(/[\.\[\]]/g);
|
|
754
|
+
let current = value;
|
|
755
|
+
for (const key of segments) {
|
|
756
|
+
if (current === null) return defaultValue;
|
|
757
|
+
if (current === void 0) return defaultValue;
|
|
758
|
+
const dequoted = key.replace(/['"]/g, "");
|
|
759
|
+
if (dequoted.trim() === "") continue;
|
|
760
|
+
current = current[dequoted];
|
|
761
|
+
}
|
|
762
|
+
if (current === void 0) return defaultValue;
|
|
763
|
+
return current;
|
|
764
|
+
};
|
|
765
|
+
|
|
766
|
+
// src/object/invert.ts
|
|
767
|
+
var invert = (obj) => {
|
|
768
|
+
if (!obj) return {};
|
|
769
|
+
const keys2 = Object.keys(obj);
|
|
770
|
+
return keys2.reduce((acc, key) => {
|
|
771
|
+
acc[obj[key]] = key;
|
|
772
|
+
return acc;
|
|
773
|
+
}, {});
|
|
774
|
+
};
|
|
775
|
+
|
|
776
|
+
// src/object/keys.ts
|
|
777
|
+
var keys = (value) => {
|
|
778
|
+
if (!value) return [];
|
|
779
|
+
const getKeys = (nested, paths) => {
|
|
780
|
+
if (isPlainObject(nested)) {
|
|
781
|
+
return Object.entries(nested).flatMap(
|
|
782
|
+
([k, v]) => getKeys(v, [...paths, k])
|
|
783
|
+
);
|
|
784
|
+
}
|
|
785
|
+
if (isArray(nested)) {
|
|
786
|
+
return nested.flatMap((item, i) => getKeys(item, [...paths, `${i}`]));
|
|
787
|
+
}
|
|
788
|
+
return [paths.join(".")];
|
|
789
|
+
};
|
|
790
|
+
return getKeys(value, []);
|
|
791
|
+
};
|
|
792
|
+
|
|
793
|
+
// src/object/listify.ts
|
|
794
|
+
var listify = (obj, toItem) => {
|
|
795
|
+
if (!obj) return [];
|
|
796
|
+
const entries = Object.entries(obj);
|
|
797
|
+
if (entries.length === 0) return [];
|
|
798
|
+
return entries.reduce((acc, entry) => {
|
|
799
|
+
acc.push(toItem(entry[0], entry[1]));
|
|
800
|
+
return acc;
|
|
801
|
+
}, []);
|
|
802
|
+
};
|
|
803
|
+
|
|
804
|
+
// src/object/lowerize.ts
|
|
805
|
+
var lowerize = (obj) => mapKeys(obj, (k) => k.toLowerCase());
|
|
806
|
+
|
|
807
|
+
// src/object/mapEntries.ts
|
|
808
|
+
var mapEntries = (obj, toEntry) => {
|
|
809
|
+
if (!obj) return {};
|
|
810
|
+
return Object.entries(obj).reduce((acc, [key, value]) => {
|
|
811
|
+
const [newKey, newValue] = toEntry(key, value);
|
|
812
|
+
acc[newKey] = newValue;
|
|
813
|
+
return acc;
|
|
814
|
+
}, {});
|
|
815
|
+
};
|
|
816
|
+
|
|
817
|
+
// src/object/mapKeys.ts
|
|
818
|
+
var mapKeys = (obj, mapFunc) => {
|
|
819
|
+
const keys2 = Object.keys(obj);
|
|
820
|
+
return keys2.reduce((acc, key) => {
|
|
821
|
+
acc[mapFunc(key, obj[key])] = obj[key];
|
|
822
|
+
return acc;
|
|
823
|
+
}, {});
|
|
824
|
+
};
|
|
825
|
+
|
|
826
|
+
// src/object/mapValues.ts
|
|
827
|
+
var mapValues = (obj, mapFunc) => {
|
|
828
|
+
const keys2 = Object.keys(obj);
|
|
829
|
+
return keys2.reduce((acc, key) => {
|
|
830
|
+
acc[key] = mapFunc(obj[key], key);
|
|
831
|
+
return acc;
|
|
832
|
+
}, {});
|
|
833
|
+
};
|
|
834
|
+
|
|
835
|
+
// src/object/omit.ts
|
|
836
|
+
var omit = (obj, keys2) => {
|
|
837
|
+
if (!obj) return {};
|
|
838
|
+
if (!keys2 || keys2.length === 0) return obj;
|
|
839
|
+
return keys2.reduce(
|
|
840
|
+
(acc, key) => {
|
|
841
|
+
delete acc[key];
|
|
842
|
+
return acc;
|
|
843
|
+
},
|
|
844
|
+
{ ...obj }
|
|
845
|
+
);
|
|
846
|
+
};
|
|
847
|
+
|
|
848
|
+
// src/object/pick.ts
|
|
849
|
+
var pick = (obj, keys2) => {
|
|
850
|
+
if (!obj) return {};
|
|
851
|
+
return keys2.reduce((acc, key) => {
|
|
852
|
+
if (Object.hasOwnProperty.call(obj, key)) acc[key] = obj[key];
|
|
853
|
+
return acc;
|
|
854
|
+
}, {});
|
|
855
|
+
};
|
|
856
|
+
|
|
857
|
+
// src/object/set.ts
|
|
858
|
+
var set = (initial, path, value) => {
|
|
859
|
+
if (!initial) return {};
|
|
860
|
+
if (!path || value === void 0) return initial;
|
|
861
|
+
const root = clone(initial);
|
|
862
|
+
const keys2 = path.match(/[^.[\]]+/g);
|
|
863
|
+
if (keys2)
|
|
864
|
+
keys2.reduce(
|
|
865
|
+
(object, key, i) => i < keys2.length - 1 ? object[key] ??= isIntString(keys2[i + 1]) ? [] : {} : object[key] = value,
|
|
866
|
+
root
|
|
867
|
+
);
|
|
868
|
+
return root;
|
|
869
|
+
};
|
|
870
|
+
|
|
871
|
+
// src/object/shake.ts
|
|
872
|
+
var shake = (obj, filter = (value) => value === void 0) => {
|
|
873
|
+
if (!obj) return {};
|
|
874
|
+
const keys2 = Object.keys(obj);
|
|
875
|
+
return keys2.reduce((acc, key) => {
|
|
876
|
+
if (!filter(obj[key])) {
|
|
877
|
+
acc[key] = obj[key];
|
|
878
|
+
}
|
|
879
|
+
return acc;
|
|
880
|
+
}, {});
|
|
881
|
+
};
|
|
882
|
+
|
|
883
|
+
// src/object/upperize.ts
|
|
884
|
+
var upperize = (obj) => mapKeys(obj, (k) => k.toUpperCase());
|
|
885
|
+
|
|
886
|
+
// src/random/draw.ts
|
|
887
|
+
var draw = (array) => {
|
|
888
|
+
const max2 = array.length;
|
|
889
|
+
if (max2 === 0) {
|
|
890
|
+
return null;
|
|
891
|
+
}
|
|
892
|
+
const index = random(0, max2 - 1);
|
|
893
|
+
return array[index];
|
|
894
|
+
};
|
|
895
|
+
|
|
896
|
+
// src/random/random.ts
|
|
897
|
+
var random = (min2, max2) => {
|
|
898
|
+
return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
|
|
899
|
+
};
|
|
900
|
+
|
|
901
|
+
// src/random/shuffle.ts
|
|
902
|
+
var shuffle = (array) => {
|
|
903
|
+
return array.map((a) => ({ rand: Math.random(), value: a })).sort((a, b) => a.rand - b.rand).map((a) => a.value);
|
|
904
|
+
};
|
|
905
|
+
|
|
906
|
+
// src/random/uid.ts
|
|
907
|
+
var uid = (length, specials = "") => {
|
|
908
|
+
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" + specials;
|
|
909
|
+
return iterate(
|
|
910
|
+
length,
|
|
911
|
+
(acc) => {
|
|
912
|
+
return acc + characters.charAt(random(0, characters.length - 1));
|
|
913
|
+
},
|
|
914
|
+
""
|
|
915
|
+
);
|
|
916
|
+
};
|
|
917
|
+
|
|
918
|
+
// src/series/series.ts
|
|
919
|
+
var series = (items, toKey = (item) => `${item}`) => {
|
|
920
|
+
const { indexesByKey, itemsByIndex } = items.reduce(
|
|
921
|
+
(acc, item, idx) => ({
|
|
922
|
+
indexesByKey: {
|
|
923
|
+
...acc.indexesByKey,
|
|
924
|
+
[toKey(item)]: idx
|
|
925
|
+
},
|
|
926
|
+
itemsByIndex: {
|
|
927
|
+
...acc.itemsByIndex,
|
|
928
|
+
[idx]: item
|
|
929
|
+
}
|
|
930
|
+
}),
|
|
931
|
+
{
|
|
932
|
+
indexesByKey: {},
|
|
933
|
+
itemsByIndex: {}
|
|
934
|
+
}
|
|
935
|
+
);
|
|
936
|
+
const min2 = (a, b) => {
|
|
937
|
+
return indexesByKey[toKey(a)] < indexesByKey[toKey(b)] ? a : b;
|
|
938
|
+
};
|
|
939
|
+
const max2 = (a, b) => {
|
|
940
|
+
return indexesByKey[toKey(a)] > indexesByKey[toKey(b)] ? a : b;
|
|
941
|
+
};
|
|
942
|
+
const first2 = () => {
|
|
943
|
+
return itemsByIndex[0];
|
|
944
|
+
};
|
|
945
|
+
const last2 = () => {
|
|
946
|
+
return itemsByIndex[items.length - 1];
|
|
947
|
+
};
|
|
948
|
+
const next = (current, defaultValue) => {
|
|
949
|
+
return itemsByIndex[indexesByKey[toKey(current)] + 1] ?? defaultValue ?? first2();
|
|
950
|
+
};
|
|
951
|
+
const previous = (current, defaultValue) => {
|
|
952
|
+
return itemsByIndex[indexesByKey[toKey(current)] - 1] ?? defaultValue ?? last2();
|
|
953
|
+
};
|
|
954
|
+
const spin = (current, num) => {
|
|
955
|
+
if (num === 0) return current;
|
|
956
|
+
const abs = Math.abs(num);
|
|
957
|
+
const rel = abs > items.length ? abs % items.length : abs;
|
|
958
|
+
return list(0, rel - 1).reduce(
|
|
959
|
+
(acc) => num > 0 ? next(acc) : previous(acc),
|
|
960
|
+
current
|
|
961
|
+
);
|
|
962
|
+
};
|
|
963
|
+
return {
|
|
964
|
+
min: min2,
|
|
965
|
+
max: max2,
|
|
966
|
+
first: first2,
|
|
967
|
+
last: last2,
|
|
968
|
+
next,
|
|
969
|
+
previous,
|
|
970
|
+
spin
|
|
971
|
+
};
|
|
972
|
+
};
|
|
973
|
+
|
|
974
|
+
// src/string/camel.ts
|
|
975
|
+
var camel = (str) => {
|
|
976
|
+
var _a;
|
|
977
|
+
const parts = ((_a = str == null ? void 0 : str.replace(/([A-Z])+/g, capitalize)) == null ? void 0 : _a.split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase())) ?? [];
|
|
978
|
+
if (parts.length === 0) return "";
|
|
979
|
+
if (parts.length === 1) return parts[0];
|
|
980
|
+
return parts.reduce((acc, part) => {
|
|
981
|
+
return `${acc}${part.charAt(0).toUpperCase()}${part.slice(1)}`;
|
|
982
|
+
});
|
|
983
|
+
};
|
|
984
|
+
|
|
985
|
+
// src/string/capitalize.ts
|
|
986
|
+
var capitalize = (str) => {
|
|
987
|
+
if (!str || str.length === 0) return "";
|
|
988
|
+
const lower = str.toLowerCase();
|
|
989
|
+
return lower.substring(0, 1).toUpperCase() + lower.substring(1, lower.length);
|
|
990
|
+
};
|
|
991
|
+
|
|
992
|
+
// src/string/dash.ts
|
|
993
|
+
var dash = (str) => {
|
|
994
|
+
var _a;
|
|
995
|
+
const parts = ((_a = str == null ? void 0 : str.replace(/([A-Z])+/g, capitalize)) == null ? void 0 : _a.split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase())) ?? [];
|
|
996
|
+
if (parts.length === 0) return "";
|
|
997
|
+
if (parts.length === 1) return parts[0];
|
|
998
|
+
return parts.reduce((acc, part) => {
|
|
999
|
+
return `${acc}-${part.toLowerCase()}`;
|
|
1000
|
+
});
|
|
1001
|
+
};
|
|
1002
|
+
|
|
1003
|
+
// src/string/pascal.ts
|
|
1004
|
+
var pascal = (str) => {
|
|
1005
|
+
const parts = (str == null ? void 0 : str.split(/[\.\-\s_]/).map((x) => x.toLowerCase())) ?? [];
|
|
1006
|
+
if (parts.length === 0) return "";
|
|
1007
|
+
return parts.map((str2) => str2.charAt(0).toUpperCase() + str2.slice(1)).join("");
|
|
1008
|
+
};
|
|
1009
|
+
|
|
1010
|
+
// src/string/snake.ts
|
|
1011
|
+
var snake = (str, options) => {
|
|
1012
|
+
const parts = (str == null ? void 0 : str.replace(/([A-Z])+/g, capitalize).split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase())) ?? [];
|
|
1013
|
+
if (parts.length === 0) return "";
|
|
1014
|
+
if (parts.length === 1) return parts[0];
|
|
1015
|
+
const result = parts.reduce((acc, part) => {
|
|
1016
|
+
return `${acc}_${part.toLowerCase()}`;
|
|
1017
|
+
});
|
|
1018
|
+
return (options == null ? void 0 : options.splitOnNumber) === false ? result : result.replace(/([A-Za-z]{1}[0-9]{1})/, (val) => `${val[0]}_${val[1]}`);
|
|
1019
|
+
};
|
|
1020
|
+
|
|
1021
|
+
// src/string/template.ts
|
|
1022
|
+
var template = (str, data, regex = /\{\{(.+?)\}\}/g) => {
|
|
1023
|
+
return Array.from(str.matchAll(regex)).reduce((acc, match) => {
|
|
1024
|
+
return acc.replace(match[0], data[match[1]]);
|
|
1025
|
+
}, str);
|
|
1026
|
+
};
|
|
1027
|
+
|
|
1028
|
+
// src/string/title.ts
|
|
1029
|
+
var title = (str) => {
|
|
1030
|
+
if (!str) return "";
|
|
1031
|
+
return str.split(/(?=[A-Z])|[\.\-\s_]/).map((s) => s.trim()).filter((s) => !!s).map((s) => capitalize(s.toLowerCase())).join(" ");
|
|
1032
|
+
};
|
|
1033
|
+
|
|
1034
|
+
// src/string/trim.ts
|
|
1035
|
+
var trim = (str, charsToTrim = " ") => {
|
|
1036
|
+
if (!str) return "";
|
|
1037
|
+
const toTrim = charsToTrim.replace(/[\W]{1}/g, "\\$&");
|
|
1038
|
+
const regex = new RegExp(`^[${toTrim}]+|[${toTrim}]+$`, "g");
|
|
1039
|
+
return str.replace(regex, "");
|
|
1040
|
+
};
|
|
1041
|
+
|
|
1042
|
+
// src/typed/isArray.ts
|
|
1043
|
+
var isArray = Array.isArray;
|
|
1044
|
+
|
|
1045
|
+
// src/typed/isDate.ts
|
|
1046
|
+
var isDate = (value) => {
|
|
1047
|
+
return Object.prototype.toString.call(value) === "[object Date]";
|
|
1048
|
+
};
|
|
1049
|
+
|
|
1050
|
+
// src/typed/isEmpty.ts
|
|
1051
|
+
var isEmpty = (value) => {
|
|
1052
|
+
if (value === true || value === false) return true;
|
|
1053
|
+
if (value === null || value === void 0) return true;
|
|
1054
|
+
if (isNumber(value)) return value === 0;
|
|
1055
|
+
if (isDate(value)) return isNaN(value.getTime());
|
|
1056
|
+
if (isFunction(value)) return false;
|
|
1057
|
+
if (isSymbol(value)) return false;
|
|
1058
|
+
const length = value.length;
|
|
1059
|
+
if (isNumber(length)) return length === 0;
|
|
1060
|
+
const size = value.size;
|
|
1061
|
+
if (isNumber(size)) return size === 0;
|
|
1062
|
+
const keys2 = Object.keys(value).length;
|
|
1063
|
+
return keys2 === 0;
|
|
1064
|
+
};
|
|
1065
|
+
|
|
1066
|
+
// src/typed/isEqual.ts
|
|
1067
|
+
var isEqual = (x, y) => {
|
|
1068
|
+
if (Object.is(x, y)) return true;
|
|
1069
|
+
if (x instanceof Date && y instanceof Date) {
|
|
1070
|
+
return x.getTime() === y.getTime();
|
|
1071
|
+
}
|
|
1072
|
+
if (x instanceof RegExp && y instanceof RegExp) {
|
|
1073
|
+
return x.toString() === y.toString();
|
|
1074
|
+
}
|
|
1075
|
+
if (typeof x !== "object" || x === null || typeof y !== "object" || y === null) {
|
|
1076
|
+
return false;
|
|
1077
|
+
}
|
|
1078
|
+
const keysX = Reflect.ownKeys(x);
|
|
1079
|
+
const keysY = Reflect.ownKeys(y);
|
|
1080
|
+
if (keysX.length !== keysY.length) return false;
|
|
1081
|
+
for (let i = 0; i < keysX.length; i++) {
|
|
1082
|
+
if (!Reflect.has(y, keysX[i])) return false;
|
|
1083
|
+
if (!isEqual(x[keysX[i]], y[keysX[i]])) return false;
|
|
1084
|
+
}
|
|
1085
|
+
return true;
|
|
1086
|
+
};
|
|
1087
|
+
|
|
1088
|
+
// src/typed/isFloat.ts
|
|
1089
|
+
var isFloat = (value) => {
|
|
1090
|
+
return isNumber(value) && value % 1 !== 0;
|
|
1091
|
+
};
|
|
1092
|
+
|
|
1093
|
+
// src/typed/isFunction.ts
|
|
1094
|
+
var isFunction = (value) => {
|
|
1095
|
+
return !!(value && value.constructor && value.call && value.apply);
|
|
1096
|
+
};
|
|
1097
|
+
|
|
1098
|
+
// src/typed/isInt.ts
|
|
1099
|
+
var isInt = (value) => {
|
|
1100
|
+
return isNumber(value) && value % 1 === 0;
|
|
1101
|
+
};
|
|
1102
|
+
|
|
1103
|
+
// src/typed/isIntString.ts
|
|
1104
|
+
var isIntString = (value) => {
|
|
1105
|
+
if (!isString(value)) return false;
|
|
1106
|
+
const num = +value;
|
|
1107
|
+
return Number.isInteger(num) && `${num}` === value;
|
|
1108
|
+
};
|
|
1109
|
+
|
|
1110
|
+
// src/typed/isNumber.ts
|
|
1111
|
+
var isNumber = (value) => {
|
|
1112
|
+
try {
|
|
1113
|
+
return Number(value) === value;
|
|
1114
|
+
} catch {
|
|
1115
|
+
return false;
|
|
1116
|
+
}
|
|
1117
|
+
};
|
|
1118
|
+
|
|
1119
|
+
// src/typed/isObject.ts
|
|
1120
|
+
var isObject = (value) => {
|
|
1121
|
+
return !!value && value.constructor === Object;
|
|
1122
|
+
};
|
|
1123
|
+
|
|
1124
|
+
// src/typed/isPlainObject.ts
|
|
1125
|
+
var isPlainObject = (value) => {
|
|
1126
|
+
if (typeof value !== "object" || value === null) {
|
|
1127
|
+
return false;
|
|
1128
|
+
}
|
|
1129
|
+
const prototype = Object.getPrototypeOf(value);
|
|
1130
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
1131
|
+
};
|
|
1132
|
+
|
|
1133
|
+
// src/typed/isPrimitive.ts
|
|
1134
|
+
var isPrimitive = (value) => {
|
|
1135
|
+
return value === void 0 || value === null || typeof value !== "object" && typeof value !== "function";
|
|
1136
|
+
};
|
|
1137
|
+
|
|
1138
|
+
// src/typed/isPromise.ts
|
|
1139
|
+
var isPromise = (value) => {
|
|
1140
|
+
if (!value) return false;
|
|
1141
|
+
if (!value.then) return false;
|
|
1142
|
+
if (!isFunction(value.then)) return false;
|
|
1143
|
+
return true;
|
|
1144
|
+
};
|
|
1145
|
+
|
|
1146
|
+
// src/typed/isString.ts
|
|
1147
|
+
var isString = (value) => {
|
|
1148
|
+
return typeof value === "string" || value instanceof String;
|
|
1149
|
+
};
|
|
1150
|
+
|
|
1151
|
+
// src/typed/isSymbol.ts
|
|
1152
|
+
var isSymbol = (value) => {
|
|
1153
|
+
return !!value && value.constructor === Symbol;
|
|
1154
|
+
};
|
|
1155
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1156
|
+
0 && (module.exports = {
|
|
1157
|
+
AggregateError,
|
|
1158
|
+
all,
|
|
1159
|
+
alphabetical,
|
|
1160
|
+
assign,
|
|
1161
|
+
boil,
|
|
1162
|
+
callable,
|
|
1163
|
+
camel,
|
|
1164
|
+
capitalize,
|
|
1165
|
+
chain,
|
|
1166
|
+
clone,
|
|
1167
|
+
cluster,
|
|
1168
|
+
compose,
|
|
1169
|
+
construct,
|
|
1170
|
+
counting,
|
|
1171
|
+
crush,
|
|
1172
|
+
dash,
|
|
1173
|
+
debounce,
|
|
1174
|
+
defer,
|
|
1175
|
+
diff,
|
|
1176
|
+
draw,
|
|
1177
|
+
first,
|
|
1178
|
+
flat,
|
|
1179
|
+
fork,
|
|
1180
|
+
get,
|
|
1181
|
+
group,
|
|
1182
|
+
guard,
|
|
1183
|
+
inRange,
|
|
1184
|
+
intersects,
|
|
1185
|
+
invert,
|
|
1186
|
+
isArray,
|
|
1187
|
+
isDate,
|
|
1188
|
+
isEmpty,
|
|
1189
|
+
isEqual,
|
|
1190
|
+
isFloat,
|
|
1191
|
+
isFunction,
|
|
1192
|
+
isInt,
|
|
1193
|
+
isIntString,
|
|
1194
|
+
isNumber,
|
|
1195
|
+
isObject,
|
|
1196
|
+
isPlainObject,
|
|
1197
|
+
isPrimitive,
|
|
1198
|
+
isPromise,
|
|
1199
|
+
isString,
|
|
1200
|
+
isSymbol,
|
|
1201
|
+
iterate,
|
|
1202
|
+
keys,
|
|
1203
|
+
last,
|
|
1204
|
+
list,
|
|
1205
|
+
listify,
|
|
1206
|
+
lowerize,
|
|
1207
|
+
map,
|
|
1208
|
+
mapEntries,
|
|
1209
|
+
mapKeys,
|
|
1210
|
+
mapValues,
|
|
1211
|
+
max,
|
|
1212
|
+
memo,
|
|
1213
|
+
merge,
|
|
1214
|
+
min,
|
|
1215
|
+
objectify,
|
|
1216
|
+
omit,
|
|
1217
|
+
parallel,
|
|
1218
|
+
partial,
|
|
1219
|
+
partob,
|
|
1220
|
+
pascal,
|
|
1221
|
+
pick,
|
|
1222
|
+
proxied,
|
|
1223
|
+
random,
|
|
1224
|
+
range,
|
|
1225
|
+
reduce,
|
|
1226
|
+
replace,
|
|
1227
|
+
replaceOrAppend,
|
|
1228
|
+
retry,
|
|
1229
|
+
select,
|
|
1230
|
+
series,
|
|
1231
|
+
set,
|
|
1232
|
+
shake,
|
|
1233
|
+
shift,
|
|
1234
|
+
shuffle,
|
|
1235
|
+
sift,
|
|
1236
|
+
sleep,
|
|
1237
|
+
snake,
|
|
1238
|
+
sort,
|
|
1239
|
+
sum,
|
|
1240
|
+
template,
|
|
1241
|
+
throttle,
|
|
1242
|
+
title,
|
|
1243
|
+
toFloat,
|
|
1244
|
+
toInt,
|
|
1245
|
+
toggle,
|
|
1246
|
+
trim,
|
|
1247
|
+
try: null,
|
|
1248
|
+
tryit,
|
|
1249
|
+
uid,
|
|
1250
|
+
unique,
|
|
1251
|
+
upperize,
|
|
1252
|
+
zip,
|
|
1253
|
+
zipToObject
|
|
1254
|
+
});
|