@oscarpalmer/atoms 0.180.0 → 0.181.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/dist/array/find.d.mts +42 -1
- package/dist/array/find.mjs +5 -1
- package/dist/array/get.mjs +2 -2
- package/dist/array/index.d.mts +3 -3
- package/dist/array/index.mjs +3 -3
- package/dist/index.d.mts +126 -25
- package/dist/index.mjs +50 -13
- package/dist/internal/array/find.d.mts +4 -3
- package/dist/internal/array/find.mjs +5 -2
- package/dist/internal/array/index-of.d.mts +42 -1
- package/dist/internal/array/index-of.mjs +5 -1
- package/dist/internal/math/aggregate.mjs +2 -2
- package/dist/internal/result.mjs +2 -2
- package/dist/internal/string.d.mts +5 -3
- package/dist/internal/string.mjs +14 -5
- package/dist/internal/value/equal.mjs +2 -2
- package/dist/internal/value/handlers.mjs +2 -2
- package/dist/value/index.d.mts +2 -1
- package/dist/value/index.mjs +2 -1
- package/dist/value/merge.d.mts +13 -0
- package/dist/value/merge.mjs +3 -1
- package/dist/value/shake.d.mts +7 -0
- package/dist/value/shake.mjs +16 -0
- package/package.json +1 -1
- package/src/array/exists.ts +1 -1
- package/src/array/find.ts +58 -0
- package/src/array/get.ts +2 -2
- package/src/internal/array/find.ts +24 -4
- package/src/internal/array/index-of.ts +59 -1
- package/src/internal/math/aggregate.ts +2 -2
- package/src/internal/result.ts +6 -3
- package/src/internal/string.ts +26 -8
- package/src/internal/value/equal.ts +2 -2
- package/src/internal/value/handlers.ts +2 -2
- package/src/value/index.ts +1 -0
- package/src/value/merge.ts +17 -1
- package/src/value/shake.ts +36 -0
package/dist/array/find.d.mts
CHANGED
|
@@ -31,5 +31,46 @@ declare function find<Item>(array: Item[], filter: (item: Item, index: number, a
|
|
|
31
31
|
* @returns First item that matches the value, or `undefined` if no match is found
|
|
32
32
|
*/
|
|
33
33
|
declare function find<Item>(array: Item[], value: Item): Item | undefined;
|
|
34
|
+
declare namespace find {
|
|
35
|
+
var last: typeof findLast;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get the last item matching the given value
|
|
39
|
+
*
|
|
40
|
+
* Available as `findLast` and `find.last`
|
|
41
|
+
* @param array Array to search in
|
|
42
|
+
* @param callback Callback to get an item's value for matching
|
|
43
|
+
* @param value Value to match against
|
|
44
|
+
* @returns Last item that matches the value, or `undefined` if no match is found
|
|
45
|
+
*/
|
|
46
|
+
declare function findLast<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Get the last item matching the given value by key
|
|
49
|
+
*
|
|
50
|
+
* Available as `findLast` and `find.last`
|
|
51
|
+
* @param array Array to search in
|
|
52
|
+
* @param key Key to get an item's value for matching
|
|
53
|
+
* @param value Value to match against
|
|
54
|
+
* @returns Last item that matches the value, or `undefined` if no match is found
|
|
55
|
+
*/
|
|
56
|
+
declare function findLast<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Get the last item matching the filter
|
|
59
|
+
*
|
|
60
|
+
* Available as `findLast` and `find.last`
|
|
61
|
+
* @param array Array to search in
|
|
62
|
+
* @param filter Filter callback to match items
|
|
63
|
+
* @returns Last item that matches the filter, or `undefined` if no match is found
|
|
64
|
+
*/
|
|
65
|
+
declare function findLast<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Get the last item matching the given value
|
|
68
|
+
*
|
|
69
|
+
* Available as `findLast` and `find.last`
|
|
70
|
+
* @param array Array to search in
|
|
71
|
+
* @param value Value to match against
|
|
72
|
+
* @returns Last item that matches the value, or `undefined` if no match is found
|
|
73
|
+
*/
|
|
74
|
+
declare function findLast<Item>(array: Item[], value: Item): Item | undefined;
|
|
34
75
|
//#endregion
|
|
35
|
-
export { find };
|
|
76
|
+
export { find, findLast };
|
package/dist/array/find.mjs
CHANGED
|
@@ -3,5 +3,9 @@ import { FIND_VALUE_ITEM, findValue } from "../internal/array/find.mjs";
|
|
|
3
3
|
function find(array, ...parameters) {
|
|
4
4
|
return findValue(FIND_VALUE_ITEM, array, parameters, false);
|
|
5
5
|
}
|
|
6
|
+
find.last = findLast;
|
|
7
|
+
function findLast(array, ...parameters) {
|
|
8
|
+
return findValue(FIND_VALUE_ITEM, array, parameters, true);
|
|
9
|
+
}
|
|
6
10
|
//#endregion
|
|
7
|
-
export { find };
|
|
11
|
+
export { find, findLast };
|
package/dist/array/get.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isNonPlainObject } from "../internal/is.mjs";
|
|
2
2
|
//#region src/array/get.ts
|
|
3
3
|
function getArray(value, indiced) {
|
|
4
4
|
if (Array.isArray(value)) return value;
|
|
5
5
|
if (value instanceof Map || value instanceof Set) return [...value.values()];
|
|
6
|
-
if (
|
|
6
|
+
if (isNonPlainObject(value)) return [value];
|
|
7
7
|
if (indiced !== true) return Object.values(value);
|
|
8
8
|
const keys = Object.keys(value);
|
|
9
9
|
const { length } = keys;
|
package/dist/array/index.d.mts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { difference } from "./difference.mjs";
|
|
2
2
|
import { exists } from "./exists.mjs";
|
|
3
|
-
import { find } from "./find.mjs";
|
|
3
|
+
import { find, findLast } from "./find.mjs";
|
|
4
4
|
import { flatten } from "./flatten.mjs";
|
|
5
5
|
import { range, times } from "./from.mjs";
|
|
6
6
|
import { getArray } from "./get.mjs";
|
|
7
7
|
import { chunk } from "../internal/array/chunk.mjs";
|
|
8
8
|
import { compact } from "../internal/array/compact.mjs";
|
|
9
|
-
import { indexOf } from "../internal/array/index-of.mjs";
|
|
9
|
+
import { indexOf, lastIndexOf } from "../internal/array/index-of.mjs";
|
|
10
10
|
import { shuffle } from "../internal/array/shuffle.mjs";
|
|
11
11
|
import { insert } from "./insert.mjs";
|
|
12
12
|
import { intersection } from "./intersection.mjs";
|
|
@@ -23,4 +23,4 @@ import { toggle } from "./toggle.mjs";
|
|
|
23
23
|
import { union } from "./union.mjs";
|
|
24
24
|
import { unique } from "./unique.mjs";
|
|
25
25
|
import { update } from "./update.mjs";
|
|
26
|
-
export { ArrayPosition, chunk, compact, difference, drop, endsWithArray, exists, find, flatten, getArray, getArrayPosition, includesArray, indexOf, indexOfArray, insert, intersection, partition, push, range, reverse, select, shuffle, single, slice, splice, startsWithArray, take, times, toSet, toggle, union, unique, update };
|
|
26
|
+
export { ArrayPosition, chunk, compact, difference, drop, endsWithArray, exists, find, findLast, flatten, getArray, getArrayPosition, includesArray, indexOf, indexOfArray, insert, intersection, lastIndexOf, partition, push, range, reverse, select, shuffle, single, slice, splice, startsWithArray, take, times, toSet, toggle, union, unique, update };
|
package/dist/array/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { chunk } from "../internal/array/chunk.mjs";
|
|
2
2
|
import { compact } from "../internal/array/compact.mjs";
|
|
3
|
-
import { indexOf } from "../internal/array/index-of.mjs";
|
|
3
|
+
import { indexOf, lastIndexOf } from "../internal/array/index-of.mjs";
|
|
4
4
|
import { shuffle } from "../internal/array/shuffle.mjs";
|
|
5
5
|
import { difference } from "./difference.mjs";
|
|
6
6
|
import { exists } from "./exists.mjs";
|
|
7
|
-
import { find } from "./find.mjs";
|
|
7
|
+
import { find, findLast } from "./find.mjs";
|
|
8
8
|
import { flatten } from "./flatten.mjs";
|
|
9
9
|
import { range, times } from "./from.mjs";
|
|
10
10
|
import { getArray } from "./get.mjs";
|
|
@@ -23,4 +23,4 @@ import { toggle } from "./toggle.mjs";
|
|
|
23
23
|
import { union } from "./union.mjs";
|
|
24
24
|
import { unique } from "./unique.mjs";
|
|
25
25
|
import { update } from "./update.mjs";
|
|
26
|
-
export { chunk, compact, difference, drop, endsWithArray, exists, find, flatten, getArray, getArrayPosition, includesArray, indexOf, indexOfArray, insert, intersection, partition, push, range, reverse, select, shuffle, single, slice, splice, startsWithArray, take, times, toSet, toggle, union, unique, update };
|
|
26
|
+
export { chunk, compact, difference, drop, endsWithArray, exists, find, findLast, flatten, getArray, getArrayPosition, includesArray, indexOf, indexOfArray, insert, intersection, lastIndexOf, partition, push, range, reverse, select, shuffle, single, slice, splice, startsWithArray, take, times, toSet, toggle, union, unique, update };
|
package/dist/index.d.mts
CHANGED
|
@@ -49,7 +49,7 @@ type GenericCallback = (...args: any[]) => any;
|
|
|
49
49
|
/**
|
|
50
50
|
* A generic key type
|
|
51
51
|
*/
|
|
52
|
-
type Key = number | string;
|
|
52
|
+
type Key$1 = number | string;
|
|
53
53
|
type KeyedValue<Item, ItemKey extends keyof Item> = Item[ItemKey] extends PropertyKey ? Item[ItemKey] : never;
|
|
54
54
|
/**
|
|
55
55
|
* A nested array
|
|
@@ -303,7 +303,7 @@ declare function firstOrDefault<Item>(array: Item[], defaultValue: Item): Item;
|
|
|
303
303
|
* @param value Callback to get an item's value
|
|
304
304
|
* @returns Record of keyed values
|
|
305
305
|
*/
|
|
306
|
-
declare function groupBy<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Simplify<Record<ReturnType<KeyCallback>, ReturnType<ValueCallback>>>;
|
|
306
|
+
declare function groupBy<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key$1, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Simplify<Record<ReturnType<KeyCallback>, ReturnType<ValueCallback>>>;
|
|
307
307
|
/**
|
|
308
308
|
* Create a record from an array of items using a specific key and value
|
|
309
309
|
*
|
|
@@ -313,7 +313,7 @@ declare function groupBy<Item, KeyCallback extends (item: Item, index: number, a
|
|
|
313
313
|
* @param value Key to use for value
|
|
314
314
|
* @returns Record of keyed values
|
|
315
315
|
*/
|
|
316
|
-
declare function groupBy<Item extends PlainObject, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: KeyCallback, value: ItemValue): Record<ReturnType<KeyCallback>, Item[ItemValue]>;
|
|
316
|
+
declare function groupBy<Item extends PlainObject, KeyCallback extends (item: Item, index: number, array: Item[]) => Key$1, ItemValue extends keyof Item>(array: Item[], key: KeyCallback, value: ItemValue): Record<ReturnType<KeyCallback>, Item[ItemValue]>;
|
|
317
317
|
/**
|
|
318
318
|
* Create a record from an array of items using a specific key and value
|
|
319
319
|
*
|
|
@@ -342,7 +342,7 @@ declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item, I
|
|
|
342
342
|
* @param callback Callback to get an item's grouping key
|
|
343
343
|
* @returns Record of keyed items
|
|
344
344
|
*/
|
|
345
|
-
declare function groupBy<Item, Callback extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], callback: Callback): Record<ReturnType<Callback>, Item>;
|
|
345
|
+
declare function groupBy<Item, Callback extends (item: Item, index: number, array: Item[]) => Key$1>(array: Item[], callback: Callback): Record<ReturnType<Callback>, Item>;
|
|
346
346
|
/**
|
|
347
347
|
* Create a record from an array of items using a specific key
|
|
348
348
|
*
|
|
@@ -370,7 +370,7 @@ declare namespace groupBy {
|
|
|
370
370
|
* @param value Callback to get an item's value
|
|
371
371
|
* @returns Record of keyed values
|
|
372
372
|
*/
|
|
373
|
-
declare function groupArraysBy<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Record<ReturnType<KeyCallback>, ReturnType<ValueCallback>[]>;
|
|
373
|
+
declare function groupArraysBy<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key$1, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Record<ReturnType<KeyCallback>, ReturnType<ValueCallback>[]>;
|
|
374
374
|
/**
|
|
375
375
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
376
376
|
*
|
|
@@ -380,7 +380,7 @@ declare function groupArraysBy<Item, KeyCallback extends (item: Item, index: num
|
|
|
380
380
|
* @param value Key to use for value
|
|
381
381
|
* @returns Record of keyed values
|
|
382
382
|
*/
|
|
383
|
-
declare function groupArraysBy<Item extends PlainObject, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: KeyCallback, value: ItemValue): Record<ReturnType<KeyCallback>, Item[ItemValue][]>;
|
|
383
|
+
declare function groupArraysBy<Item extends PlainObject, KeyCallback extends (item: Item, index: number, array: Item[]) => Key$1, ItemValue extends keyof Item>(array: Item[], key: KeyCallback, value: ItemValue): Record<ReturnType<KeyCallback>, Item[ItemValue][]>;
|
|
384
384
|
/**
|
|
385
385
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
386
386
|
*
|
|
@@ -409,7 +409,7 @@ declare function groupArraysBy<Item extends PlainObject, ItemKey extends keyof I
|
|
|
409
409
|
* @param callback Callback to get an item's grouping key
|
|
410
410
|
* @returns Record of keyed items
|
|
411
411
|
*/
|
|
412
|
-
declare function groupArraysBy<Item, Callback extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], callback: Callback): Record<ReturnType<Callback>, Item[]>;
|
|
412
|
+
declare function groupArraysBy<Item, Callback extends (item: Item, index: number, array: Item[]) => Key$1>(array: Item[], callback: Callback): Record<ReturnType<Callback>, Item[]>;
|
|
413
413
|
/**
|
|
414
414
|
* Create a record from an array of items using a specific key, grouping items into arrays
|
|
415
415
|
*
|
|
@@ -475,6 +475,47 @@ declare function indexOf<Item>(array: Item[], filter: (item: Item, index: number
|
|
|
475
475
|
* @returns Index of the first matching item, or `-1` if no match is found
|
|
476
476
|
*/
|
|
477
477
|
declare function indexOf<Item>(array: Item[], item: Item): number;
|
|
478
|
+
declare namespace indexOf {
|
|
479
|
+
var last: typeof lastIndexOf;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Get the index of the last matching item by callback
|
|
483
|
+
*
|
|
484
|
+
* Available as `lastIndexOf` and `indexOf.last`
|
|
485
|
+
* @param array Array to search in
|
|
486
|
+
* @param callback Callback to get an item's value
|
|
487
|
+
* @param value Value to match against
|
|
488
|
+
* @returns Index of the last matching item, or `-1` if no match is found
|
|
489
|
+
*/
|
|
490
|
+
declare function lastIndexOf<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): number;
|
|
491
|
+
/**
|
|
492
|
+
* Get the index of the last matching item by key
|
|
493
|
+
*
|
|
494
|
+
* Available as `lastIndexOf` and `indexOf.last`
|
|
495
|
+
* @param array Array to search in
|
|
496
|
+
* @param key Key to match items by
|
|
497
|
+
* @param value Value to match against
|
|
498
|
+
* @returns Index of the last matching item, or `-1` if no match is found
|
|
499
|
+
*/
|
|
500
|
+
declare function lastIndexOf<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): number;
|
|
501
|
+
/**
|
|
502
|
+
* Get the index of the last item matching the filter
|
|
503
|
+
*
|
|
504
|
+
* Available as `lastIndexOf` and `indexOf.last`
|
|
505
|
+
* @param array Array to search in
|
|
506
|
+
* @param filter Filter callback to match items
|
|
507
|
+
* @returns Index of the last matching item, or `-1` if no match is found
|
|
508
|
+
*/
|
|
509
|
+
declare function lastIndexOf<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): number;
|
|
510
|
+
/**
|
|
511
|
+
* Get the index of the last item matching the given item
|
|
512
|
+
*
|
|
513
|
+
* Available as `lastIndexOf` and `indexOf.last`
|
|
514
|
+
* @param array Array to search in
|
|
515
|
+
* @param item Item to match against
|
|
516
|
+
* @returns Index of the last matching item, or `-1` if no match is found
|
|
517
|
+
*/
|
|
518
|
+
declare function lastIndexOf<Item>(array: Item[], item: Item): number;
|
|
478
519
|
//#endregion
|
|
479
520
|
//#region src/internal/array/shuffle.d.ts
|
|
480
521
|
/**
|
|
@@ -572,6 +613,47 @@ declare function find<Item>(array: Item[], filter: (item: Item, index: number, a
|
|
|
572
613
|
* @returns First item that matches the value, or `undefined` if no match is found
|
|
573
614
|
*/
|
|
574
615
|
declare function find<Item>(array: Item[], value: Item): Item | undefined;
|
|
616
|
+
declare namespace find {
|
|
617
|
+
var last: typeof findLast;
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Get the last item matching the given value
|
|
621
|
+
*
|
|
622
|
+
* Available as `findLast` and `find.last`
|
|
623
|
+
* @param array Array to search in
|
|
624
|
+
* @param callback Callback to get an item's value for matching
|
|
625
|
+
* @param value Value to match against
|
|
626
|
+
* @returns Last item that matches the value, or `undefined` if no match is found
|
|
627
|
+
*/
|
|
628
|
+
declare function findLast<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item | undefined;
|
|
629
|
+
/**
|
|
630
|
+
* Get the last item matching the given value by key
|
|
631
|
+
*
|
|
632
|
+
* Available as `findLast` and `find.last`
|
|
633
|
+
* @param array Array to search in
|
|
634
|
+
* @param key Key to get an item's value for matching
|
|
635
|
+
* @param value Value to match against
|
|
636
|
+
* @returns Last item that matches the value, or `undefined` if no match is found
|
|
637
|
+
*/
|
|
638
|
+
declare function findLast<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
|
|
639
|
+
/**
|
|
640
|
+
* Get the last item matching the filter
|
|
641
|
+
*
|
|
642
|
+
* Available as `findLast` and `find.last`
|
|
643
|
+
* @param array Array to search in
|
|
644
|
+
* @param filter Filter callback to match items
|
|
645
|
+
* @returns Last item that matches the filter, or `undefined` if no match is found
|
|
646
|
+
*/
|
|
647
|
+
declare function findLast<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item | undefined;
|
|
648
|
+
/**
|
|
649
|
+
* Get the last item matching the given value
|
|
650
|
+
*
|
|
651
|
+
* Available as `findLast` and `find.last`
|
|
652
|
+
* @param array Array to search in
|
|
653
|
+
* @param value Value to match against
|
|
654
|
+
* @returns Last item that matches the value, or `undefined` if no match is found
|
|
655
|
+
*/
|
|
656
|
+
declare function findLast<Item>(array: Item[], value: Item): Item | undefined;
|
|
575
657
|
//#endregion
|
|
576
658
|
//#region src/array/flatten.d.ts
|
|
577
659
|
/**
|
|
@@ -1685,7 +1767,7 @@ declare function swapIndices<Item>(array: Item[], first: number, second: number)
|
|
|
1685
1767
|
* @param value Callback to get an item's value
|
|
1686
1768
|
* @returns Map of keyed values
|
|
1687
1769
|
*/
|
|
1688
|
-
declare function toMap<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Map<ReturnType<KeyCallback>, ReturnType<ValueCallback>>;
|
|
1770
|
+
declare function toMap<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key$1, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Map<ReturnType<KeyCallback>, ReturnType<ValueCallback>>;
|
|
1689
1771
|
/**
|
|
1690
1772
|
* Create a Map from an array of items using a callback and value
|
|
1691
1773
|
*
|
|
@@ -1695,7 +1777,7 @@ declare function toMap<Item, KeyCallback extends (item: Item, index: number, arr
|
|
|
1695
1777
|
* @param value Key to use for value
|
|
1696
1778
|
* @returns Map of keyed values
|
|
1697
1779
|
*/
|
|
1698
|
-
declare function toMap<Item extends PlainObject, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: KeyCallback, value: ItemValue): Map<ReturnType<KeyCallback>, Item[ItemValue]>;
|
|
1780
|
+
declare function toMap<Item extends PlainObject, KeyCallback extends (item: Item, index: number, array: Item[]) => Key$1, ItemValue extends keyof Item>(array: Item[], key: KeyCallback, value: ItemValue): Map<ReturnType<KeyCallback>, Item[ItemValue]>;
|
|
1699
1781
|
/**
|
|
1700
1782
|
* Create a Map from an array of items using a key and callback
|
|
1701
1783
|
*
|
|
@@ -1724,7 +1806,7 @@ declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, Ite
|
|
|
1724
1806
|
* @param callback Callback to get an item's grouping key
|
|
1725
1807
|
* @returns Map of keyed items
|
|
1726
1808
|
*/
|
|
1727
|
-
declare function toMap<Item, Callback extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], callback: Callback): Map<ReturnType<Callback>, Item>;
|
|
1809
|
+
declare function toMap<Item, Callback extends (item: Item, index: number, array: Item[]) => Key$1>(array: Item[], callback: Callback): Map<ReturnType<Callback>, Item>;
|
|
1728
1810
|
/**
|
|
1729
1811
|
* Create a Map from an array of items using a key
|
|
1730
1812
|
*
|
|
@@ -1752,7 +1834,7 @@ declare namespace toMap {
|
|
|
1752
1834
|
* @param value Callback to get an item's value
|
|
1753
1835
|
* @returns Map of keyed arrays of values
|
|
1754
1836
|
*/
|
|
1755
|
-
declare function toMapArrays<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Map<ReturnType<KeyCallback>, ReturnType<ValueCallback>[]>;
|
|
1837
|
+
declare function toMapArrays<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key$1, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Map<ReturnType<KeyCallback>, ReturnType<ValueCallback>[]>;
|
|
1756
1838
|
/**
|
|
1757
1839
|
* Create a Map from an array of items using a callback and value, grouping values into arrays
|
|
1758
1840
|
*
|
|
@@ -1762,7 +1844,7 @@ declare function toMapArrays<Item, KeyCallback extends (item: Item, index: numbe
|
|
|
1762
1844
|
* @param value Key to use for value
|
|
1763
1845
|
* @returns Map of keyed arrays of values
|
|
1764
1846
|
*/
|
|
1765
|
-
declare function toMapArrays<Item extends PlainObject, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: KeyCallback, value: ItemValue): Map<ReturnType<KeyCallback>, Item[ItemValue][]>;
|
|
1847
|
+
declare function toMapArrays<Item extends PlainObject, KeyCallback extends (item: Item, index: number, array: Item[]) => Key$1, ItemValue extends keyof Item>(array: Item[], key: KeyCallback, value: ItemValue): Map<ReturnType<KeyCallback>, Item[ItemValue][]>;
|
|
1766
1848
|
/**
|
|
1767
1849
|
* Create a Map from an array of items using a key and callback, grouping values into arrays
|
|
1768
1850
|
*
|
|
@@ -1791,7 +1873,7 @@ declare function toMapArrays<Item extends PlainObject, ItemKey extends keyof Ite
|
|
|
1791
1873
|
* @param callback Callback to get an item's grouping key
|
|
1792
1874
|
* @returns Map of keyed arrays of items
|
|
1793
1875
|
*/
|
|
1794
|
-
declare function toMapArrays<Item, Callback extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], callback: Callback): Map<ReturnType<Callback>, Item[]>;
|
|
1876
|
+
declare function toMapArrays<Item, Callback extends (item: Item, index: number, array: Item[]) => Key$1>(array: Item[], callback: Callback): Map<ReturnType<Callback>, Item[]>;
|
|
1795
1877
|
/**
|
|
1796
1878
|
* Create a Map from an array of items using a key, grouping items into arrays
|
|
1797
1879
|
*
|
|
@@ -1812,7 +1894,7 @@ declare function toMapArrays<Item extends PlainObject, ItemKey extends keyof Ite
|
|
|
1812
1894
|
* @param value Callback to get an item's value
|
|
1813
1895
|
* @returns Record of keyed values
|
|
1814
1896
|
*/
|
|
1815
|
-
declare function toRecord<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Record<ReturnType<KeyCallback>, ReturnType<ValueCallback>>;
|
|
1897
|
+
declare function toRecord<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key$1, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Record<ReturnType<KeyCallback>, ReturnType<ValueCallback>>;
|
|
1816
1898
|
/**
|
|
1817
1899
|
* Create a record from an array of items using a callback and value
|
|
1818
1900
|
*
|
|
@@ -1822,7 +1904,7 @@ declare function toRecord<Item, KeyCallback extends (item: Item, index: number,
|
|
|
1822
1904
|
* @param value Key to use for value
|
|
1823
1905
|
* @returns Record with keys
|
|
1824
1906
|
*/
|
|
1825
|
-
declare function toRecord<Item extends PlainObject, Callback extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], callback: Callback, value: ItemValue): Record<ReturnType<Callback>, Item[ItemValue]>;
|
|
1907
|
+
declare function toRecord<Item extends PlainObject, Callback extends (item: Item, index: number, array: Item[]) => Key$1, ItemValue extends keyof Item>(array: Item[], callback: Callback, value: ItemValue): Record<ReturnType<Callback>, Item[ItemValue]>;
|
|
1826
1908
|
/**
|
|
1827
1909
|
* Create a record from an array of items using a key and callback
|
|
1828
1910
|
*
|
|
@@ -1851,7 +1933,7 @@ declare function toRecord<Item extends PlainObject, ItemKey extends keyof Item,
|
|
|
1851
1933
|
* @param callback Callback to get an item's grouping key
|
|
1852
1934
|
* @returns Record of keyed values
|
|
1853
1935
|
*/
|
|
1854
|
-
declare function toRecord<Item, Callback extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], callback: Callback): Record<ReturnType<Callback>, Item>;
|
|
1936
|
+
declare function toRecord<Item, Callback extends (item: Item, index: number, array: Item[]) => Key$1>(array: Item[], callback: Callback): Record<ReturnType<Callback>, Item>;
|
|
1855
1937
|
/**
|
|
1856
1938
|
* Create a record from an array of items using a key
|
|
1857
1939
|
*
|
|
@@ -1879,7 +1961,7 @@ declare namespace toRecord {
|
|
|
1879
1961
|
* @param value Callback to get an item's value
|
|
1880
1962
|
* @returns Record of keyed arrays of values
|
|
1881
1963
|
*/
|
|
1882
|
-
declare function toRecordArrays<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Record<ReturnType<KeyCallback>, ReturnType<ValueCallback>[]>;
|
|
1964
|
+
declare function toRecordArrays<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key$1, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Record<ReturnType<KeyCallback>, ReturnType<ValueCallback>[]>;
|
|
1883
1965
|
/**
|
|
1884
1966
|
* Create a record from an array of items using a callback and value, grouping values into arrays
|
|
1885
1967
|
*
|
|
@@ -1889,7 +1971,7 @@ declare function toRecordArrays<Item, KeyCallback extends (item: Item, index: nu
|
|
|
1889
1971
|
* @param value Key to use for value
|
|
1890
1972
|
* @returns Record of keyed arrays of values
|
|
1891
1973
|
*/
|
|
1892
|
-
declare function toRecordArrays<Item extends PlainObject, Callback extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], callback: Callback, value: ItemValue): Record<ReturnType<Callback>, Item[ItemValue][]>;
|
|
1974
|
+
declare function toRecordArrays<Item extends PlainObject, Callback extends (item: Item, index: number, array: Item[]) => Key$1, ItemValue extends keyof Item>(array: Item[], callback: Callback, value: ItemValue): Record<ReturnType<Callback>, Item[ItemValue][]>;
|
|
1893
1975
|
/**
|
|
1894
1976
|
* Create a record from an array of items using a key and callback, grouping values into arrays
|
|
1895
1977
|
*
|
|
@@ -1918,7 +2000,7 @@ declare function toRecordArrays<Item extends PlainObject, ItemKey extends keyof
|
|
|
1918
2000
|
* @param callback Callback to get an item's grouping key
|
|
1919
2001
|
* @returns Record of keyed arrays of items
|
|
1920
2002
|
*/
|
|
1921
|
-
declare function toRecordArrays<Item, Callback extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], callback: Callback): Record<ReturnType<Callback>, Item[]>;
|
|
2003
|
+
declare function toRecordArrays<Item, Callback extends (item: Item, index: number, array: Item[]) => Key$1>(array: Item[], callback: Callback): Record<ReturnType<Callback>, Item[]>;
|
|
1922
2004
|
/**
|
|
1923
2005
|
* Create a record from an array of items using a key, grouping items into arrays
|
|
1924
2006
|
*
|
|
@@ -2564,12 +2646,14 @@ declare namespace pipe {
|
|
|
2564
2646
|
declare function getString(value: unknown): string;
|
|
2565
2647
|
declare function ignoreKey(key: string): boolean;
|
|
2566
2648
|
/**
|
|
2567
|
-
* Join an array of values into a string
|
|
2568
|
-
*
|
|
2649
|
+
* Join an array of values into a string _(while ignoring empty values)_
|
|
2650
|
+
*
|
|
2651
|
+
* _(`null`, `undefined`, and any values that become whitespace-only strings are considered empty)_
|
|
2652
|
+
* @param array Array of values
|
|
2569
2653
|
* @param delimiter Delimiter to use between values
|
|
2570
2654
|
* @returns Joined string
|
|
2571
2655
|
*/
|
|
2572
|
-
declare function join(
|
|
2656
|
+
declare function join(array: unknown[], delimiter?: string): string;
|
|
2573
2657
|
declare function tryDecode(value: string): string;
|
|
2574
2658
|
declare function tryEncode(value: boolean | number | string): unknown;
|
|
2575
2659
|
/**
|
|
@@ -3182,6 +3266,10 @@ declare function omit<Value extends PlainObject, ValueKey extends keyof Value>(v
|
|
|
3182
3266
|
*/
|
|
3183
3267
|
declare function pick<Value extends PlainObject, ValueKey extends keyof Value>(value: Value, keys: ValueKey[]): Pick<Value, ValueKey>;
|
|
3184
3268
|
//#endregion
|
|
3269
|
+
//#region src/value/shake.d.ts
|
|
3270
|
+
type Shaken<Value extends PlainObject> = { [Key in keyof Value]: Value[Key] extends undefined ? never : Value[Key] };
|
|
3271
|
+
declare function shake<Value extends PlainObject>(value: Value): Shaken<Value>;
|
|
3272
|
+
//#endregion
|
|
3185
3273
|
//#region src/value/smush.d.ts
|
|
3186
3274
|
type Smushed<Value extends PlainObject> = Simplify<{ [NestedKey in NestedKeys<Value>]: NestedValue<Value, ToString<NestedKey>> }>;
|
|
3187
3275
|
/**
|
|
@@ -3213,16 +3301,29 @@ declare function unsmush<Value extends PlainObject>(value: Value): Unsmushed<Val
|
|
|
3213
3301
|
* Options for merging values
|
|
3214
3302
|
*/
|
|
3215
3303
|
type MergeOptions = {
|
|
3304
|
+
/**
|
|
3305
|
+
* Assign values to the first array or object instead of creating a new one?
|
|
3306
|
+
*/
|
|
3307
|
+
assignValues?: boolean;
|
|
3216
3308
|
/**
|
|
3217
3309
|
* Key _(or key epxressions)_ for values that should be replaced
|
|
3310
|
+
*
|
|
3218
3311
|
* ```ts
|
|
3219
3312
|
* merge([{items: [1, 2, 3]}, {items: [99]}]); // {items: [99]}
|
|
3220
3313
|
* ```
|
|
3221
3314
|
*/
|
|
3222
3315
|
replaceableObjects?: string | RegExp | Array<string | RegExp>;
|
|
3316
|
+
/**
|
|
3317
|
+
* Skip nullable values when merging objects?
|
|
3318
|
+
*
|
|
3319
|
+
* ```ts
|
|
3320
|
+
* merge({a: 1, b: 2}, {b: null, c: 3}, {d: null}); // {a: 1, b: 2, c: 3}
|
|
3321
|
+
* ```
|
|
3322
|
+
*/
|
|
3223
3323
|
skipNullableAny?: boolean;
|
|
3224
3324
|
/**
|
|
3225
3325
|
* Skip nullable values when merging arrays?
|
|
3326
|
+
*
|
|
3226
3327
|
* ```ts
|
|
3227
3328
|
* merge([1, 2, 3], [null, null, 99]); // [1, 2, 99]
|
|
3228
3329
|
* ```
|
|
@@ -3645,7 +3746,7 @@ declare function isInstanceOf<Instance>(constructor: Constructor<Instance>, valu
|
|
|
3645
3746
|
* @param value Value to check
|
|
3646
3747
|
* @returns `true` if the value is a `Key` _(`number` or `string`)_, otherwise `false`
|
|
3647
3748
|
*/
|
|
3648
|
-
declare function isKey(value: unknown): value is Key;
|
|
3749
|
+
declare function isKey(value: unknown): value is Key$1;
|
|
3649
3750
|
/**
|
|
3650
3751
|
* Is the value not an array or a plain object?
|
|
3651
3752
|
* @param value Value to check
|
|
@@ -3670,7 +3771,7 @@ declare function isNonInstanceOf<Instance, Value>(constructor: Constructor<Insta
|
|
|
3670
3771
|
* @param value Value to check
|
|
3671
3772
|
* @returns `true` if the value is not a `Key` _(`number` or `string`)_, otherwise `false`
|
|
3672
3773
|
*/
|
|
3673
|
-
declare function isNonKey<Value>(value: Value): value is Exclude<Value, Key>;
|
|
3774
|
+
declare function isNonKey<Value>(value: Value): value is Exclude<Value, Key$1>;
|
|
3674
3775
|
/**
|
|
3675
3776
|
* Is the value not a number?
|
|
3676
3777
|
* @param value Value to check
|
|
@@ -5106,4 +5207,4 @@ declare class SizedSet<Value = unknown> extends Set<Value> {
|
|
|
5106
5207
|
get(value: Value, update?: boolean): Value | undefined;
|
|
5107
5208
|
}
|
|
5108
5209
|
//#endregion
|
|
5109
|
-
export { AnyResult, ArrayComparisonSorter, ArrayKeySorter, ArrayOrPlainObject, ArrayPosition, ArrayValueSorter, Asserter, AsyncCancelableCallback, AttemptFlow, AttemptFlowPromise, type Beacon, type BeaconOptions, BuiltIns, CancelableCallback, CancelablePromise, type Color, Constructor, DiffOptions, DiffResult, DiffValue, EqualOptions, Err, EventPosition, ExtendedErr, ExtendedResult, Flow, FlowPromise, FulfilledPromise, FuzzyConfiguration, FuzzyOptions, FuzzyResult, FuzzySearchOptions, GenericAsyncCallback, GenericCallback, type HSLAColor, type HSLColor, Key, KeyedValue, type Logger, type Memoized, type MemoizedOptions, MergeOptions, Merger, NestedArray, NestedKeys, NestedPartial, NestedValue, NestedValues, NumericalKeys, NumericalValues, type Observable, type Observer, Ok, OnceAsyncCallback, OnceCallback, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PlainObject, Primitive, PromiseData, PromiseHandlers, PromiseOptions, PromiseParameters, PromiseStrategy, PromiseTimeoutError, PromisesItems, PromisesOptions, PromisesResult, PromisesUnwrapped, PromisesValue, PromisesValues, type Queue, QueueError, type QueueOptions, type Queued, type QueuedResult, type RGBAColor, type RGBColor, RejectedPromise, RequiredKeys, Result, ResultMatch, RetryError, RetryOptions, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, Simplify, SizedMap, SizedSet, Smushed, SortDirection, Sorter, type Subscription, TemplateOptions, type Time, ToString, TypedArray, Unsmushed, UnwrapValue, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, first, firstOrDefault, flatten, floor, flow, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayPosition, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeEqualizer, initializeMerger, initializeSorter, initializeTemplater, insert, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isSorted, isTypedArray, join, kebabCase, last, lastOrDefault, logger, lowerCase, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, settlePromise, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
|
|
5210
|
+
export { AnyResult, ArrayComparisonSorter, ArrayKeySorter, ArrayOrPlainObject, ArrayPosition, ArrayValueSorter, Asserter, AsyncCancelableCallback, AttemptFlow, AttemptFlowPromise, type Beacon, type BeaconOptions, BuiltIns, CancelableCallback, CancelablePromise, type Color, Constructor, DiffOptions, DiffResult, DiffValue, EqualOptions, Err, EventPosition, ExtendedErr, ExtendedResult, Flow, FlowPromise, FulfilledPromise, FuzzyConfiguration, FuzzyOptions, FuzzyResult, FuzzySearchOptions, GenericAsyncCallback, GenericCallback, type HSLAColor, type HSLColor, Key$1 as Key, KeyedValue, type Logger, type Memoized, type MemoizedOptions, MergeOptions, Merger, NestedArray, NestedKeys, NestedPartial, NestedValue, NestedValues, NumericalKeys, NumericalValues, type Observable, type Observer, Ok, OnceAsyncCallback, OnceCallback, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PlainObject, Primitive, PromiseData, PromiseHandlers, PromiseOptions, PromiseParameters, PromiseStrategy, PromiseTimeoutError, PromisesItems, PromisesOptions, PromisesResult, PromisesUnwrapped, PromisesValue, PromisesValues, type Queue, QueueError, type QueueOptions, type Queued, type QueuedResult, type RGBAColor, type RGBColor, RejectedPromise, RequiredKeys, Result, ResultMatch, RetryError, RetryOptions, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, Shaken, Simplify, SizedMap, SizedSet, Smushed, SortDirection, Sorter, type Subscription, TemplateOptions, type Time, ToString, TypedArray, Unsmushed, UnwrapValue, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, findLast, first, firstOrDefault, flatten, floor, flow, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayPosition, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeEqualizer, initializeMerger, initializeSorter, initializeTemplater, insert, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isSorted, isTypedArray, join, kebabCase, last, lastIndexOf, lastOrDefault, logger, lowerCase, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
|
package/dist/index.mjs
CHANGED
|
@@ -21,9 +21,12 @@ function findValue(type, array, parameters, reversed) {
|
|
|
21
21
|
if (!Array.isArray(array) || array.length === 0) return findIndex ? -1 : void 0;
|
|
22
22
|
const { bool, key, value } = getFindParameters(parameters);
|
|
23
23
|
const callbacks = getArrayCallbacks(bool, key);
|
|
24
|
-
if (callbacks?.bool == null && callbacks?.keyed == null)
|
|
24
|
+
if (callbacks?.bool == null && callbacks?.keyed == null) {
|
|
25
|
+
if (findIndex) return reversed ? array.lastIndexOf(value) : array.indexOf(value);
|
|
26
|
+
return reversed ? array.findLast((item) => Object.is(item, value)) : array.find((item) => Object.is(item, value));
|
|
27
|
+
}
|
|
25
28
|
if (callbacks.bool != null) {
|
|
26
|
-
const index = array.findIndex(callbacks.bool);
|
|
29
|
+
const index = reversed ? array.findLastIndex(callbacks.bool) : array.findIndex(callbacks.bool);
|
|
27
30
|
return findIndex ? index : array[index];
|
|
28
31
|
}
|
|
29
32
|
return findValueInArray(array, callbacks.keyed, value, findIndex, reversed);
|
|
@@ -177,6 +180,10 @@ function compact(array, strict) {
|
|
|
177
180
|
function indexOf(array, ...parameters) {
|
|
178
181
|
return findValue(FIND_VALUE_INDEX, array, parameters, false);
|
|
179
182
|
}
|
|
183
|
+
indexOf.last = lastIndexOf;
|
|
184
|
+
function lastIndexOf(array, ...parameters) {
|
|
185
|
+
return findValue(FIND_VALUE_INDEX, array, parameters, true);
|
|
186
|
+
}
|
|
180
187
|
//#endregion
|
|
181
188
|
//#region src/internal/is.ts
|
|
182
189
|
/**
|
|
@@ -426,6 +433,10 @@ function exists(array, ...parameters) {
|
|
|
426
433
|
function find(array, ...parameters) {
|
|
427
434
|
return findValue(FIND_VALUE_ITEM, array, parameters, false);
|
|
428
435
|
}
|
|
436
|
+
find.last = findLast;
|
|
437
|
+
function findLast(array, ...parameters) {
|
|
438
|
+
return findValue(FIND_VALUE_ITEM, array, parameters, true);
|
|
439
|
+
}
|
|
429
440
|
//#endregion
|
|
430
441
|
//#region src/array/flatten.ts
|
|
431
442
|
/**
|
|
@@ -460,7 +471,7 @@ function times(length, value) {
|
|
|
460
471
|
function getArray(value, indiced) {
|
|
461
472
|
if (Array.isArray(value)) return value;
|
|
462
473
|
if (value instanceof Map || value instanceof Set) return [...value.values()];
|
|
463
|
-
if (
|
|
474
|
+
if (isNonPlainObject(value)) return [value];
|
|
464
475
|
if (indiced !== true) return Object.values(value);
|
|
465
476
|
const keys = Object.keys(value);
|
|
466
477
|
const { length } = keys;
|
|
@@ -831,7 +842,7 @@ function aggregate(type, array, key) {
|
|
|
831
842
|
for (let index = 0; index < length; index += 1) {
|
|
832
843
|
const item = array[index];
|
|
833
844
|
const value = callback == null ? item : callback(item, index, array);
|
|
834
|
-
if (
|
|
845
|
+
if (isNonNumber(value)) continue;
|
|
835
846
|
aggregated = aggregator(aggregated, value, notNumber);
|
|
836
847
|
counted += 1;
|
|
837
848
|
notNumber = false;
|
|
@@ -881,13 +892,23 @@ function ignoreKey(key) {
|
|
|
881
892
|
return EXPRESSION_IGNORED.test(key);
|
|
882
893
|
}
|
|
883
894
|
/**
|
|
884
|
-
* Join an array of values into a string
|
|
885
|
-
*
|
|
895
|
+
* Join an array of values into a string _(while ignoring empty values)_
|
|
896
|
+
*
|
|
897
|
+
* _(`null`, `undefined`, and any values that become whitespace-only strings are considered empty)_
|
|
898
|
+
* @param array Array of values
|
|
886
899
|
* @param delimiter Delimiter to use between values
|
|
887
900
|
* @returns Joined string
|
|
888
901
|
*/
|
|
889
|
-
function join(
|
|
890
|
-
|
|
902
|
+
function join(array, delimiter) {
|
|
903
|
+
if (!Array.isArray(array)) return "";
|
|
904
|
+
const { length } = array;
|
|
905
|
+
if (length === 0) return "";
|
|
906
|
+
const values = [];
|
|
907
|
+
for (let index = 0; index < length; index += 1) {
|
|
908
|
+
const item = getString(array[index]);
|
|
909
|
+
if (item.trim().length > 0) values.push(item);
|
|
910
|
+
}
|
|
911
|
+
return values.join(typeof delimiter === "string" ? delimiter : "");
|
|
891
912
|
}
|
|
892
913
|
function tryCallback(value, callback) {
|
|
893
914
|
try {
|
|
@@ -940,7 +961,7 @@ function getHandlers(owner, options) {
|
|
|
940
961
|
if (isConstructable(first) && isConstructable(second) && first.constructor === second.constructor) return handlers.get(first.constructor);
|
|
941
962
|
},
|
|
942
963
|
register(constructor, handler) {
|
|
943
|
-
if (
|
|
964
|
+
if (isNonConstructor(constructor) || handler === owner) return;
|
|
944
965
|
let actual = handler ?? options.method;
|
|
945
966
|
if (typeof actual !== "function" && typeof actual !== "string") return;
|
|
946
967
|
if (typeof actual === "string") actual = typeof constructor.prototype[actual] === "function" ? actual : void 0;
|
|
@@ -1890,7 +1911,7 @@ const MESSAGE_FAILED = "Retry failed";
|
|
|
1890
1911
|
//#endregion
|
|
1891
1912
|
//#region src/internal/result.ts
|
|
1892
1913
|
function _isResult(value, okValue) {
|
|
1893
|
-
if (
|
|
1914
|
+
if (isNonPlainObject(value)) return false;
|
|
1894
1915
|
return value.ok === okValue && (okValue ? PROPERTY_VALUE : PROPERTY_ERROR) in value;
|
|
1895
1916
|
}
|
|
1896
1917
|
function isError(value, extended) {
|
|
@@ -2106,7 +2127,7 @@ function getEqualOptions(input) {
|
|
|
2106
2127
|
options.ignoreCase = input;
|
|
2107
2128
|
return options;
|
|
2108
2129
|
}
|
|
2109
|
-
if (
|
|
2130
|
+
if (isNonPlainObject(input)) return options;
|
|
2110
2131
|
options.ignoreCase = typeof input.ignoreCase === "boolean" ? input.ignoreCase : false;
|
|
2111
2132
|
options.ignoreExpressions.values = (Array.isArray(input.ignoreKeys) ? input.ignoreKeys : [input.ignoreKeys]).filter((key) => key instanceof RegExp);
|
|
2112
2133
|
options.ignoreKeys.values = new Set((Array.isArray(input.ignoreKeys) ? input.ignoreKeys : [input.ignoreKeys]).filter((key) => typeof key === "string"));
|
|
@@ -3134,6 +3155,20 @@ function pick(value, keys) {
|
|
|
3134
3155
|
return partial(value, keys, false);
|
|
3135
3156
|
}
|
|
3136
3157
|
//#endregion
|
|
3158
|
+
//#region src/value/shake.ts
|
|
3159
|
+
function shake(value) {
|
|
3160
|
+
const shaken = {};
|
|
3161
|
+
if (isNonPlainObject(value)) return shaken;
|
|
3162
|
+
const keys = Object.keys(value);
|
|
3163
|
+
const { length } = keys;
|
|
3164
|
+
for (let index = 0; index < length; index += 1) {
|
|
3165
|
+
const key = keys[index];
|
|
3166
|
+
const val = value[key];
|
|
3167
|
+
if (val !== void 0) shaken[key] = val;
|
|
3168
|
+
}
|
|
3169
|
+
return shaken;
|
|
3170
|
+
}
|
|
3171
|
+
//#endregion
|
|
3137
3172
|
//#region src/value/smush.ts
|
|
3138
3173
|
function flattenObject(value, depth, smushed, prefix) {
|
|
3139
3174
|
if (depth >= MAX_DEPTH) return {};
|
|
@@ -3206,12 +3241,14 @@ function unsmush(value) {
|
|
|
3206
3241
|
//#region src/value/merge.ts
|
|
3207
3242
|
function getMergeOptions(options) {
|
|
3208
3243
|
const actual = {
|
|
3244
|
+
assignValues: false,
|
|
3209
3245
|
replaceableObjects: void 0,
|
|
3210
3246
|
skipNullableAny: false,
|
|
3211
3247
|
skipNullableInArrays: false
|
|
3212
3248
|
};
|
|
3213
3249
|
if (typeof options !== "object" || options == null) return actual;
|
|
3214
3250
|
actual.replaceableObjects = getReplaceableObjects(options.replaceableObjects);
|
|
3251
|
+
actual.assignValues = options.assignValues === true;
|
|
3215
3252
|
actual.skipNullableAny = options.skipNullableAny === true;
|
|
3216
3253
|
actual.skipNullableInArrays = options.skipNullableInArrays === true;
|
|
3217
3254
|
return actual;
|
|
@@ -3241,7 +3278,7 @@ merge.initialize = initializeMerger;
|
|
|
3241
3278
|
function mergeObjects(values, options, prefix) {
|
|
3242
3279
|
const { length } = values;
|
|
3243
3280
|
const isArray = values.every(Array.isArray);
|
|
3244
|
-
const merged = isArray ? [] : {};
|
|
3281
|
+
const merged = options.assignValues ? values[0] : isArray ? [] : {};
|
|
3245
3282
|
for (let outerIndex = 0; outerIndex < length; outerIndex += 1) {
|
|
3246
3283
|
const item = values[outerIndex];
|
|
3247
3284
|
const keys = Object.keys(item);
|
|
@@ -5017,4 +5054,4 @@ var SizedSet = class extends Set {
|
|
|
5017
5054
|
}
|
|
5018
5055
|
};
|
|
5019
5056
|
//#endregion
|
|
5020
|
-
export { CancelablePromise, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PromiseTimeoutError, QueueError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, first, firstOrDefault, flatten, floor, flow, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayPosition, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeEqualizer, initializeMerger, initializeSorter, initializeTemplater, insert, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isSorted, isTypedArray, join, kebabCase, last, lastOrDefault, logger, lowerCase, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, settlePromise, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
|
|
5057
|
+
export { CancelablePromise, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PromiseTimeoutError, QueueError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, findLast, first, firstOrDefault, flatten, floor, flow, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayPosition, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeEqualizer, initializeMerger, initializeSorter, initializeTemplater, insert, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isSorted, isTypedArray, join, kebabCase, last, lastIndexOf, lastOrDefault, logger, lowerCase, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
|