radashi 13.0.0-beta.ffa4778 → 13.0.2
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/README.md +12 -12
- package/dist/radashi.cjs +695 -136
- package/dist/radashi.d.cts +3067 -2275
- package/dist/radashi.d.ts +3067 -2275
- package/dist/radashi.js +665 -137
- package/package.json +18 -17
package/dist/radashi.cjs
CHANGED
|
@@ -40,36 +40,49 @@ function castArrayIfExists(value) {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
// src/array/cluster.ts
|
|
43
|
-
function cluster(array, size
|
|
43
|
+
function cluster(array, size) {
|
|
44
44
|
const clusters = [];
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
if (size > 0) {
|
|
46
|
+
for (let i = 0; i < array.length; i += size) {
|
|
47
|
+
clusters.push(array.slice(i, i + size));
|
|
48
|
+
}
|
|
47
49
|
}
|
|
48
50
|
return clusters;
|
|
49
51
|
}
|
|
50
52
|
|
|
53
|
+
// src/array/concat.ts
|
|
54
|
+
function concat(...values) {
|
|
55
|
+
const result = [];
|
|
56
|
+
const append = (value) => value != null && result.push(value);
|
|
57
|
+
for (const value of values) {
|
|
58
|
+
if (Array.isArray(value)) {
|
|
59
|
+
value.forEach(append);
|
|
60
|
+
} else {
|
|
61
|
+
append(value);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
|
|
51
67
|
// src/array/counting.ts
|
|
52
|
-
function counting(array,
|
|
68
|
+
function counting(array, identity2) {
|
|
53
69
|
return array.reduce(
|
|
54
70
|
(acc, item) => {
|
|
55
|
-
const id =
|
|
71
|
+
const id = identity2(item);
|
|
56
72
|
acc[id] = (acc[id] ?? 0) + 1;
|
|
57
73
|
return acc;
|
|
58
74
|
},
|
|
59
|
-
|
|
75
|
+
/* @__PURE__ */ Object.create(null)
|
|
60
76
|
);
|
|
61
77
|
}
|
|
62
78
|
|
|
63
79
|
// src/array/diff.ts
|
|
64
|
-
function diff(root, other,
|
|
65
|
-
const bKeys =
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
{}
|
|
71
|
-
);
|
|
72
|
-
return root.filter((a) => !bKeys[identity(a)]);
|
|
80
|
+
function diff(root, other, identity2 = (t) => t) {
|
|
81
|
+
const bKeys = /* @__PURE__ */ new Set();
|
|
82
|
+
for (const item of other) {
|
|
83
|
+
bKeys.add(identity2(item));
|
|
84
|
+
}
|
|
85
|
+
return root.filter((a) => !bKeys.has(identity2(a)));
|
|
73
86
|
}
|
|
74
87
|
|
|
75
88
|
// src/array/first.ts
|
|
@@ -96,28 +109,41 @@ function fork(array, condition) {
|
|
|
96
109
|
|
|
97
110
|
// src/array/group.ts
|
|
98
111
|
function group(array, getGroupId) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
{}
|
|
109
|
-
);
|
|
112
|
+
const groups = /* @__PURE__ */ Object.create(null);
|
|
113
|
+
array.forEach((item, index) => {
|
|
114
|
+
const groupId = getGroupId(item, index);
|
|
115
|
+
if (!groups[groupId]) {
|
|
116
|
+
groups[groupId] = [];
|
|
117
|
+
}
|
|
118
|
+
groups[groupId].push(item);
|
|
119
|
+
});
|
|
120
|
+
return groups;
|
|
110
121
|
}
|
|
111
122
|
|
|
112
123
|
// src/array/intersects.ts
|
|
113
|
-
function intersects(listA, listB,
|
|
114
|
-
if (
|
|
115
|
-
const known = new Set(listA.map(
|
|
116
|
-
return listB.some((item) => known.has(
|
|
124
|
+
function intersects(listA, listB, identity2) {
|
|
125
|
+
if (identity2) {
|
|
126
|
+
const known = new Set(listA.map(identity2));
|
|
127
|
+
return listB.some((item) => known.has(identity2(item)));
|
|
117
128
|
}
|
|
118
129
|
return listB.some((item) => listA.includes(item));
|
|
119
130
|
}
|
|
120
131
|
|
|
132
|
+
// src/array/isArrayEqual.ts
|
|
133
|
+
function isArrayEqual(array1, array2) {
|
|
134
|
+
if (array1 !== array2) {
|
|
135
|
+
if (array1.length !== array2.length) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
for (let i = 0; i < array1.length; i++) {
|
|
139
|
+
if (!Object.is(array1[i], array2[i])) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
|
|
121
147
|
// src/array/iterate.ts
|
|
122
148
|
function iterate(count, func, initValue) {
|
|
123
149
|
let value = initValue;
|
|
@@ -140,8 +166,8 @@ function list(startOrLength, end, valueOrMapper, step) {
|
|
|
140
166
|
// src/array/mapify.ts
|
|
141
167
|
function mapify(array, getKey, getValue = (item) => item) {
|
|
142
168
|
const map2 = /* @__PURE__ */ new Map();
|
|
143
|
-
for (const item of array) {
|
|
144
|
-
map2.set(getKey(item,
|
|
169
|
+
for (const [index, item] of array.entries()) {
|
|
170
|
+
map2.set(getKey(item, index), getValue(item, index));
|
|
145
171
|
}
|
|
146
172
|
return map2;
|
|
147
173
|
}
|
|
@@ -161,14 +187,28 @@ function merge(prev, array, toKey) {
|
|
|
161
187
|
// src/array/objectify.ts
|
|
162
188
|
function objectify(array, getKey, getValue = (item) => item) {
|
|
163
189
|
return array.reduce(
|
|
164
|
-
(acc, item) => {
|
|
165
|
-
acc[getKey(item)] = getValue(item);
|
|
190
|
+
(acc, item, i) => {
|
|
191
|
+
acc[getKey(item, i)] = getValue(item, i);
|
|
166
192
|
return acc;
|
|
167
193
|
},
|
|
168
194
|
{}
|
|
169
195
|
);
|
|
170
196
|
}
|
|
171
197
|
|
|
198
|
+
// src/array/pluck.ts
|
|
199
|
+
function pluck(array, mappings) {
|
|
200
|
+
return array.map(
|
|
201
|
+
mappings ? (item) => mappings.map(
|
|
202
|
+
(mapping) => isFunction(mapping) ? mapping(item) : item[mapping]
|
|
203
|
+
) : Object.values
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// src/array/remove.ts
|
|
208
|
+
function remove(array, predicate) {
|
|
209
|
+
return array.filter((item) => !predicate(item));
|
|
210
|
+
}
|
|
211
|
+
|
|
172
212
|
// src/array/replace.ts
|
|
173
213
|
function replace(array, newItem, match) {
|
|
174
214
|
if (newItem === void 0) {
|
|
@@ -215,12 +255,12 @@ function select(array, mapper, condition) {
|
|
|
215
255
|
|
|
216
256
|
// src/array/selectFirst.ts
|
|
217
257
|
function selectFirst(array, mapper, condition) {
|
|
218
|
-
let
|
|
219
|
-
const
|
|
220
|
-
|
|
258
|
+
let foundItem;
|
|
259
|
+
const foundIndex = array.findIndex((item, index) => {
|
|
260
|
+
foundItem = item;
|
|
221
261
|
return condition ? condition(item, index) : mapper(item, index) != null;
|
|
222
262
|
});
|
|
223
|
-
return
|
|
263
|
+
return foundIndex === -1 ? void 0 : mapper(foundItem, foundIndex);
|
|
224
264
|
}
|
|
225
265
|
|
|
226
266
|
// src/array/shift.ts
|
|
@@ -237,14 +277,14 @@ function shift(arr, n) {
|
|
|
237
277
|
|
|
238
278
|
// src/array/sift.ts
|
|
239
279
|
function sift(array) {
|
|
240
|
-
return
|
|
280
|
+
return array?.filter((x) => !!x) ?? [];
|
|
241
281
|
}
|
|
242
282
|
|
|
243
283
|
// src/array/sort.ts
|
|
244
|
-
function sort(array, getter,
|
|
284
|
+
function sort(array, getter = identity, direction = "asc") {
|
|
245
285
|
const asc = (a, b) => getter(a) - getter(b);
|
|
246
286
|
const dsc = (a, b) => getter(b) - getter(a);
|
|
247
|
-
return array.slice().sort(
|
|
287
|
+
return array.slice().sort(direction === "desc" ? dsc : asc);
|
|
248
288
|
}
|
|
249
289
|
|
|
250
290
|
// src/array/toggle.ts
|
|
@@ -259,11 +299,11 @@ function toggle(array, item, toKey, options) {
|
|
|
259
299
|
} else {
|
|
260
300
|
matcher = (x) => x === item;
|
|
261
301
|
}
|
|
262
|
-
const
|
|
263
|
-
if (
|
|
302
|
+
const existingIndex = array.findIndex(matcher);
|
|
303
|
+
if (existingIndex !== -1) {
|
|
264
304
|
return array.filter((x, idx) => !matcher(x, idx));
|
|
265
305
|
}
|
|
266
|
-
return
|
|
306
|
+
return options?.strategy === "prepend" ? [item, ...array] : [...array, item];
|
|
267
307
|
}
|
|
268
308
|
|
|
269
309
|
// src/array/unique.ts
|
|
@@ -312,19 +352,6 @@ function zipToObject(keys2, values) {
|
|
|
312
352
|
);
|
|
313
353
|
}
|
|
314
354
|
|
|
315
|
-
// src/async/AggregateError.ts
|
|
316
|
-
var AggregateErrorOrPolyfill = /* @__PURE__ */ (() => globalThis.AggregateError ?? class AggregateError extends Error {
|
|
317
|
-
constructor(errors = []) {
|
|
318
|
-
var _a, _b;
|
|
319
|
-
super();
|
|
320
|
-
const name = ((_a = errors.find((e) => e.name)) == null ? void 0 : _a.name) ?? "";
|
|
321
|
-
this.name = `AggregateError(${name}...)`;
|
|
322
|
-
this.message = `AggregateError with ${errors.length} errors`;
|
|
323
|
-
this.stack = ((_b = errors.find((e) => e.stack)) == null ? void 0 : _b.stack) ?? this.stack;
|
|
324
|
-
this.errors = errors;
|
|
325
|
-
}
|
|
326
|
-
})();
|
|
327
|
-
|
|
328
355
|
// src/async/all.ts
|
|
329
356
|
async function all(input) {
|
|
330
357
|
const errors = [];
|
|
@@ -355,7 +382,7 @@ async function defer(func) {
|
|
|
355
382
|
const callbacks = [];
|
|
356
383
|
const register = (fn, options) => callbacks.push({
|
|
357
384
|
fn,
|
|
358
|
-
rethrow:
|
|
385
|
+
rethrow: options?.rethrow ?? false
|
|
359
386
|
});
|
|
360
387
|
const [err, response] = await tryit(func)(register);
|
|
361
388
|
for (const { fn, rethrow } of callbacks) {
|
|
@@ -372,17 +399,16 @@ async function defer(func) {
|
|
|
372
399
|
|
|
373
400
|
// src/async/guard.ts
|
|
374
401
|
function guard(func, shouldGuard) {
|
|
375
|
-
const
|
|
402
|
+
const onError = (err) => {
|
|
376
403
|
if (shouldGuard && !shouldGuard(err)) {
|
|
377
404
|
throw err;
|
|
378
405
|
}
|
|
379
|
-
return void 0;
|
|
380
406
|
};
|
|
381
407
|
try {
|
|
382
408
|
const result = func();
|
|
383
|
-
return result instanceof Promise ? result.catch(
|
|
409
|
+
return result instanceof Promise ? result.catch(onError) : result;
|
|
384
410
|
} catch (err) {
|
|
385
|
-
return
|
|
411
|
+
return onError(err);
|
|
386
412
|
}
|
|
387
413
|
}
|
|
388
414
|
|
|
@@ -413,21 +439,20 @@ async function parallel(options, array, func) {
|
|
|
413
439
|
};
|
|
414
440
|
} else {
|
|
415
441
|
signal = options.signal;
|
|
416
|
-
signal
|
|
442
|
+
signal?.throwIfAborted();
|
|
417
443
|
}
|
|
418
444
|
const processor = async (resolve) => {
|
|
419
445
|
const results2 = [];
|
|
420
|
-
while (!
|
|
446
|
+
while (!signal?.aborted) {
|
|
421
447
|
const next = work.pop();
|
|
422
448
|
if (!next) {
|
|
423
449
|
break;
|
|
424
450
|
}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
result,
|
|
429
|
-
|
|
430
|
-
});
|
|
451
|
+
try {
|
|
452
|
+
results2.push({ result: await func(next.item), index: next.index });
|
|
453
|
+
} catch (error) {
|
|
454
|
+
results2.push({ error, result: void 0, index: next.index });
|
|
455
|
+
}
|
|
431
456
|
}
|
|
432
457
|
return resolve(results2);
|
|
433
458
|
};
|
|
@@ -447,7 +472,7 @@ async function parallel(options, array, func) {
|
|
|
447
472
|
const itemResults = await (signalPromise ? Promise.race([queues, signalPromise]) : queues);
|
|
448
473
|
const [errors, results] = fork(
|
|
449
474
|
sort(flat(itemResults), (r) => r.index),
|
|
450
|
-
(x) =>
|
|
475
|
+
(x) => "error" in x
|
|
451
476
|
);
|
|
452
477
|
if (errors.length > 0) {
|
|
453
478
|
throw new AggregateErrorOrPolyfill(errors.map((error) => error.error));
|
|
@@ -455,35 +480,48 @@ async function parallel(options, array, func) {
|
|
|
455
480
|
return results.map((r) => r.result);
|
|
456
481
|
}
|
|
457
482
|
|
|
483
|
+
// src/async/queueByKey.ts
|
|
484
|
+
function queueByKey(asyncFn, keyFn) {
|
|
485
|
+
const queues = /* @__PURE__ */ new Map();
|
|
486
|
+
return async (...args) => {
|
|
487
|
+
const key = keyFn(...args);
|
|
488
|
+
const next = () => asyncFn(...args);
|
|
489
|
+
const queue = (queues.get(key) || Promise.resolve()).then(next, next);
|
|
490
|
+
queues.set(key, queue);
|
|
491
|
+
const cleanup = () => queues.get(key) === queue && queues.delete(key);
|
|
492
|
+
queue.then(cleanup, cleanup);
|
|
493
|
+
return queue;
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
|
|
458
497
|
// src/async/reduce.ts
|
|
459
498
|
async function reduce(array, reducer, initialValue) {
|
|
460
|
-
|
|
499
|
+
let index = 0;
|
|
461
500
|
let acc = initialValue;
|
|
462
501
|
if (acc === void 0 && arguments.length < 3) {
|
|
463
502
|
if (!array.length) {
|
|
464
503
|
throw new TypeError("Reduce of empty array with no initial value");
|
|
465
504
|
}
|
|
466
|
-
acc = array[
|
|
467
|
-
indices.next();
|
|
505
|
+
acc = array[index++];
|
|
468
506
|
}
|
|
469
|
-
|
|
470
|
-
acc = await reducer(acc, array[index], index);
|
|
507
|
+
while (index < array.length) {
|
|
508
|
+
acc = await reducer(acc, array[index], index++);
|
|
471
509
|
}
|
|
472
510
|
return acc;
|
|
473
511
|
}
|
|
474
512
|
|
|
475
513
|
// src/async/retry.ts
|
|
476
514
|
async function retry(options, func) {
|
|
477
|
-
const times =
|
|
478
|
-
const delay = options
|
|
479
|
-
const backoff =
|
|
480
|
-
const signal = options
|
|
515
|
+
const times = options?.times ?? 3;
|
|
516
|
+
const delay = options?.delay;
|
|
517
|
+
const backoff = options?.backoff ?? null;
|
|
518
|
+
const signal = options?.signal;
|
|
481
519
|
let i = 0;
|
|
482
520
|
while (true) {
|
|
483
521
|
const [err, result] = await tryit(func)((err2) => {
|
|
484
522
|
throw { _exited: err2 };
|
|
485
523
|
});
|
|
486
|
-
signal
|
|
524
|
+
signal?.throwIfAborted();
|
|
487
525
|
if (!err) {
|
|
488
526
|
return result;
|
|
489
527
|
}
|
|
@@ -507,14 +545,6 @@ function sleep(milliseconds) {
|
|
|
507
545
|
return new Promise((res) => setTimeout(res, milliseconds));
|
|
508
546
|
}
|
|
509
547
|
|
|
510
|
-
// src/async/TimeoutError.ts
|
|
511
|
-
var TimeoutError = class extends Error {
|
|
512
|
-
constructor(message) {
|
|
513
|
-
super(message ?? "Operation timed out");
|
|
514
|
-
this.name = "TimeoutError";
|
|
515
|
-
}
|
|
516
|
-
};
|
|
517
|
-
|
|
518
548
|
// src/async/timeout.ts
|
|
519
549
|
function timeout(ms, error) {
|
|
520
550
|
return new Promise(
|
|
@@ -525,6 +555,19 @@ function timeout(ms, error) {
|
|
|
525
555
|
);
|
|
526
556
|
}
|
|
527
557
|
|
|
558
|
+
// src/async/toResult.ts
|
|
559
|
+
async function toResult(promise) {
|
|
560
|
+
try {
|
|
561
|
+
const result = await promise;
|
|
562
|
+
return [void 0, result];
|
|
563
|
+
} catch (error) {
|
|
564
|
+
if (isError(error)) {
|
|
565
|
+
return [error, void 0];
|
|
566
|
+
}
|
|
567
|
+
throw error;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
528
571
|
// src/async/tryit.ts
|
|
529
572
|
function tryit(func) {
|
|
530
573
|
return (...args) => {
|
|
@@ -551,6 +594,34 @@ function withResolvers() {
|
|
|
551
594
|
return { resolve, reject, promise };
|
|
552
595
|
}
|
|
553
596
|
|
|
597
|
+
// src/async/promiseMemo.ts
|
|
598
|
+
function promiseMemo(func, options = {}) {
|
|
599
|
+
const { key: keyFunc, ttl, cache = /* @__PURE__ */ Object.create(null) } = options;
|
|
600
|
+
return function callWithMemo(...args) {
|
|
601
|
+
const key = keyFunc ? keyFunc(...args) : JSON.stringify({ args });
|
|
602
|
+
const existing = cache[key];
|
|
603
|
+
if (existing !== void 0) {
|
|
604
|
+
if (!existing.exp) {
|
|
605
|
+
return existing.value;
|
|
606
|
+
}
|
|
607
|
+
if (existing.exp > (/* @__PURE__ */ new Date()).getTime()) {
|
|
608
|
+
return existing.value;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
const promise = func(...args);
|
|
612
|
+
const entry = cache[key] = {
|
|
613
|
+
exp: ttl ? (/* @__PURE__ */ new Date()).getTime() + ttl : null,
|
|
614
|
+
value: promise
|
|
615
|
+
};
|
|
616
|
+
promise.catch(() => {
|
|
617
|
+
if (cache[key] === entry) {
|
|
618
|
+
delete cache[key];
|
|
619
|
+
}
|
|
620
|
+
});
|
|
621
|
+
return promise;
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
|
|
554
625
|
// src/curry/callable.ts
|
|
555
626
|
function callable(obj, fn) {
|
|
556
627
|
return new Proxy(Object.assign(fn.bind(null), obj), {
|
|
@@ -578,27 +649,28 @@ function compose(...funcs) {
|
|
|
578
649
|
// src/curry/debounce.ts
|
|
579
650
|
function debounce({ delay, leading }, callee) {
|
|
580
651
|
let timeout2;
|
|
581
|
-
const debounced = (...args) => {
|
|
582
|
-
clearTimeout(timeout2);
|
|
652
|
+
const debounced = ((...args) => {
|
|
583
653
|
if (leading) {
|
|
584
654
|
leading = false;
|
|
585
655
|
callee(...args);
|
|
586
656
|
} else {
|
|
657
|
+
clearTimeout(timeout2);
|
|
587
658
|
timeout2 = setTimeout(
|
|
588
659
|
debounced.flush = () => {
|
|
589
|
-
debounced.
|
|
590
|
-
clearTimeout(timeout2);
|
|
660
|
+
debounced.cancel();
|
|
591
661
|
callee(...args);
|
|
592
662
|
},
|
|
593
663
|
delay
|
|
594
664
|
);
|
|
595
665
|
}
|
|
596
|
-
};
|
|
666
|
+
});
|
|
597
667
|
debounced.callee = callee;
|
|
668
|
+
debounced.isDebounced = () => timeout2 !== void 0;
|
|
598
669
|
debounced.flush = noop;
|
|
599
670
|
debounced.cancel = () => {
|
|
600
671
|
debounced.flush = noop;
|
|
601
672
|
clearTimeout(timeout2);
|
|
673
|
+
timeout2 = void 0;
|
|
602
674
|
};
|
|
603
675
|
return debounced;
|
|
604
676
|
}
|
|
@@ -609,7 +681,8 @@ function flip(fn) {
|
|
|
609
681
|
}
|
|
610
682
|
|
|
611
683
|
// src/curry/memo.ts
|
|
612
|
-
function
|
|
684
|
+
function memo(func, options = {}) {
|
|
685
|
+
const { key: keyFunc, ttl, cache = /* @__PURE__ */ Object.create(null) } = options;
|
|
613
686
|
return function callWithMemo(...args) {
|
|
614
687
|
const key = keyFunc ? keyFunc(...args) : JSON.stringify({ args });
|
|
615
688
|
const existing = cache[key];
|
|
@@ -629,8 +702,20 @@ function memoize(cache, func, keyFunc, ttl) {
|
|
|
629
702
|
return result;
|
|
630
703
|
};
|
|
631
704
|
}
|
|
632
|
-
|
|
633
|
-
|
|
705
|
+
|
|
706
|
+
// src/curry/memoLastCall.ts
|
|
707
|
+
function memoLastCall(fn) {
|
|
708
|
+
let lastArgs = null;
|
|
709
|
+
let lastResult = null;
|
|
710
|
+
return (...args) => {
|
|
711
|
+
if (lastArgs && lastArgs.length === args.length && lastArgs.every((arg, i) => Object.is(arg, args[i]))) {
|
|
712
|
+
return lastResult;
|
|
713
|
+
}
|
|
714
|
+
const result = fn(...args);
|
|
715
|
+
lastArgs = args;
|
|
716
|
+
lastResult = result;
|
|
717
|
+
return result;
|
|
718
|
+
};
|
|
634
719
|
}
|
|
635
720
|
|
|
636
721
|
// src/curry/once.ts
|
|
@@ -662,6 +747,50 @@ function partob(fn, argObj) {
|
|
|
662
747
|
return (restObj) => fn({ ...argObj, ...restObj });
|
|
663
748
|
}
|
|
664
749
|
|
|
750
|
+
// src/curry/promiseChain.ts
|
|
751
|
+
function promiseChain(...funcs) {
|
|
752
|
+
return async (...args) => {
|
|
753
|
+
let result = await funcs[0](...args);
|
|
754
|
+
for (let i = 1; i < funcs.length; i++) {
|
|
755
|
+
result = await funcs[i](result);
|
|
756
|
+
}
|
|
757
|
+
return result;
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
// src/curry/promiseDebounce.ts
|
|
762
|
+
function promiseDebounce({ delay, leading }, callee) {
|
|
763
|
+
let timeout2;
|
|
764
|
+
const debounced = ((...args) => {
|
|
765
|
+
const promise = new Promise((resolve) => {
|
|
766
|
+
if (leading) {
|
|
767
|
+
leading = false;
|
|
768
|
+
resolve(callee(...args));
|
|
769
|
+
} else {
|
|
770
|
+
clearTimeout(timeout2);
|
|
771
|
+
timeout2 = setTimeout(
|
|
772
|
+
debounced.flush = () => {
|
|
773
|
+
debounced.cancel();
|
|
774
|
+
resolve((async () => callee(...args))());
|
|
775
|
+
return promise;
|
|
776
|
+
},
|
|
777
|
+
delay
|
|
778
|
+
);
|
|
779
|
+
}
|
|
780
|
+
});
|
|
781
|
+
return promise;
|
|
782
|
+
});
|
|
783
|
+
debounced.callee = callee;
|
|
784
|
+
debounced.isDebounced = () => timeout2 !== void 0;
|
|
785
|
+
debounced.flush = noop;
|
|
786
|
+
debounced.cancel = () => {
|
|
787
|
+
debounced.flush = noop;
|
|
788
|
+
clearTimeout(timeout2);
|
|
789
|
+
timeout2 = void 0;
|
|
790
|
+
};
|
|
791
|
+
return debounced;
|
|
792
|
+
}
|
|
793
|
+
|
|
665
794
|
// src/curry/proxied.ts
|
|
666
795
|
function proxied(handler) {
|
|
667
796
|
return new Proxy(
|
|
@@ -725,6 +854,11 @@ function castMapping(mapping) {
|
|
|
725
854
|
return isFunction(mapping) ? mapping : mapping != null ? (input) => input[mapping] : (input) => input;
|
|
726
855
|
}
|
|
727
856
|
|
|
857
|
+
// src/function/identity.ts
|
|
858
|
+
function identity(value) {
|
|
859
|
+
return value;
|
|
860
|
+
}
|
|
861
|
+
|
|
728
862
|
// src/function/noop.ts
|
|
729
863
|
function noop() {
|
|
730
864
|
}
|
|
@@ -765,22 +899,29 @@ function min(array, getter) {
|
|
|
765
899
|
return array.reduce((a, b) => get2(a) < get2(b) ? a : b);
|
|
766
900
|
}
|
|
767
901
|
|
|
902
|
+
// src/number/parseDuration.ts
|
|
903
|
+
function parseDuration(duration, options) {
|
|
904
|
+
return new DurationParser(options).parse(duration);
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
// src/number/parseQuantity.ts
|
|
908
|
+
function parseQuantity(quantity, options) {
|
|
909
|
+
return new QuantityParser(options).parse(quantity);
|
|
910
|
+
}
|
|
911
|
+
|
|
768
912
|
// src/number/range.ts
|
|
769
913
|
function* range(startOrLength, end, valueOrMapper = (i) => i, step = 1) {
|
|
770
914
|
const mapper = isFunction(valueOrMapper) ? valueOrMapper : () => valueOrMapper;
|
|
771
|
-
const start = end ? startOrLength : 0;
|
|
915
|
+
const start = end !== void 0 ? startOrLength : 0;
|
|
772
916
|
const final = end ?? startOrLength;
|
|
773
917
|
for (let i = start; i <= final; i += step) {
|
|
774
918
|
yield mapper(i);
|
|
775
|
-
if (i + step > final) {
|
|
776
|
-
break;
|
|
777
|
-
}
|
|
778
919
|
}
|
|
779
920
|
}
|
|
780
921
|
|
|
781
922
|
// src/number/round.ts
|
|
782
923
|
function round(value, precision, toInteger = Math.round) {
|
|
783
|
-
if (precision) {
|
|
924
|
+
if (precision && Number.isFinite(value)) {
|
|
784
925
|
const p = precision > 0 ? Math.min(precision, 292) : Math.max(precision, -323);
|
|
785
926
|
let [q, e] = `${value}e`.split("e");
|
|
786
927
|
[q, e] = `${toInteger(+`${q}e${+e + p}`)}e`.split("e");
|
|
@@ -811,6 +952,9 @@ function assign(initial, override) {
|
|
|
811
952
|
const proto = Object.getPrototypeOf(initial);
|
|
812
953
|
const merged = proto ? { ...initial } : Object.assign(Object.create(proto), initial);
|
|
813
954
|
for (const key of Object.keys(override)) {
|
|
955
|
+
if (isDangerousKey(key, merged)) {
|
|
956
|
+
continue;
|
|
957
|
+
}
|
|
814
958
|
merged[key] = isPlainObject(initial[key]) && isPlainObject(override[key]) ? assign(initial[key], override[key]) : override[key];
|
|
815
959
|
}
|
|
816
960
|
return merged;
|
|
@@ -819,7 +963,7 @@ function assign(initial, override) {
|
|
|
819
963
|
// src/object/clone.ts
|
|
820
964
|
function clone(obj) {
|
|
821
965
|
const proto = Object.getPrototypeOf(obj);
|
|
822
|
-
const newObj = typeof
|
|
966
|
+
const newObj = typeof proto?.constructor === "function" ? new proto.constructor() : Object.create(proto);
|
|
823
967
|
for (const key of Object.getOwnPropertyNames(obj)) {
|
|
824
968
|
newObj[key] = obj[key];
|
|
825
969
|
}
|
|
@@ -902,8 +1046,11 @@ function construct(obj) {
|
|
|
902
1046
|
|
|
903
1047
|
// src/object/crush.ts
|
|
904
1048
|
function crush(value) {
|
|
905
|
-
|
|
906
|
-
|
|
1049
|
+
if (Object.keys(value).length === 0) {
|
|
1050
|
+
return {};
|
|
1051
|
+
}
|
|
1052
|
+
return (function crushReducer(crushed, value2, path) {
|
|
1053
|
+
if ((isObject(value2) || isArray(value2)) && Object.keys(value2).length > 0) {
|
|
907
1054
|
for (const [prop, propValue] of Object.entries(value2)) {
|
|
908
1055
|
crushReducer(crushed, propValue, path ? `${path}.${prop}` : prop);
|
|
909
1056
|
}
|
|
@@ -911,12 +1058,12 @@ function crush(value) {
|
|
|
911
1058
|
crushed[path] = value2;
|
|
912
1059
|
}
|
|
913
1060
|
return crushed;
|
|
914
|
-
}({}, value, "");
|
|
1061
|
+
})({}, value, "");
|
|
915
1062
|
}
|
|
916
1063
|
|
|
917
1064
|
// src/object/filterKey.ts
|
|
918
1065
|
function filterKey(obj, key, filter) {
|
|
919
|
-
return Object.hasOwnProperty.call(obj, key) && (filter == null || (isArray(filter) ? filter.includes(key) : filter(obj[key], key, obj)));
|
|
1066
|
+
return Object.prototype.hasOwnProperty.call(obj, key) && (filter == null || (isArray(filter) ? filter.includes(key) : filter(obj[key], key, obj)));
|
|
920
1067
|
}
|
|
921
1068
|
|
|
922
1069
|
// src/object/get.ts
|
|
@@ -942,6 +1089,25 @@ function get(value, path, defaultValue) {
|
|
|
942
1089
|
return current;
|
|
943
1090
|
}
|
|
944
1091
|
|
|
1092
|
+
// src/object/getOrInsert.ts
|
|
1093
|
+
function getOrInsert(map2, key, value) {
|
|
1094
|
+
if (map2.has(key)) {
|
|
1095
|
+
return map2.get(key);
|
|
1096
|
+
}
|
|
1097
|
+
map2.set(key, value);
|
|
1098
|
+
return value;
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
// src/object/getOrInsertComputed.ts
|
|
1102
|
+
function getOrInsertComputed(map2, key, compute) {
|
|
1103
|
+
if (map2.has(key)) {
|
|
1104
|
+
return map2.get(key);
|
|
1105
|
+
}
|
|
1106
|
+
const newValue = compute();
|
|
1107
|
+
map2.set(key, newValue);
|
|
1108
|
+
return newValue;
|
|
1109
|
+
}
|
|
1110
|
+
|
|
945
1111
|
// src/object/invert.ts
|
|
946
1112
|
function invert(obj) {
|
|
947
1113
|
const keys2 = Object.keys(obj);
|
|
@@ -954,6 +1120,11 @@ function invert(obj) {
|
|
|
954
1120
|
);
|
|
955
1121
|
}
|
|
956
1122
|
|
|
1123
|
+
// src/object/isDangerousKey.ts
|
|
1124
|
+
function isDangerousKey(key, object) {
|
|
1125
|
+
return !(object && !Object.getPrototypeOf(object)) && (key === "__proto__" || key === "prototype" || key === "constructor");
|
|
1126
|
+
}
|
|
1127
|
+
|
|
957
1128
|
// src/object/keys.ts
|
|
958
1129
|
function keys(value) {
|
|
959
1130
|
const keys2 = [];
|
|
@@ -1027,6 +1198,17 @@ function mapValues(obj, mapFunc) {
|
|
|
1027
1198
|
);
|
|
1028
1199
|
}
|
|
1029
1200
|
|
|
1201
|
+
// src/object/mergeOptions.ts
|
|
1202
|
+
function mergeOptions(a, b) {
|
|
1203
|
+
if (a === void 0) {
|
|
1204
|
+
return b;
|
|
1205
|
+
}
|
|
1206
|
+
if (b === void 0) {
|
|
1207
|
+
return a;
|
|
1208
|
+
}
|
|
1209
|
+
return { ...a, ...b };
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1030
1212
|
// src/object/omit.ts
|
|
1031
1213
|
function omit(obj, keys2) {
|
|
1032
1214
|
if (keys2.length === 0) {
|
|
@@ -1059,16 +1241,24 @@ function pick(obj, filter) {
|
|
|
1059
1241
|
|
|
1060
1242
|
// src/object/set.ts
|
|
1061
1243
|
function set(initial, path, value) {
|
|
1062
|
-
if (
|
|
1244
|
+
if (path.length === 0) {
|
|
1063
1245
|
return initial;
|
|
1064
1246
|
}
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
(
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1247
|
+
return (function recurse(object, keys2, index) {
|
|
1248
|
+
const key = keys2[index];
|
|
1249
|
+
object ??= isIntString(key) ? [] : {};
|
|
1250
|
+
if (isDangerousKey(key, object)) {
|
|
1251
|
+
throw new Error("Unsafe key in path: " + key);
|
|
1252
|
+
}
|
|
1253
|
+
if (index < keys2.length - 1) {
|
|
1254
|
+
value = recurse(object[key], keys2, index + 1);
|
|
1255
|
+
}
|
|
1256
|
+
if (!Object.is(object[key], value)) {
|
|
1257
|
+
object = clone(object);
|
|
1258
|
+
object[key] = value;
|
|
1259
|
+
}
|
|
1260
|
+
return object;
|
|
1261
|
+
})(initial, path.match(/[^.[\]]+/g), 0);
|
|
1072
1262
|
}
|
|
1073
1263
|
|
|
1074
1264
|
// src/object/shake.ts
|
|
@@ -1183,6 +1373,237 @@ function upperize(obj) {
|
|
|
1183
1373
|
return mapKeys(obj, (k) => k.toUpperCase());
|
|
1184
1374
|
}
|
|
1185
1375
|
|
|
1376
|
+
// src/oop/AggregateError.ts
|
|
1377
|
+
var AggregateErrorOrPolyfill = /* @__PURE__ */ (() => {
|
|
1378
|
+
if (globalThis.AggregateError) {
|
|
1379
|
+
return globalThis.AggregateError;
|
|
1380
|
+
}
|
|
1381
|
+
function AggregateError(errors, message, options = void 0) {
|
|
1382
|
+
const error = Reflect.construct(
|
|
1383
|
+
Error,
|
|
1384
|
+
[message],
|
|
1385
|
+
new.target ?? AggregateError
|
|
1386
|
+
);
|
|
1387
|
+
if (options !== null && (typeof options === "object" || typeof options === "function") && "cause" in options) {
|
|
1388
|
+
Object.defineProperty(error, "cause", {
|
|
1389
|
+
value: options.cause,
|
|
1390
|
+
writable: true,
|
|
1391
|
+
configurable: true
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
Object.defineProperty(error, "errors", {
|
|
1395
|
+
value: [...errors],
|
|
1396
|
+
writable: true,
|
|
1397
|
+
configurable: true
|
|
1398
|
+
});
|
|
1399
|
+
return error;
|
|
1400
|
+
}
|
|
1401
|
+
Object.setPrototypeOf(AggregateError, Error);
|
|
1402
|
+
Object.setPrototypeOf(AggregateError.prototype, Error.prototype);
|
|
1403
|
+
Object.defineProperty(AggregateError, "prototype", { writable: false });
|
|
1404
|
+
Object.defineProperties(AggregateError.prototype, {
|
|
1405
|
+
name: { value: "AggregateError", writable: true, configurable: true },
|
|
1406
|
+
message: { value: "", writable: true, configurable: true }
|
|
1407
|
+
});
|
|
1408
|
+
return AggregateError;
|
|
1409
|
+
})();
|
|
1410
|
+
|
|
1411
|
+
// src/oop/QuantityParser.ts
|
|
1412
|
+
var QuantityParser = class {
|
|
1413
|
+
units;
|
|
1414
|
+
short;
|
|
1415
|
+
constructor({ units, short }) {
|
|
1416
|
+
this.units = units;
|
|
1417
|
+
this.short = short;
|
|
1418
|
+
}
|
|
1419
|
+
/**
|
|
1420
|
+
* Parse a quantity string into its numeric value
|
|
1421
|
+
*
|
|
1422
|
+
* @throws {Error} If the quantity string is invalid or contains an unknown unit
|
|
1423
|
+
*/
|
|
1424
|
+
parse(quantity) {
|
|
1425
|
+
const match = quantity.match(/^(-?\d+(?:\.\d+)?) ?(\w+)?s?$/);
|
|
1426
|
+
if (!match) {
|
|
1427
|
+
throw new Error(`Invalid quantity, cannot parse: ${quantity}`);
|
|
1428
|
+
}
|
|
1429
|
+
let unit = match[2];
|
|
1430
|
+
unit = this.short?.[unit] || unit;
|
|
1431
|
+
const count = Number.parseFloat(match[1]);
|
|
1432
|
+
if (Math.abs(count) > 1 && unit.endsWith("s")) {
|
|
1433
|
+
unit = unit.substring(0, unit.length - 1);
|
|
1434
|
+
}
|
|
1435
|
+
if (!this.units[unit]) {
|
|
1436
|
+
throw new Error(
|
|
1437
|
+
`Invalid unit: ${unit}, makes sure it is one of: ${Object.keys(this.units).join(", ")}`
|
|
1438
|
+
);
|
|
1439
|
+
}
|
|
1440
|
+
return count * this.units[unit];
|
|
1441
|
+
}
|
|
1442
|
+
};
|
|
1443
|
+
|
|
1444
|
+
// src/oop/DurationParser.ts
|
|
1445
|
+
var DURATION_UNITS = {
|
|
1446
|
+
week: 6048e5,
|
|
1447
|
+
day: 864e5,
|
|
1448
|
+
hour: 36e5,
|
|
1449
|
+
minute: 6e4,
|
|
1450
|
+
second: 1e3,
|
|
1451
|
+
millisecond: 1
|
|
1452
|
+
};
|
|
1453
|
+
var DURATION_SHORT_UNITS = {
|
|
1454
|
+
w: "week",
|
|
1455
|
+
d: "day",
|
|
1456
|
+
h: "hour",
|
|
1457
|
+
m: "minute",
|
|
1458
|
+
s: "second",
|
|
1459
|
+
ms: "millisecond"
|
|
1460
|
+
};
|
|
1461
|
+
var DurationParser = class _DurationParser extends QuantityParser {
|
|
1462
|
+
constructor(options) {
|
|
1463
|
+
super({
|
|
1464
|
+
units: {
|
|
1465
|
+
..._DurationParser.units,
|
|
1466
|
+
...options?.units
|
|
1467
|
+
},
|
|
1468
|
+
short: {
|
|
1469
|
+
..._DurationParser.shortUnits,
|
|
1470
|
+
...options?.short
|
|
1471
|
+
}
|
|
1472
|
+
});
|
|
1473
|
+
}
|
|
1474
|
+
static get units() {
|
|
1475
|
+
return DURATION_UNITS;
|
|
1476
|
+
}
|
|
1477
|
+
static get shortUnits() {
|
|
1478
|
+
return DURATION_SHORT_UNITS;
|
|
1479
|
+
}
|
|
1480
|
+
};
|
|
1481
|
+
|
|
1482
|
+
// src/oop/Semaphore.ts
|
|
1483
|
+
var SemaphorePermit = class {
|
|
1484
|
+
constructor(semaphore, request, weight) {
|
|
1485
|
+
this.semaphore = semaphore;
|
|
1486
|
+
this.request = request;
|
|
1487
|
+
this.weight = weight;
|
|
1488
|
+
}
|
|
1489
|
+
semaphore;
|
|
1490
|
+
request;
|
|
1491
|
+
weight;
|
|
1492
|
+
/**
|
|
1493
|
+
* Releases this permit back to the semaphore, allowing another
|
|
1494
|
+
* operation to acquire it.
|
|
1495
|
+
*/
|
|
1496
|
+
release() {
|
|
1497
|
+
this.semaphore.release(this);
|
|
1498
|
+
this.release = noop;
|
|
1499
|
+
}
|
|
1500
|
+
};
|
|
1501
|
+
var Semaphore = class {
|
|
1502
|
+
/**
|
|
1503
|
+
* Creates a new semaphore with the specified capacity.
|
|
1504
|
+
* @param maxCapacity Maximum number of permits that can be issued simultaneously
|
|
1505
|
+
*/
|
|
1506
|
+
constructor(maxCapacity) {
|
|
1507
|
+
this.maxCapacity = maxCapacity;
|
|
1508
|
+
if (maxCapacity <= 0) {
|
|
1509
|
+
throw new Error("maxCapacity must be > 0");
|
|
1510
|
+
}
|
|
1511
|
+
this.capacity = maxCapacity;
|
|
1512
|
+
}
|
|
1513
|
+
maxCapacity;
|
|
1514
|
+
queue = [];
|
|
1515
|
+
/**
|
|
1516
|
+
* Current number of permits available to be acquired
|
|
1517
|
+
*/
|
|
1518
|
+
capacity;
|
|
1519
|
+
/**
|
|
1520
|
+
* Number of pending acquisition requests.
|
|
1521
|
+
*/
|
|
1522
|
+
get queueLength() {
|
|
1523
|
+
return this.queue.length;
|
|
1524
|
+
}
|
|
1525
|
+
/**
|
|
1526
|
+
* Acquires a permit from this semaphore, waiting if necessary until
|
|
1527
|
+
* one becomes available.
|
|
1528
|
+
* @param options.signal - The signal to abort the acquisition
|
|
1529
|
+
* @param options.weight - The weight of the permit to acquire
|
|
1530
|
+
* @returns A promise that resolves to a permit when one is
|
|
1531
|
+
* available
|
|
1532
|
+
*/
|
|
1533
|
+
async acquire({
|
|
1534
|
+
signal,
|
|
1535
|
+
weight = 1
|
|
1536
|
+
} = {}) {
|
|
1537
|
+
if (weight <= 0) {
|
|
1538
|
+
throw new Error("weight must be > 0");
|
|
1539
|
+
}
|
|
1540
|
+
if (weight > this.maxCapacity) {
|
|
1541
|
+
throw new Error("weight must be \u2264 maxCapacity");
|
|
1542
|
+
}
|
|
1543
|
+
if (signal?.aborted) {
|
|
1544
|
+
throw signal.reason;
|
|
1545
|
+
}
|
|
1546
|
+
const request = withResolvers();
|
|
1547
|
+
const permit = new SemaphorePermit(this, request, weight);
|
|
1548
|
+
if (signal && this.capacity < weight) {
|
|
1549
|
+
const abort = () => {
|
|
1550
|
+
const index = this.queue.indexOf(permit);
|
|
1551
|
+
if (index >= 0) {
|
|
1552
|
+
this.queue.splice(index, 1);
|
|
1553
|
+
request.reject(signal.reason);
|
|
1554
|
+
}
|
|
1555
|
+
};
|
|
1556
|
+
signal.addEventListener("abort", abort);
|
|
1557
|
+
const cleanup = () => {
|
|
1558
|
+
signal.removeEventListener("abort", abort);
|
|
1559
|
+
};
|
|
1560
|
+
request.promise.then(cleanup, cleanup);
|
|
1561
|
+
}
|
|
1562
|
+
if (this.capacity < weight) {
|
|
1563
|
+
this.queue.push(permit);
|
|
1564
|
+
await request.promise;
|
|
1565
|
+
} else {
|
|
1566
|
+
this.capacity -= weight;
|
|
1567
|
+
}
|
|
1568
|
+
return permit;
|
|
1569
|
+
}
|
|
1570
|
+
/**
|
|
1571
|
+
* Rejects all pending acquisition requests.
|
|
1572
|
+
*/
|
|
1573
|
+
reject(error) {
|
|
1574
|
+
this.acquire = () => Promise.reject(error);
|
|
1575
|
+
this.queue.forEach((permit) => permit.request.reject(error));
|
|
1576
|
+
this.queue = [];
|
|
1577
|
+
}
|
|
1578
|
+
/**
|
|
1579
|
+
* Releases a permit back to the semaphore, increasing capacity and
|
|
1580
|
+
* potentially fulfilling a pending acquisition request.
|
|
1581
|
+
*/
|
|
1582
|
+
release(permit) {
|
|
1583
|
+
this.capacity += permit.weight;
|
|
1584
|
+
let nextPermit = this.queue[0];
|
|
1585
|
+
while (nextPermit && this.capacity >= nextPermit.weight) {
|
|
1586
|
+
this.capacity -= nextPermit.weight;
|
|
1587
|
+
this.queue.shift();
|
|
1588
|
+
nextPermit.request.resolve();
|
|
1589
|
+
nextPermit = this.queue[0];
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
};
|
|
1593
|
+
|
|
1594
|
+
// src/oop/TimeoutError.ts
|
|
1595
|
+
var TimeoutError = class extends Error {
|
|
1596
|
+
name = "TimeoutError";
|
|
1597
|
+
constructor(message) {
|
|
1598
|
+
super(message ?? "Operation timed out");
|
|
1599
|
+
}
|
|
1600
|
+
};
|
|
1601
|
+
|
|
1602
|
+
// src/random/absoluteJitter.ts
|
|
1603
|
+
function absoluteJitter(base, offset) {
|
|
1604
|
+
return base + offset * (2 * Math.random() - 1);
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1186
1607
|
// src/random/draw.ts
|
|
1187
1608
|
function draw(array) {
|
|
1188
1609
|
const max2 = array.length;
|
|
@@ -1193,6 +1614,11 @@ function draw(array) {
|
|
|
1193
1614
|
return array[index];
|
|
1194
1615
|
}
|
|
1195
1616
|
|
|
1617
|
+
// src/random/proportionalJitter.ts
|
|
1618
|
+
function proportionalJitter(base, factor) {
|
|
1619
|
+
return base * (1 - factor * (2 * Math.random() - 1));
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1196
1622
|
// src/random/random.ts
|
|
1197
1623
|
function random(min2, max2) {
|
|
1198
1624
|
return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
|
|
@@ -1299,16 +1725,62 @@ function dash(str) {
|
|
|
1299
1725
|
});
|
|
1300
1726
|
}
|
|
1301
1727
|
|
|
1728
|
+
// src/string/deburr.ts
|
|
1729
|
+
var DEBURR_MAP = new Map(
|
|
1730
|
+
Object.entries({
|
|
1731
|
+
\u00C6: "Ae",
|
|
1732
|
+
\u00D0: "D",
|
|
1733
|
+
\u00D8: "O",
|
|
1734
|
+
\u00DE: "Th",
|
|
1735
|
+
\u00DF: "ss",
|
|
1736
|
+
\u00E6: "ae",
|
|
1737
|
+
\u00F0: "d",
|
|
1738
|
+
\u00F8: "o",
|
|
1739
|
+
\u00FE: "th",
|
|
1740
|
+
\u0110: "D",
|
|
1741
|
+
\u0111: "d",
|
|
1742
|
+
\u0126: "H",
|
|
1743
|
+
\u0127: "h",
|
|
1744
|
+
\u0131: "i",
|
|
1745
|
+
\u0132: "IJ",
|
|
1746
|
+
\u0133: "ij",
|
|
1747
|
+
\u0138: "k",
|
|
1748
|
+
\u013F: "L",
|
|
1749
|
+
\u0140: "l",
|
|
1750
|
+
\u0141: "L",
|
|
1751
|
+
\u0142: "l",
|
|
1752
|
+
\u0149: "'n",
|
|
1753
|
+
\u014A: "N",
|
|
1754
|
+
\u014B: "n",
|
|
1755
|
+
\u0152: "Oe",
|
|
1756
|
+
\u0153: "oe",
|
|
1757
|
+
\u0166: "T",
|
|
1758
|
+
\u0167: "t",
|
|
1759
|
+
\u017F: "s"
|
|
1760
|
+
})
|
|
1761
|
+
);
|
|
1762
|
+
function deburr(input) {
|
|
1763
|
+
let result = "";
|
|
1764
|
+
const chars = input.normalize("NFD");
|
|
1765
|
+
for (let index = 0; index < chars.length; index++) {
|
|
1766
|
+
const char = chars[index];
|
|
1767
|
+
if (char >= "\u0300" && char <= "\u036F" || char >= "\uFE20" && char <= "\uFE23") {
|
|
1768
|
+
continue;
|
|
1769
|
+
}
|
|
1770
|
+
result += DEBURR_MAP.get(char) ?? char;
|
|
1771
|
+
}
|
|
1772
|
+
return result;
|
|
1773
|
+
}
|
|
1774
|
+
|
|
1302
1775
|
// src/string/dedent.ts
|
|
1776
|
+
// @__NO_SIDE_EFFECTS__
|
|
1303
1777
|
function dedent(text, ...values) {
|
|
1304
|
-
var _a;
|
|
1305
1778
|
if (isArray(text)) {
|
|
1306
1779
|
if (values.length > 0) {
|
|
1307
|
-
return dedent(
|
|
1780
|
+
return /* @__PURE__ */ dedent(
|
|
1308
1781
|
text.reduce((acc, input, i) => {
|
|
1309
|
-
var _a2;
|
|
1310
1782
|
let value = String(values[i] ?? "");
|
|
1311
|
-
const indent2 = value.includes("\n") &&
|
|
1783
|
+
const indent2 = value.includes("\n") && input.match(/[ \t]*(?=[^\n]*$)/)?.[0];
|
|
1312
1784
|
if (indent2) {
|
|
1313
1785
|
value = value.replace(/\n(?=[^\n]*?\S)/g, "\n" + indent2);
|
|
1314
1786
|
}
|
|
@@ -1318,11 +1790,24 @@ function dedent(text, ...values) {
|
|
|
1318
1790
|
}
|
|
1319
1791
|
text = text[0];
|
|
1320
1792
|
}
|
|
1321
|
-
const indent = values[0] ??
|
|
1793
|
+
const indent = values[0] ?? text.match(/^[ \t]*(?=\S)/m)?.[0];
|
|
1322
1794
|
const output = indent ? text.replace(new RegExp(`^${indent}`, "gm"), "") : text;
|
|
1323
1795
|
return output.replace(/^[ \t]*\n|\n[ \t]*$/g, "");
|
|
1324
1796
|
}
|
|
1325
1797
|
|
|
1798
|
+
// src/string/escapeHTML.ts
|
|
1799
|
+
var htmlCharacters = /[&<>"']/g;
|
|
1800
|
+
var replacements = {
|
|
1801
|
+
"&": "&",
|
|
1802
|
+
"<": "<",
|
|
1803
|
+
">": ">",
|
|
1804
|
+
'"': """,
|
|
1805
|
+
"'": "'"
|
|
1806
|
+
};
|
|
1807
|
+
function escapeHTML(input) {
|
|
1808
|
+
return input.replace(htmlCharacters, (char) => replacements[char]);
|
|
1809
|
+
}
|
|
1810
|
+
|
|
1326
1811
|
// src/string/pascal.ts
|
|
1327
1812
|
function pascal(str) {
|
|
1328
1813
|
const result = str.replace(
|
|
@@ -1391,7 +1876,7 @@ function snake(str, options) {
|
|
|
1391
1876
|
const result = parts.reduce((acc, part) => {
|
|
1392
1877
|
return `${acc}_${part.toLowerCase()}`;
|
|
1393
1878
|
});
|
|
1394
|
-
return
|
|
1879
|
+
return options?.splitOnNumber === false ? result : result.replace(/([A-Za-z]{1}[0-9]{1})/g, (val) => `${val[0]}_${val[1]}`);
|
|
1395
1880
|
}
|
|
1396
1881
|
|
|
1397
1882
|
// src/string/template.ts
|
|
@@ -1412,15 +1897,44 @@ function title(str) {
|
|
|
1412
1897
|
}
|
|
1413
1898
|
|
|
1414
1899
|
// src/string/trim.ts
|
|
1415
|
-
function trim(str, charsToTrim
|
|
1900
|
+
function trim(str, charsToTrim) {
|
|
1416
1901
|
const toTrim = charsToTrim.replace(/[\W]{1}/g, "\\$&");
|
|
1417
1902
|
const regex = new RegExp(`^[${toTrim}]+|[${toTrim}]+$`, "g");
|
|
1418
1903
|
return str.replace(regex, "");
|
|
1419
1904
|
}
|
|
1420
1905
|
|
|
1906
|
+
// src/typed/assert.ts
|
|
1907
|
+
function assert(condition, message) {
|
|
1908
|
+
if (!condition) {
|
|
1909
|
+
throw message instanceof Error ? message : new Error(message ?? "Assertion failed");
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
|
|
1913
|
+
// src/typed/getErrorMessage.ts
|
|
1914
|
+
function getErrorMessage(error) {
|
|
1915
|
+
if (error instanceof Error && error.message) {
|
|
1916
|
+
return error.message;
|
|
1917
|
+
}
|
|
1918
|
+
return typeof error === "string" && error.length > 0 ? error : "Unknown error.";
|
|
1919
|
+
}
|
|
1920
|
+
|
|
1421
1921
|
// src/typed/isArray.ts
|
|
1422
1922
|
var isArray = /* @__PURE__ */ (() => Array.isArray)();
|
|
1423
1923
|
|
|
1924
|
+
// src/typed/isAsyncIterable.ts
|
|
1925
|
+
var asyncIteratorSymbol = (
|
|
1926
|
+
/* c8 ignore next */
|
|
1927
|
+
Symbol.asyncIterator || /* @__PURE__ */ Symbol.for("Symbol.asyncIterator")
|
|
1928
|
+
);
|
|
1929
|
+
function isAsyncIterable(value) {
|
|
1930
|
+
return !!value && typeof value === "object" && typeof value[asyncIteratorSymbol] === "function";
|
|
1931
|
+
}
|
|
1932
|
+
|
|
1933
|
+
// src/typed/isBigInt.ts
|
|
1934
|
+
function isBigInt(value) {
|
|
1935
|
+
return typeof value === "bigint";
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1424
1938
|
// src/typed/isBoolean.ts
|
|
1425
1939
|
function isBoolean(value) {
|
|
1426
1940
|
return typeof value === "boolean";
|
|
@@ -1438,24 +1952,12 @@ function isDate(value) {
|
|
|
1438
1952
|
|
|
1439
1953
|
// src/typed/isEmpty.ts
|
|
1440
1954
|
function isEmpty(value) {
|
|
1441
|
-
if (value
|
|
1442
|
-
return true;
|
|
1443
|
-
}
|
|
1444
|
-
if (value === null || value === void 0) {
|
|
1445
|
-
return true;
|
|
1446
|
-
}
|
|
1447
|
-
if (isNumber(value)) {
|
|
1448
|
-
return value === 0;
|
|
1955
|
+
if (typeof value !== "object" || value === null) {
|
|
1956
|
+
return !value || value === true;
|
|
1449
1957
|
}
|
|
1450
1958
|
if (isDate(value)) {
|
|
1451
1959
|
return Number.isNaN(value.getTime());
|
|
1452
1960
|
}
|
|
1453
|
-
if (isFunction(value)) {
|
|
1454
|
-
return false;
|
|
1455
|
-
}
|
|
1456
|
-
if (isSymbol(value)) {
|
|
1457
|
-
return false;
|
|
1458
|
-
}
|
|
1459
1961
|
const length = value.length;
|
|
1460
1962
|
if (isNumber(length)) {
|
|
1461
1963
|
return length === 0;
|
|
@@ -1535,6 +2037,19 @@ function isMap(value) {
|
|
|
1535
2037
|
return isTagged(value, "[object Map]");
|
|
1536
2038
|
}
|
|
1537
2039
|
|
|
2040
|
+
// src/typed/isMapEqual.ts
|
|
2041
|
+
function isMapEqual(x, y) {
|
|
2042
|
+
if (x.size !== y.size) {
|
|
2043
|
+
return false;
|
|
2044
|
+
}
|
|
2045
|
+
for (const [key, value] of x) {
|
|
2046
|
+
if (!isEqual(value, y.get(key))) {
|
|
2047
|
+
return false;
|
|
2048
|
+
}
|
|
2049
|
+
}
|
|
2050
|
+
return true;
|
|
2051
|
+
}
|
|
2052
|
+
|
|
1538
2053
|
// src/typed/isNullish.ts
|
|
1539
2054
|
function isNullish(value) {
|
|
1540
2055
|
return value === null || value === void 0;
|
|
@@ -1599,6 +2114,19 @@ function isSet(value) {
|
|
|
1599
2114
|
return isTagged(value, "[object Set]");
|
|
1600
2115
|
}
|
|
1601
2116
|
|
|
2117
|
+
// src/typed/isSetEqual.ts
|
|
2118
|
+
function isSetEqual(x, y) {
|
|
2119
|
+
if (x.size !== y.size) {
|
|
2120
|
+
return false;
|
|
2121
|
+
}
|
|
2122
|
+
for (const item of x) {
|
|
2123
|
+
if (!y.has(item)) {
|
|
2124
|
+
return false;
|
|
2125
|
+
}
|
|
2126
|
+
}
|
|
2127
|
+
return true;
|
|
2128
|
+
}
|
|
2129
|
+
|
|
1602
2130
|
// src/typed/isString.ts
|
|
1603
2131
|
function isString(value) {
|
|
1604
2132
|
return typeof value === "string";
|
|
@@ -1631,11 +2159,17 @@ function isWeakSet(value) {
|
|
|
1631
2159
|
|
|
1632
2160
|
exports.AggregateError = AggregateErrorOrPolyfill;
|
|
1633
2161
|
exports.DefaultCloningStrategy = DefaultCloningStrategy;
|
|
2162
|
+
exports.DurationParser = DurationParser;
|
|
1634
2163
|
exports.FastCloningStrategy = FastCloningStrategy;
|
|
2164
|
+
exports.QuantityParser = QuantityParser;
|
|
2165
|
+
exports.Semaphore = Semaphore;
|
|
2166
|
+
exports.SemaphorePermit = SemaphorePermit;
|
|
1635
2167
|
exports.TimeoutError = TimeoutError;
|
|
2168
|
+
exports.absoluteJitter = absoluteJitter;
|
|
1636
2169
|
exports.all = all;
|
|
1637
2170
|
exports.alphabetical = alphabetical;
|
|
1638
2171
|
exports.always = always;
|
|
2172
|
+
exports.assert = assert;
|
|
1639
2173
|
exports.assign = assign;
|
|
1640
2174
|
exports.boil = boil;
|
|
1641
2175
|
exports.callable = callable;
|
|
@@ -1652,29 +2186,40 @@ exports.clone = clone;
|
|
|
1652
2186
|
exports.cloneDeep = cloneDeep;
|
|
1653
2187
|
exports.cluster = cluster;
|
|
1654
2188
|
exports.compose = compose;
|
|
2189
|
+
exports.concat = concat;
|
|
1655
2190
|
exports.construct = construct;
|
|
1656
2191
|
exports.counting = counting;
|
|
1657
2192
|
exports.crush = crush;
|
|
1658
2193
|
exports.dash = dash;
|
|
1659
2194
|
exports.debounce = debounce;
|
|
2195
|
+
exports.deburr = deburr;
|
|
1660
2196
|
exports.dedent = dedent;
|
|
1661
2197
|
exports.defer = defer;
|
|
1662
2198
|
exports.diff = diff;
|
|
1663
2199
|
exports.draw = draw;
|
|
2200
|
+
exports.escapeHTML = escapeHTML;
|
|
1664
2201
|
exports.filterKey = filterKey;
|
|
1665
2202
|
exports.first = first;
|
|
1666
2203
|
exports.flat = flat;
|
|
1667
2204
|
exports.flip = flip;
|
|
1668
2205
|
exports.fork = fork;
|
|
1669
2206
|
exports.get = get;
|
|
2207
|
+
exports.getErrorMessage = getErrorMessage;
|
|
2208
|
+
exports.getOrInsert = getOrInsert;
|
|
2209
|
+
exports.getOrInsertComputed = getOrInsertComputed;
|
|
1670
2210
|
exports.group = group;
|
|
1671
2211
|
exports.guard = guard;
|
|
2212
|
+
exports.identity = identity;
|
|
1672
2213
|
exports.inRange = inRange;
|
|
1673
2214
|
exports.intersects = intersects;
|
|
1674
2215
|
exports.invert = invert;
|
|
1675
2216
|
exports.isArray = isArray;
|
|
2217
|
+
exports.isArrayEqual = isArrayEqual;
|
|
2218
|
+
exports.isAsyncIterable = isAsyncIterable;
|
|
2219
|
+
exports.isBigInt = isBigInt;
|
|
1676
2220
|
exports.isBoolean = isBoolean;
|
|
1677
2221
|
exports.isClass = isClass;
|
|
2222
|
+
exports.isDangerousKey = isDangerousKey;
|
|
1678
2223
|
exports.isDate = isDate;
|
|
1679
2224
|
exports.isEmpty = isEmpty;
|
|
1680
2225
|
exports.isEqual = isEqual;
|
|
@@ -1685,6 +2230,7 @@ exports.isInt = isInt;
|
|
|
1685
2230
|
exports.isIntString = isIntString;
|
|
1686
2231
|
exports.isIterable = isIterable;
|
|
1687
2232
|
exports.isMap = isMap;
|
|
2233
|
+
exports.isMapEqual = isMapEqual;
|
|
1688
2234
|
exports.isNullish = isNullish;
|
|
1689
2235
|
exports.isNumber = isNumber;
|
|
1690
2236
|
exports.isObject = isObject;
|
|
@@ -1696,6 +2242,7 @@ exports.isResult = isResult;
|
|
|
1696
2242
|
exports.isResultErr = isResultErr;
|
|
1697
2243
|
exports.isResultOk = isResultOk;
|
|
1698
2244
|
exports.isSet = isSet;
|
|
2245
|
+
exports.isSetEqual = isSetEqual;
|
|
1699
2246
|
exports.isString = isString;
|
|
1700
2247
|
exports.isSymbol = isSymbol;
|
|
1701
2248
|
exports.isTagged = isTagged;
|
|
@@ -1716,21 +2263,32 @@ exports.mapValues = mapValues;
|
|
|
1716
2263
|
exports.mapify = mapify;
|
|
1717
2264
|
exports.max = max;
|
|
1718
2265
|
exports.memo = memo;
|
|
2266
|
+
exports.memoLastCall = memoLastCall;
|
|
1719
2267
|
exports.merge = merge;
|
|
2268
|
+
exports.mergeOptions = mergeOptions;
|
|
1720
2269
|
exports.min = min;
|
|
1721
2270
|
exports.noop = noop;
|
|
1722
2271
|
exports.objectify = objectify;
|
|
1723
2272
|
exports.omit = omit;
|
|
1724
2273
|
exports.once = once;
|
|
1725
2274
|
exports.parallel = parallel;
|
|
2275
|
+
exports.parseDuration = parseDuration;
|
|
2276
|
+
exports.parseQuantity = parseQuantity;
|
|
1726
2277
|
exports.partial = partial;
|
|
1727
2278
|
exports.partob = partob;
|
|
1728
2279
|
exports.pascal = pascal;
|
|
1729
2280
|
exports.pick = pick;
|
|
2281
|
+
exports.pluck = pluck;
|
|
2282
|
+
exports.promiseChain = promiseChain;
|
|
2283
|
+
exports.promiseDebounce = promiseDebounce;
|
|
2284
|
+
exports.promiseMemo = promiseMemo;
|
|
2285
|
+
exports.proportionalJitter = proportionalJitter;
|
|
1730
2286
|
exports.proxied = proxied;
|
|
2287
|
+
exports.queueByKey = queueByKey;
|
|
1731
2288
|
exports.random = random;
|
|
1732
2289
|
exports.range = range;
|
|
1733
2290
|
exports.reduce = reduce;
|
|
2291
|
+
exports.remove = remove;
|
|
1734
2292
|
exports.replace = replace;
|
|
1735
2293
|
exports.replaceOrAppend = replaceOrAppend;
|
|
1736
2294
|
exports.retry = retry;
|
|
@@ -1754,6 +2312,7 @@ exports.timeout = timeout;
|
|
|
1754
2312
|
exports.title = title;
|
|
1755
2313
|
exports.toFloat = toFloat;
|
|
1756
2314
|
exports.toInt = toInt;
|
|
2315
|
+
exports.toResult = toResult;
|
|
1757
2316
|
exports.toggle = toggle;
|
|
1758
2317
|
exports.traverse = traverse;
|
|
1759
2318
|
exports.trim = trim;
|