@web-ts-toolkit/utils 0.43.0 → 0.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +138 -7
- package/index.d.mts +398 -8
- package/index.d.ts +398 -8
- package/index.js +352 -82
- package/index.mjs +351 -82
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -3,11 +3,24 @@ function addLeadingSlash(value) {
|
|
|
3
3
|
return value.startsWith("/") ? value : `/${value}`;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
+
// src/dictionary.ts
|
|
7
|
+
function defineOwnDataProperty(target, key, value) {
|
|
8
|
+
Object.defineProperty(target, key, {
|
|
9
|
+
value,
|
|
10
|
+
writable: true,
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function hasOwnDataProperty(target, key) {
|
|
16
|
+
return Object.prototype.hasOwnProperty.call(target, key);
|
|
17
|
+
}
|
|
18
|
+
|
|
6
19
|
// src/arrayToRecord.ts
|
|
7
20
|
function arrayToRecord(arr) {
|
|
8
21
|
const obj = {};
|
|
9
22
|
for (let x = 0; x < arr.length; x++) {
|
|
10
|
-
obj
|
|
23
|
+
defineOwnDataProperty(obj, arr[x], true);
|
|
11
24
|
}
|
|
12
25
|
return obj;
|
|
13
26
|
}
|
|
@@ -36,10 +49,16 @@ function isPlainObject(value) {
|
|
|
36
49
|
return prototype === null || prototype === Object.prototype;
|
|
37
50
|
}
|
|
38
51
|
function normalizePathPart(part) {
|
|
39
|
-
|
|
40
|
-
|
|
52
|
+
return part;
|
|
53
|
+
}
|
|
54
|
+
function isArrayIndexKey(key) {
|
|
55
|
+
if (typeof key === "number") {
|
|
56
|
+
return Number.isInteger(key) && key >= 0 && key < 4294967295;
|
|
57
|
+
}
|
|
58
|
+
if (!/^(0|[1-9]\d*)$/.test(key)) {
|
|
59
|
+
return false;
|
|
41
60
|
}
|
|
42
|
-
return
|
|
61
|
+
return Number(key) < 4294967295;
|
|
43
62
|
}
|
|
44
63
|
function toPath(path) {
|
|
45
64
|
if (Array.isArray(path)) {
|
|
@@ -57,6 +76,17 @@ function toPath(path) {
|
|
|
57
76
|
});
|
|
58
77
|
return result.length > 0 ? result : [input];
|
|
59
78
|
}
|
|
79
|
+
function hasOwnKey(target, key) {
|
|
80
|
+
return Object.prototype.hasOwnProperty.call(target, key);
|
|
81
|
+
}
|
|
82
|
+
function defineOwnValue(target, key, value) {
|
|
83
|
+
Object.defineProperty(target, key, {
|
|
84
|
+
value,
|
|
85
|
+
writable: true,
|
|
86
|
+
enumerable: true,
|
|
87
|
+
configurable: true
|
|
88
|
+
});
|
|
89
|
+
}
|
|
60
90
|
function hasUnsafePathPart(parts) {
|
|
61
91
|
for (let index = 0; index < parts.length; index++) {
|
|
62
92
|
const part = parts[index];
|
|
@@ -107,13 +137,16 @@ function setPath(target, path, value) {
|
|
|
107
137
|
for (let index = 0; index < parts.length - 1; index++) {
|
|
108
138
|
const key = parts[index];
|
|
109
139
|
const nextKey = parts[index + 1];
|
|
110
|
-
const existing = current[key];
|
|
140
|
+
const existing = hasOwnKey(current, key) ? current[key] : void 0;
|
|
111
141
|
if (!isObject(existing)) {
|
|
112
|
-
|
|
142
|
+
const container = isArrayIndexKey(nextKey) ? [] : {};
|
|
143
|
+
defineOwnValue(current, key, container);
|
|
144
|
+
current = container;
|
|
145
|
+
} else {
|
|
146
|
+
current = existing;
|
|
113
147
|
}
|
|
114
|
-
current = current[key];
|
|
115
148
|
}
|
|
116
|
-
current
|
|
149
|
+
defineOwnValue(current, parts[parts.length - 1], value);
|
|
117
150
|
return target;
|
|
118
151
|
}
|
|
119
152
|
function deletePath(target, path) {
|
|
@@ -127,6 +160,9 @@ function deletePath(target, path) {
|
|
|
127
160
|
let current = target;
|
|
128
161
|
for (let index = 0; index < parts.length - 1; index++) {
|
|
129
162
|
const key = parts[index];
|
|
163
|
+
if (!hasOwnKey(current, key)) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
130
166
|
const nextValue = current[key];
|
|
131
167
|
if (!isObject(nextValue)) {
|
|
132
168
|
return;
|
|
@@ -138,19 +174,14 @@ function deletePath(target, path) {
|
|
|
138
174
|
function sameValueZero(left, right) {
|
|
139
175
|
return left === right || left !== left && right !== right;
|
|
140
176
|
}
|
|
141
|
-
function arrayIncludes(array, value) {
|
|
142
|
-
for (let index = 0; index < array.length; index++) {
|
|
143
|
-
if (sameValueZero(array[index], value)) {
|
|
144
|
-
return true;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
177
|
function baseUniq(array) {
|
|
178
|
+
const seen = /* @__PURE__ */ new Set();
|
|
150
179
|
const result = [];
|
|
151
180
|
for (let index = 0; index < array.length; index++) {
|
|
152
|
-
|
|
153
|
-
|
|
181
|
+
const value = array[index];
|
|
182
|
+
if (!seen.has(value)) {
|
|
183
|
+
seen.add(value);
|
|
184
|
+
result.push(value);
|
|
154
185
|
}
|
|
155
186
|
}
|
|
156
187
|
return result;
|
|
@@ -205,14 +236,29 @@ function compareAscending(left, right) {
|
|
|
205
236
|
return leftString > rightString ? 1 : -1;
|
|
206
237
|
}
|
|
207
238
|
function cloneValue(value) {
|
|
208
|
-
if (
|
|
209
|
-
|
|
210
|
-
return structuredClone(value);
|
|
211
|
-
} catch {
|
|
212
|
-
}
|
|
239
|
+
if (isExoticRoot(value)) {
|
|
240
|
+
throw exoticTypeError(value);
|
|
213
241
|
}
|
|
214
|
-
|
|
215
|
-
|
|
242
|
+
return cloneInner(value, /* @__PURE__ */ new Map());
|
|
243
|
+
}
|
|
244
|
+
function isExoticRoot(value) {
|
|
245
|
+
if (value === null || typeof value !== "object") {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
if (value instanceof Date || value instanceof RegExp || Array.isArray(value)) {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
return !isPlainObject(value) && !isInheritedPlainLike(value);
|
|
252
|
+
}
|
|
253
|
+
function exoticTypeError(value) {
|
|
254
|
+
const name = typeof value.constructor?.name === "string" && value.constructor.name.length > 0 ? value.constructor.name : typeof value;
|
|
255
|
+
return new TypeError(
|
|
256
|
+
`cloneDeep: unsupported value of type ${name}; only plain objects, arrays, Date, and RegExp can be cloned`
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
function cloneInner(value, seen) {
|
|
260
|
+
if (value === null || typeof value !== "object") {
|
|
261
|
+
return value;
|
|
216
262
|
}
|
|
217
263
|
if (value instanceof Date) {
|
|
218
264
|
return new Date(value.getTime());
|
|
@@ -220,55 +266,205 @@ function cloneValue(value) {
|
|
|
220
266
|
if (value instanceof RegExp) {
|
|
221
267
|
return new RegExp(value.source, value.flags);
|
|
222
268
|
}
|
|
223
|
-
if (
|
|
224
|
-
|
|
225
|
-
|
|
269
|
+
if (Array.isArray(value)) {
|
|
270
|
+
if (seen.has(value)) {
|
|
271
|
+
return seen.get(value);
|
|
272
|
+
}
|
|
273
|
+
const result = [];
|
|
274
|
+
seen.set(value, result);
|
|
275
|
+
for (let index = 0; index < value.length; index++) {
|
|
276
|
+
if (hasOwnKey(value, index)) {
|
|
277
|
+
defineOwnValue(result, index, cloneInner(value[index], seen));
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
copyOwnEnumerableExtras(value, result, seen);
|
|
281
|
+
return result;
|
|
282
|
+
}
|
|
283
|
+
if (isPlainObject(value) || isInheritedPlainLike(value)) {
|
|
284
|
+
if (seen.has(value)) {
|
|
285
|
+
return seen.get(value);
|
|
286
|
+
}
|
|
287
|
+
const source = value;
|
|
288
|
+
const prototype = Object.getPrototypeOf(source);
|
|
289
|
+
const result = Object.create(prototype);
|
|
290
|
+
seen.set(source, result);
|
|
291
|
+
const keys2 = ownEnumerableKeys(source);
|
|
226
292
|
for (let index = 0; index < keys2.length; index++) {
|
|
227
293
|
const key = keys2[index];
|
|
228
|
-
|
|
294
|
+
const child = source[key];
|
|
295
|
+
defineOwnValue(result, key, cloneInner(child, seen));
|
|
229
296
|
}
|
|
230
297
|
return result;
|
|
231
298
|
}
|
|
232
299
|
return value;
|
|
233
300
|
}
|
|
301
|
+
function isInheritedPlainLike(value) {
|
|
302
|
+
let current = value;
|
|
303
|
+
while (current !== null) {
|
|
304
|
+
const prototype = Object.getPrototypeOf(current);
|
|
305
|
+
if (prototype === null || prototype === Object.prototype) {
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
const constructor = prototype.constructor;
|
|
309
|
+
if (constructor !== void 0 && constructor !== Object) {
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
current = prototype;
|
|
313
|
+
}
|
|
314
|
+
return true;
|
|
315
|
+
}
|
|
316
|
+
function ownEnumerableKeys(source) {
|
|
317
|
+
const keys2 = Object.keys(source);
|
|
318
|
+
const symbols = Object.getOwnPropertySymbols(source);
|
|
319
|
+
for (let index = 0; index < symbols.length; index++) {
|
|
320
|
+
if (Object.prototype.propertyIsEnumerable.call(source, symbols[index])) {
|
|
321
|
+
keys2.push(symbols[index]);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return keys2;
|
|
325
|
+
}
|
|
326
|
+
function copyOwnEnumerableExtras(source, target, seen) {
|
|
327
|
+
const keys2 = ownEnumerableKeys(source);
|
|
328
|
+
for (let index = 0; index < keys2.length; index++) {
|
|
329
|
+
const key = keys2[index];
|
|
330
|
+
if (typeof key === "string" && /^(0|[1-9]\d*)$/.test(key)) {
|
|
331
|
+
const numeric = Number(key);
|
|
332
|
+
if (Number.isInteger(numeric) && numeric >= 0 && numeric < source.length) {
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (hasOwnKey(target, key)) {
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
defineOwnValue(target, key, cloneInner(source[key], seen));
|
|
340
|
+
}
|
|
341
|
+
}
|
|
234
342
|
function deepEqual(left, right) {
|
|
343
|
+
return deepEqualInner(left, right, /* @__PURE__ */ new Map());
|
|
344
|
+
}
|
|
345
|
+
function pairsHas(pairs, left, right) {
|
|
346
|
+
return pairs.get(left)?.has(right) ?? false;
|
|
347
|
+
}
|
|
348
|
+
function pairsAdd(pairs, left, right) {
|
|
349
|
+
let set2 = pairs.get(left);
|
|
350
|
+
if (set2 === void 0) {
|
|
351
|
+
set2 = /* @__PURE__ */ new Set();
|
|
352
|
+
pairs.set(left, set2);
|
|
353
|
+
}
|
|
354
|
+
set2.add(right);
|
|
355
|
+
}
|
|
356
|
+
function pairsDelete(pairs, left, right) {
|
|
357
|
+
const set2 = pairs.get(left);
|
|
358
|
+
if (set2 === void 0) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
set2.delete(right);
|
|
362
|
+
if (set2.size === 0) {
|
|
363
|
+
pairs.delete(left);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
function isComparableObject(value) {
|
|
367
|
+
return typeof value === "object" && value !== null && (isPlainObject(value) || isInheritedPlainLike(value));
|
|
368
|
+
}
|
|
369
|
+
function isExtraArrayKey(key, length) {
|
|
370
|
+
if (typeof key === "symbol") {
|
|
371
|
+
return true;
|
|
372
|
+
}
|
|
373
|
+
if (/^(0|[1-9]\d*)$/.test(key)) {
|
|
374
|
+
const numeric = Number(key);
|
|
375
|
+
if (Number.isInteger(numeric) && numeric >= 0 && numeric < length) {
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return true;
|
|
380
|
+
}
|
|
381
|
+
function deepEqualInner(left, right, pairs) {
|
|
235
382
|
if (sameValueZero(left, right)) {
|
|
236
383
|
return true;
|
|
237
384
|
}
|
|
238
|
-
if (left instanceof Date
|
|
239
|
-
return left.getTime()
|
|
385
|
+
if (left instanceof Date || right instanceof Date) {
|
|
386
|
+
return left instanceof Date && right instanceof Date && sameValueZero(left.getTime(), right.getTime());
|
|
240
387
|
}
|
|
241
|
-
if (left instanceof RegExp
|
|
242
|
-
return left.source === right.source && left.flags === right.flags;
|
|
388
|
+
if (left instanceof RegExp || right instanceof RegExp) {
|
|
389
|
+
return left instanceof RegExp && right instanceof RegExp && left.source === right.source && left.flags === right.flags;
|
|
243
390
|
}
|
|
244
391
|
if (Array.isArray(left) || Array.isArray(right)) {
|
|
245
392
|
if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) {
|
|
246
393
|
return false;
|
|
247
394
|
}
|
|
248
|
-
|
|
249
|
-
|
|
395
|
+
if (pairsHas(pairs, left, right)) {
|
|
396
|
+
return true;
|
|
397
|
+
}
|
|
398
|
+
pairsAdd(pairs, left, right);
|
|
399
|
+
try {
|
|
400
|
+
for (let index = 0; index < left.length; index++) {
|
|
401
|
+
const leftHas = hasOwnKey(left, index);
|
|
402
|
+
const rightHas = hasOwnKey(right, index);
|
|
403
|
+
if (leftHas !== rightHas) {
|
|
404
|
+
return false;
|
|
405
|
+
}
|
|
406
|
+
if (leftHas && !deepEqualInner(left[index], right[index], pairs)) {
|
|
407
|
+
return false;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
const leftExtras = ownEnumerableKeys(left).filter((key) => isExtraArrayKey(key, left.length));
|
|
411
|
+
const rightExtras = ownEnumerableKeys(right).filter((key) => isExtraArrayKey(key, right.length));
|
|
412
|
+
if (leftExtras.length !== rightExtras.length) {
|
|
250
413
|
return false;
|
|
251
414
|
}
|
|
415
|
+
for (let index = 0; index < leftExtras.length; index++) {
|
|
416
|
+
const key = leftExtras[index];
|
|
417
|
+
if (!hasOwnKey(right, key)) {
|
|
418
|
+
return false;
|
|
419
|
+
}
|
|
420
|
+
if (!deepEqualInner(
|
|
421
|
+
left[key],
|
|
422
|
+
right[key],
|
|
423
|
+
pairs
|
|
424
|
+
)) {
|
|
425
|
+
return false;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return true;
|
|
429
|
+
} finally {
|
|
430
|
+
pairsDelete(pairs, left, right);
|
|
252
431
|
}
|
|
253
|
-
return true;
|
|
254
432
|
}
|
|
255
|
-
if (!
|
|
433
|
+
if (!isComparableObject(left) || !isComparableObject(right)) {
|
|
256
434
|
return false;
|
|
257
435
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
if (leftKeys.length !== rightKeys.length) {
|
|
261
|
-
return false;
|
|
436
|
+
if (pairsHas(pairs, left, right)) {
|
|
437
|
+
return true;
|
|
262
438
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
439
|
+
pairsAdd(pairs, left, right);
|
|
440
|
+
try {
|
|
441
|
+
const leftKeys = ownEnumerableKeys(left);
|
|
442
|
+
const rightKeys = ownEnumerableKeys(right);
|
|
443
|
+
if (leftKeys.length !== rightKeys.length) {
|
|
266
444
|
return false;
|
|
267
445
|
}
|
|
446
|
+
for (let index = 0; index < leftKeys.length; index++) {
|
|
447
|
+
const key = leftKeys[index];
|
|
448
|
+
if (!hasOwnKey(right, key)) {
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
if (!deepEqualInner(
|
|
452
|
+
left[key],
|
|
453
|
+
right[key],
|
|
454
|
+
pairs
|
|
455
|
+
)) {
|
|
456
|
+
return false;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return true;
|
|
460
|
+
} finally {
|
|
461
|
+
pairsDelete(pairs, left, right);
|
|
268
462
|
}
|
|
269
|
-
return true;
|
|
270
463
|
}
|
|
271
464
|
function partialMatch(object, source) {
|
|
465
|
+
return partialMatchInner(object, source, /* @__PURE__ */ new Map());
|
|
466
|
+
}
|
|
467
|
+
function partialMatchInner(object, source, pairs) {
|
|
272
468
|
if (sameValueZero(object, source)) {
|
|
273
469
|
return true;
|
|
274
470
|
}
|
|
@@ -276,27 +472,70 @@ function partialMatch(object, source) {
|
|
|
276
472
|
if (!Array.isArray(object) || object.length < source.length) {
|
|
277
473
|
return false;
|
|
278
474
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
475
|
+
if (pairsHas(pairs, source, object)) {
|
|
476
|
+
return true;
|
|
477
|
+
}
|
|
478
|
+
pairsAdd(pairs, source, object);
|
|
479
|
+
try {
|
|
480
|
+
for (let index = 0; index < source.length; index++) {
|
|
481
|
+
if (!hasOwnKey(source, index)) {
|
|
482
|
+
continue;
|
|
483
|
+
}
|
|
484
|
+
if (!hasOwnKey(object, index)) {
|
|
485
|
+
return false;
|
|
486
|
+
}
|
|
487
|
+
if (!partialMatchInner(object[index], source[index], pairs)) {
|
|
488
|
+
return false;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
const sourceExtras = ownEnumerableKeys(source).filter((key) => isExtraArrayKey(key, source.length));
|
|
492
|
+
for (let index = 0; index < sourceExtras.length; index++) {
|
|
493
|
+
const key = sourceExtras[index];
|
|
494
|
+
if (!hasOwnKey(object, key)) {
|
|
495
|
+
return false;
|
|
496
|
+
}
|
|
497
|
+
if (!partialMatchInner(
|
|
498
|
+
object[key],
|
|
499
|
+
source[key],
|
|
500
|
+
pairs
|
|
501
|
+
)) {
|
|
502
|
+
return false;
|
|
503
|
+
}
|
|
282
504
|
}
|
|
505
|
+
return true;
|
|
506
|
+
} finally {
|
|
507
|
+
pairsDelete(pairs, source, object);
|
|
283
508
|
}
|
|
284
|
-
return true;
|
|
285
509
|
}
|
|
286
|
-
if (isPlainObject(source)) {
|
|
510
|
+
if (isPlainObject(source) || typeof source === "object" && source !== null && isInheritedPlainLike(source)) {
|
|
287
511
|
if (!isObject(object)) {
|
|
288
512
|
return false;
|
|
289
513
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
514
|
+
if (pairsHas(pairs, source, object)) {
|
|
515
|
+
return true;
|
|
516
|
+
}
|
|
517
|
+
pairsAdd(pairs, source, object);
|
|
518
|
+
try {
|
|
519
|
+
const keys2 = ownEnumerableKeys(source);
|
|
520
|
+
for (let index = 0; index < keys2.length; index++) {
|
|
521
|
+
const key = keys2[index];
|
|
522
|
+
if (!hasOwnKey(object, key)) {
|
|
523
|
+
return false;
|
|
524
|
+
}
|
|
525
|
+
if (!partialMatchInner(
|
|
526
|
+
object[key],
|
|
527
|
+
source[key],
|
|
528
|
+
pairs
|
|
529
|
+
)) {
|
|
530
|
+
return false;
|
|
531
|
+
}
|
|
295
532
|
}
|
|
533
|
+
return true;
|
|
534
|
+
} finally {
|
|
535
|
+
pairsDelete(pairs, source, object);
|
|
296
536
|
}
|
|
297
|
-
return true;
|
|
298
537
|
}
|
|
299
|
-
return
|
|
538
|
+
return deepEqualInner(object, source, pairs);
|
|
300
539
|
}
|
|
301
540
|
|
|
302
541
|
// src/cloneDeep.ts
|
|
@@ -318,7 +557,8 @@ function difference(array, ...values) {
|
|
|
318
557
|
return [];
|
|
319
558
|
}
|
|
320
559
|
const excluded = values.flatMap((value) => Array.isArray(value) ? value : []);
|
|
321
|
-
|
|
560
|
+
const excludedSet = new Set(excluded);
|
|
561
|
+
return array.filter((item) => !excludedSet.has(item));
|
|
322
562
|
}
|
|
323
563
|
|
|
324
564
|
// src/eachRight.ts
|
|
@@ -419,10 +659,23 @@ function flattenDeep(array) {
|
|
|
419
659
|
return [];
|
|
420
660
|
}
|
|
421
661
|
const result = [];
|
|
422
|
-
|
|
423
|
-
|
|
662
|
+
const stack = [{ values: array, index: 0 }];
|
|
663
|
+
const ancestors = /* @__PURE__ */ new Set([array]);
|
|
664
|
+
while (stack.length > 0) {
|
|
665
|
+
const frame = stack[stack.length - 1];
|
|
666
|
+
if (frame.index >= frame.values.length) {
|
|
667
|
+
stack.pop();
|
|
668
|
+
ancestors.delete(frame.values);
|
|
669
|
+
continue;
|
|
670
|
+
}
|
|
671
|
+
const value = frame.values[frame.index];
|
|
672
|
+
frame.index += 1;
|
|
424
673
|
if (Array.isArray(value)) {
|
|
425
|
-
|
|
674
|
+
if (ancestors.has(value)) {
|
|
675
|
+
throw new TypeError("flattenDeep: cyclic array reference is not supported");
|
|
676
|
+
}
|
|
677
|
+
ancestors.add(value);
|
|
678
|
+
stack.push({ values: value, index: 0 });
|
|
426
679
|
} else {
|
|
427
680
|
result.push(value);
|
|
428
681
|
}
|
|
@@ -470,7 +723,12 @@ function groupBy(collection, iteratee) {
|
|
|
470
723
|
for (let index = 0; index < collection.length; index++) {
|
|
471
724
|
const value = collection[index];
|
|
472
725
|
const key = String(callback(value, index, collection));
|
|
473
|
-
(result[key]
|
|
726
|
+
let bucket = hasOwnDataProperty(result, key) ? result[key] : void 0;
|
|
727
|
+
if (bucket === void 0) {
|
|
728
|
+
bucket = [];
|
|
729
|
+
defineOwnDataProperty(result, key, bucket);
|
|
730
|
+
}
|
|
731
|
+
bucket.push(value);
|
|
474
732
|
}
|
|
475
733
|
return result;
|
|
476
734
|
}
|
|
@@ -479,7 +737,12 @@ function groupBy(collection, iteratee) {
|
|
|
479
737
|
const key = keys2[index];
|
|
480
738
|
const value = collection[key];
|
|
481
739
|
const group = String(callback(value, key, collection));
|
|
482
|
-
(result[group]
|
|
740
|
+
let bucket = hasOwnDataProperty(result, group) ? result[group] : void 0;
|
|
741
|
+
if (bucket === void 0) {
|
|
742
|
+
bucket = [];
|
|
743
|
+
defineOwnDataProperty(result, group, bucket);
|
|
744
|
+
}
|
|
745
|
+
bucket.push(value);
|
|
483
746
|
}
|
|
484
747
|
return result;
|
|
485
748
|
}
|
|
@@ -499,7 +762,8 @@ function intersection(...arrays) {
|
|
|
499
762
|
return [];
|
|
500
763
|
}
|
|
501
764
|
const uniqueValues = baseUniq(first);
|
|
502
|
-
|
|
765
|
+
const restSets = rest.map((array) => Array.isArray(array) ? new Set(array) : null);
|
|
766
|
+
return uniqueValues.filter((value) => restSets.every((set2) => set2 !== null && set2.has(value)));
|
|
503
767
|
}
|
|
504
768
|
|
|
505
769
|
// src/intersectionBy.ts
|
|
@@ -514,17 +778,16 @@ function intersectionBy(...args) {
|
|
|
514
778
|
}
|
|
515
779
|
const [first, ...rest] = sources;
|
|
516
780
|
const result = [];
|
|
517
|
-
const seen =
|
|
781
|
+
const seen = /* @__PURE__ */ new Set();
|
|
782
|
+
const restSets = rest.map((array) => new Set(array.map((value) => callback(value))));
|
|
518
783
|
for (let index = 0; index < first.length; index++) {
|
|
519
784
|
const item = first[index];
|
|
520
785
|
const computed = callback(item);
|
|
521
|
-
if (seen.
|
|
786
|
+
if (seen.has(computed)) {
|
|
522
787
|
continue;
|
|
523
788
|
}
|
|
524
|
-
if (
|
|
525
|
-
|
|
526
|
-
)) {
|
|
527
|
-
seen.push(computed);
|
|
789
|
+
if (restSets.every((set2) => set2.has(computed))) {
|
|
790
|
+
seen.add(computed);
|
|
528
791
|
result.push(item);
|
|
529
792
|
}
|
|
530
793
|
}
|
|
@@ -538,7 +801,7 @@ function isArray(value) {
|
|
|
538
801
|
|
|
539
802
|
// src/isBoolean.ts
|
|
540
803
|
function isBoolean(value) {
|
|
541
|
-
return
|
|
804
|
+
return typeof value === "boolean";
|
|
542
805
|
}
|
|
543
806
|
|
|
544
807
|
// src/isEmpty.ts
|
|
@@ -588,7 +851,7 @@ function isNil(value) {
|
|
|
588
851
|
|
|
589
852
|
// src/isNumber.ts
|
|
590
853
|
function isNumber(value) {
|
|
591
|
-
return typeof value === "number"
|
|
854
|
+
return typeof value === "number";
|
|
592
855
|
}
|
|
593
856
|
|
|
594
857
|
// src/isObject.ts
|
|
@@ -608,7 +871,7 @@ function isPromise(value) {
|
|
|
608
871
|
|
|
609
872
|
// src/isString.ts
|
|
610
873
|
function isString(value) {
|
|
611
|
-
return typeof value === "string"
|
|
874
|
+
return typeof value === "string";
|
|
612
875
|
}
|
|
613
876
|
|
|
614
877
|
// src/isUndefined.ts
|
|
@@ -662,7 +925,8 @@ function mapKeys(object, iteratee) {
|
|
|
662
925
|
const keys2 = Object.keys(object);
|
|
663
926
|
for (let index = 0; index < keys2.length; index++) {
|
|
664
927
|
const key = keys2[index];
|
|
665
|
-
|
|
928
|
+
const mappedKey = String(iteratee(object[key], key, object));
|
|
929
|
+
defineOwnDataProperty(result, mappedKey, object[key]);
|
|
666
930
|
}
|
|
667
931
|
return result;
|
|
668
932
|
}
|
|
@@ -676,7 +940,7 @@ function mapValues(object, iteratee) {
|
|
|
676
940
|
const keys2 = Object.keys(object);
|
|
677
941
|
for (let index = 0; index < keys2.length; index++) {
|
|
678
942
|
const key = keys2[index];
|
|
679
|
-
result
|
|
943
|
+
defineOwnDataProperty(result, key, iteratee(object[key], key, object));
|
|
680
944
|
}
|
|
681
945
|
return result;
|
|
682
946
|
}
|
|
@@ -700,6 +964,9 @@ function omit(object, paths) {
|
|
|
700
964
|
return {};
|
|
701
965
|
}
|
|
702
966
|
const result = cloneDeep(object);
|
|
967
|
+
if (result === object) {
|
|
968
|
+
throw new TypeError("omit: unsupported object type; input cannot be cloned without aliasing");
|
|
969
|
+
}
|
|
703
970
|
const pathList = Array.isArray(paths) ? paths : [paths];
|
|
704
971
|
for (let index = 0; index < pathList.length; index++) {
|
|
705
972
|
deletePath(result, pathList[index]);
|
|
@@ -718,7 +985,7 @@ function omitBy(object, predicate) {
|
|
|
718
985
|
const key = keys2[index];
|
|
719
986
|
const value = object[key];
|
|
720
987
|
if (!predicate(value, key, object)) {
|
|
721
|
-
result
|
|
988
|
+
defineOwnDataProperty(result, key, value);
|
|
722
989
|
}
|
|
723
990
|
}
|
|
724
991
|
return result;
|
|
@@ -734,7 +1001,9 @@ function orderBy(collection, iteratees = [], orders = []) {
|
|
|
734
1001
|
if (!Array.isArray(collection)) {
|
|
735
1002
|
return [];
|
|
736
1003
|
}
|
|
737
|
-
const callbacks = (iteratees.length > 0 ? iteratees : [void 0]).map(
|
|
1004
|
+
const callbacks = (iteratees.length > 0 ? iteratees : [void 0]).map(
|
|
1005
|
+
(iteratee) => getIteratee(iteratee)
|
|
1006
|
+
);
|
|
738
1007
|
return [...collection].map((value, index) => ({ value, index })).sort((left, right) => {
|
|
739
1008
|
for (let index = 0; index < callbacks.length; index++) {
|
|
740
1009
|
const callback = callbacks[index];
|
|
@@ -780,7 +1049,7 @@ function pickBy(object, predicate) {
|
|
|
780
1049
|
const key = keys2[index];
|
|
781
1050
|
const value = object[key];
|
|
782
1051
|
if (predicate(value, key, object)) {
|
|
783
|
-
result
|
|
1052
|
+
defineOwnDataProperty(result, key, value);
|
|
784
1053
|
}
|
|
785
1054
|
}
|
|
786
1055
|
return result;
|
|
@@ -886,7 +1155,7 @@ function toStringRecord(value) {
|
|
|
886
1155
|
const entries = Object.entries(value);
|
|
887
1156
|
for (let index = 0; index < entries.length; index++) {
|
|
888
1157
|
const [key, entryValue] = entries[index];
|
|
889
|
-
result
|
|
1158
|
+
defineOwnDataProperty(result, key, String(entryValue));
|
|
890
1159
|
}
|
|
891
1160
|
return entries.length > 0 ? result : void 0;
|
|
892
1161
|
}
|
|
@@ -906,14 +1175,14 @@ function uniqBy(array, iteratee) {
|
|
|
906
1175
|
}
|
|
907
1176
|
const callback = getIteratee(iteratee);
|
|
908
1177
|
const result = [];
|
|
909
|
-
const seen =
|
|
1178
|
+
const seen = /* @__PURE__ */ new Set();
|
|
910
1179
|
for (let index = 0; index < array.length; index++) {
|
|
911
1180
|
const value = array[index];
|
|
912
1181
|
const computed = callback(value, index, array);
|
|
913
|
-
if (seen.
|
|
1182
|
+
if (seen.has(computed)) {
|
|
914
1183
|
continue;
|
|
915
1184
|
}
|
|
916
|
-
seen.
|
|
1185
|
+
seen.add(computed);
|
|
917
1186
|
result.push(value);
|
|
918
1187
|
}
|
|
919
1188
|
return result;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@web-ts-toolkit/utils",
|
|
3
3
|
"description": "Shared collection, object, async, and URL helpers used across workspace packages",
|
|
4
4
|
"homepage": "https://web-ts-toolkit.pages.dev/docs/packages/utils",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.44.0",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"keywords": [
|
|
8
8
|
"utilities",
|