@oscarpalmer/atoms 0.76.0 → 0.77.1
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/js/array/count.cjs +1 -8
- package/dist/js/array/count.js +1 -8
- package/dist/js/array/exists.cjs +1 -8
- package/dist/js/array/exists.js +1 -8
- package/dist/js/array/filter.cjs +1 -8
- package/dist/js/array/filter.js +1 -8
- package/dist/js/array/find.cjs +1 -8
- package/dist/js/array/find.js +1 -8
- package/dist/js/array/index-of.cjs +1 -8
- package/dist/js/array/index-of.js +1 -8
- package/dist/js/array/unique.cjs +1 -1
- package/dist/js/array/unique.js +1 -1
- package/dist/js/internal/array/find.cjs +12 -2
- package/dist/js/internal/array/find.js +12 -2
- package/dist/js/value/equal.cjs +4 -1
- package/dist/js/value/equal.js +4 -1
- package/package.json +11 -4
- package/src/js/array/count.ts +10 -23
- package/src/js/array/exists.ts +10 -25
- package/src/js/array/filter.ts +10 -23
- package/src/js/array/find.ts +10 -23
- package/src/js/array/group-by.ts +66 -56
- package/src/js/array/index-of.ts +10 -23
- package/src/js/array/models.ts +2 -16
- package/src/js/array/sort.ts +23 -7
- package/src/js/array/to-map.ts +59 -53
- package/src/js/array/to-record.ts +63 -61
- package/src/js/array/unique.ts +10 -10
- package/src/js/internal/array/callbacks.ts +4 -4
- package/src/js/internal/array/find.ts +29 -6
- package/src/js/internal/value/handle.ts +5 -5
- package/src/js/value/clone.ts +3 -1
- package/src/js/value/equal.ts +4 -1
- package/src/js/value/get.ts +9 -9
- package/src/js/value/set.ts +10 -11
- package/types/array/count.d.cts +35 -6
- package/types/array/count.d.ts +4 -4
- package/types/array/exists.d.cts +35 -6
- package/types/array/exists.d.ts +4 -4
- package/types/array/filter.d.cts +35 -6
- package/types/array/filter.d.ts +4 -4
- package/types/array/find.d.cts +35 -6
- package/types/array/find.d.ts +4 -4
- package/types/array/group-by.d.cts +44 -15
- package/types/array/group-by.d.ts +13 -14
- package/types/array/index-of.d.cts +35 -6
- package/types/array/index-of.d.ts +4 -4
- package/types/array/index.d.cts +103 -66
- package/types/array/models.d.cts +2 -7
- package/types/array/models.d.ts +2 -7
- package/types/array/sort.d.cts +45 -4
- package/types/array/sort.d.ts +14 -4
- package/types/array/to-map.d.cts +44 -15
- package/types/array/to-map.d.ts +13 -14
- package/types/array/to-record.d.cts +44 -15
- package/types/array/to-record.d.ts +13 -14
- package/types/array/unique.d.cts +36 -6
- package/types/array/unique.d.ts +5 -5
- package/types/index.d.cts +280 -261
- package/types/internal/array/find.d.cts +2 -2
- package/types/internal/array/find.d.ts +2 -2
- package/types/internal/value/handle.d.cts +27 -2
- package/types/internal/value/handle.d.ts +2 -2
- package/types/value/clone.d.cts +1 -1
- package/types/value/clone.d.ts +1 -1
- package/types/value/get.d.cts +3 -3
- package/types/value/get.d.ts +3 -3
- package/types/value/index.d.cts +5 -5
- package/types/value/set.d.cts +3 -3
- package/types/value/set.d.ts +3 -3
package/src/js/array/group-by.ts
CHANGED
|
@@ -1,140 +1,150 @@
|
|
|
1
|
-
import type {KeyCallback, ValueCallback} from '~/array/models';
|
|
2
1
|
import {getCallbacks} from '~/internal/array/callbacks';
|
|
3
2
|
import type {Key, KeyedValue, PlainObject} from '~/models';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Create a record from an array of items using a specific key
|
|
7
6
|
*/
|
|
8
|
-
export function groupBy<Item,
|
|
7
|
+
export function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
9
8
|
array: Item[],
|
|
10
|
-
key:
|
|
11
|
-
): Record<KeyedValue<Item,
|
|
9
|
+
key: ItemKey,
|
|
10
|
+
): Record<KeyedValue<Item, ItemKey>, Item>;
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* Create a record from an array of items using a specific key, and grouping them into arrays
|
|
15
14
|
*/
|
|
16
|
-
export function groupBy<Item,
|
|
15
|
+
export function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
17
16
|
array: Item[],
|
|
18
|
-
key:
|
|
17
|
+
key: ItemKey,
|
|
19
18
|
arrays: true,
|
|
20
|
-
): Record<KeyedValue<Item,
|
|
19
|
+
): Record<KeyedValue<Item, ItemKey>, Item[]>;
|
|
21
20
|
|
|
22
21
|
/**
|
|
23
22
|
* Create a record from an array of items using a specific key
|
|
24
23
|
*/
|
|
25
|
-
export function groupBy<
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
): Record<ReturnType<
|
|
24
|
+
export function groupBy<
|
|
25
|
+
Item,
|
|
26
|
+
ItemKey extends (item: Item, index: number, array: Item[]) => Key,
|
|
27
|
+
>(array: Item[], key: ItemKey): Record<ReturnType<ItemKey>, Item>;
|
|
29
28
|
|
|
30
29
|
/**
|
|
31
30
|
* Create a record from an array of items using a specific key, and grouping them into arrays
|
|
32
31
|
*/
|
|
33
|
-
export function groupBy<
|
|
32
|
+
export function groupBy<
|
|
33
|
+
Item,
|
|
34
|
+
ItemKey extends (item: Item, index: number, array: Item[]) => Key,
|
|
35
|
+
>(
|
|
34
36
|
array: Item[],
|
|
35
|
-
key:
|
|
37
|
+
key: ItemKey,
|
|
36
38
|
arrays: true,
|
|
37
|
-
): Record<ReturnType<
|
|
39
|
+
): Record<ReturnType<ItemKey>, Item[]>;
|
|
38
40
|
|
|
39
41
|
/**
|
|
40
42
|
* Create a record from an array of items using a specific key and value
|
|
41
43
|
*/
|
|
42
|
-
export function groupBy<
|
|
44
|
+
export function groupBy<
|
|
45
|
+
Item extends PlainObject,
|
|
46
|
+
ItemKey extends keyof Item,
|
|
47
|
+
ItemValue extends keyof Item,
|
|
48
|
+
>(
|
|
43
49
|
array: Item[],
|
|
44
|
-
key:
|
|
45
|
-
value:
|
|
46
|
-
): Record<KeyedValue<Item,
|
|
50
|
+
key: ItemKey,
|
|
51
|
+
value: ItemValue,
|
|
52
|
+
): Record<KeyedValue<Item, ItemKey>, KeyedValue<Item, ItemValue>>;
|
|
47
53
|
|
|
48
54
|
/**
|
|
49
55
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
50
56
|
*/
|
|
51
|
-
export function groupBy<
|
|
57
|
+
export function groupBy<
|
|
58
|
+
Item extends PlainObject,
|
|
59
|
+
ItemKey extends keyof Item,
|
|
60
|
+
ItemValue extends keyof Item,
|
|
61
|
+
>(
|
|
52
62
|
array: Item[],
|
|
53
|
-
key:
|
|
54
|
-
value:
|
|
63
|
+
key: ItemKey,
|
|
64
|
+
value: ItemValue,
|
|
55
65
|
arrays: true,
|
|
56
|
-
): Record<KeyedValue<Item,
|
|
66
|
+
): Record<KeyedValue<Item, ItemKey>, Array<KeyedValue<Item, ItemValue>>>;
|
|
57
67
|
|
|
58
68
|
/**
|
|
59
69
|
* Create a record from an array of items using a specific key and value
|
|
60
70
|
*/
|
|
61
71
|
export function groupBy<
|
|
62
|
-
Item,
|
|
63
|
-
|
|
64
|
-
|
|
72
|
+
Item extends PlainObject,
|
|
73
|
+
ItemKey extends keyof Item,
|
|
74
|
+
ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
|
|
65
75
|
>(
|
|
66
76
|
array: Item[],
|
|
67
|
-
key:
|
|
68
|
-
value:
|
|
69
|
-
): Record<KeyedValue<Item,
|
|
77
|
+
key: ItemKey,
|
|
78
|
+
value: ItemValue,
|
|
79
|
+
): Record<KeyedValue<Item, ItemKey>, ReturnType<ItemValue>>;
|
|
70
80
|
|
|
71
81
|
/**
|
|
72
82
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
73
83
|
*/
|
|
74
84
|
export function groupBy<
|
|
75
|
-
Item,
|
|
76
|
-
|
|
77
|
-
|
|
85
|
+
Item extends PlainObject,
|
|
86
|
+
ItemKey extends keyof Item,
|
|
87
|
+
ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
|
|
78
88
|
>(
|
|
79
89
|
array: Item[],
|
|
80
|
-
key:
|
|
81
|
-
value:
|
|
90
|
+
key: ItemKey,
|
|
91
|
+
value: ItemValue,
|
|
82
92
|
arrays: true,
|
|
83
|
-
): Record<KeyedValue<Item,
|
|
93
|
+
): Record<KeyedValue<Item, ItemKey>, Array<ReturnType<ItemValue>>>;
|
|
84
94
|
|
|
85
95
|
/**
|
|
86
96
|
* Create a record from an array of items using a specific key and value
|
|
87
97
|
*/
|
|
88
98
|
export function groupBy<
|
|
89
|
-
Item,
|
|
90
|
-
|
|
91
|
-
|
|
99
|
+
Item extends PlainObject,
|
|
100
|
+
ItemKey extends (item: Item, index: number, array: Item[]) => Key,
|
|
101
|
+
ItemValue extends keyof Item,
|
|
92
102
|
>(
|
|
93
103
|
array: Item[],
|
|
94
|
-
key:
|
|
95
|
-
value:
|
|
96
|
-
): Record<ReturnType<
|
|
104
|
+
key: ItemKey,
|
|
105
|
+
value: ItemValue,
|
|
106
|
+
): Record<ReturnType<ItemKey>, KeyedValue<Item, ItemValue>>;
|
|
97
107
|
|
|
98
108
|
/**
|
|
99
109
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
100
110
|
*/
|
|
101
111
|
export function groupBy<
|
|
102
|
-
Item,
|
|
103
|
-
|
|
104
|
-
|
|
112
|
+
Item extends PlainObject,
|
|
113
|
+
ItemKey extends (item: Item, index: number, array: Item[]) => Key,
|
|
114
|
+
ItemValue extends keyof Item,
|
|
105
115
|
>(
|
|
106
116
|
array: Item[],
|
|
107
|
-
key:
|
|
108
|
-
value:
|
|
117
|
+
key: ItemKey,
|
|
118
|
+
value: ItemValue,
|
|
109
119
|
arrays: true,
|
|
110
|
-
): Record<ReturnType<
|
|
120
|
+
): Record<ReturnType<ItemKey>, Array<KeyedValue<Item, ItemValue>>>;
|
|
111
121
|
|
|
112
122
|
/**
|
|
113
123
|
* Create a record from an array of items using a specific key and value
|
|
114
124
|
*/
|
|
115
125
|
export function groupBy<
|
|
116
126
|
Item,
|
|
117
|
-
|
|
118
|
-
|
|
127
|
+
ItemKey extends (item: Item, index: number, array: Item[]) => Key,
|
|
128
|
+
ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
|
|
119
129
|
>(
|
|
120
130
|
array: Item[],
|
|
121
|
-
key:
|
|
122
|
-
value:
|
|
123
|
-
): Record<ReturnType<
|
|
131
|
+
key: ItemKey,
|
|
132
|
+
value: ItemValue,
|
|
133
|
+
): Record<ReturnType<ItemKey>, ReturnType<ItemValue>>;
|
|
124
134
|
|
|
125
135
|
/**
|
|
126
136
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
127
137
|
*/
|
|
128
138
|
export function groupBy<
|
|
129
139
|
Item,
|
|
130
|
-
|
|
131
|
-
|
|
140
|
+
ItemKey extends (item: Item, index: number, array: Item[]) => Key,
|
|
141
|
+
ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
|
|
132
142
|
>(
|
|
133
143
|
array: Item[],
|
|
134
|
-
key:
|
|
135
|
-
value:
|
|
144
|
+
key: ItemKey,
|
|
145
|
+
value: ItemValue,
|
|
136
146
|
arrays: true,
|
|
137
|
-
): Record<ReturnType<
|
|
147
|
+
): Record<ReturnType<ItemKey>, Array<ReturnType<ItemValue>>>;
|
|
138
148
|
|
|
139
149
|
export function groupBy(
|
|
140
150
|
array: unknown[],
|
package/src/js/array/index-of.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {BooleanCallback, KeyCallback} from '~/array/models';
|
|
2
1
|
import {findValue} from '~/internal/array/find';
|
|
2
|
+
import type {Key, PlainObject} from '~/models';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Get the index for the first item matching `value` _(or `-1` if no match is found)_
|
|
@@ -11,41 +11,28 @@ export function indexOf<Item>(array: Item[], value: Item): number;
|
|
|
11
11
|
*/
|
|
12
12
|
export function indexOf<Item>(
|
|
13
13
|
array: Item[],
|
|
14
|
-
matches:
|
|
14
|
+
matches: (item: Item, index: number, array: Item[]) => boolean,
|
|
15
15
|
): number;
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* - Get the index for the first matching item _(or `-1` if no match is found)_
|
|
19
19
|
* - Use `key` to find a comparison value to match with `value`
|
|
20
20
|
*/
|
|
21
|
-
export function indexOf<Item,
|
|
21
|
+
export function indexOf<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
22
22
|
array: Item[],
|
|
23
|
-
key:
|
|
24
|
-
value: Item[
|
|
23
|
+
key: ItemKey,
|
|
24
|
+
value: Item[ItemKey],
|
|
25
25
|
): number;
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* - Get the index for the first matching item _(or `-1` if no match is found)_
|
|
29
29
|
* - Use `key` to find a comparison value to match with `value`
|
|
30
30
|
*/
|
|
31
|
-
export function indexOf<
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
): number;
|
|
31
|
+
export function indexOf<
|
|
32
|
+
Item,
|
|
33
|
+
ItemKey extends (item: Item, index: number, array: Item[]) => Key,
|
|
34
|
+
>(array: Item[], key: ItemKey, value: ReturnType<ItemKey>): number;
|
|
36
35
|
|
|
37
36
|
export function indexOf(array: unknown[], ...parameters: unknown[]): number {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return findValue(
|
|
41
|
-
'index',
|
|
42
|
-
array,
|
|
43
|
-
length === 1 && typeof parameters[0] === 'function'
|
|
44
|
-
? parameters[0]
|
|
45
|
-
: undefined,
|
|
46
|
-
length === 2 ? parameters[0] : undefined,
|
|
47
|
-
length === 1 && typeof parameters[0] !== 'function'
|
|
48
|
-
? parameters[0]
|
|
49
|
-
: parameters[1],
|
|
50
|
-
) as number;
|
|
37
|
+
return findValue('index', array, parameters) as number;
|
|
51
38
|
}
|
package/src/js/array/models.ts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import type {GenericCallback, Key} from '~/models';
|
|
2
2
|
|
|
3
|
-
export type ArrayCallback<Item, Value> = (
|
|
4
|
-
item: Item,
|
|
5
|
-
index: number,
|
|
6
|
-
array: Item[],
|
|
7
|
-
) => Value;
|
|
8
|
-
|
|
9
|
-
export type BooleanCallback<Item> = ArrayCallback<Item, boolean>;
|
|
10
|
-
|
|
11
3
|
export type Callbacks = {
|
|
12
4
|
bool?: GenericCallback;
|
|
13
5
|
key?: GenericCallback;
|
|
@@ -18,18 +10,12 @@ export type FindType = 'index' | 'value';
|
|
|
18
10
|
|
|
19
11
|
export type InsertType = 'push' | 'splice';
|
|
20
12
|
|
|
21
|
-
export type KeyCallback<Item> = ArrayCallback<Item, Key>;
|
|
22
|
-
|
|
23
13
|
export type SortKey<Item> = {
|
|
24
14
|
direction: 'asc' | 'desc';
|
|
25
|
-
value: Key |
|
|
15
|
+
value: Key | ((item: Item) => Key);
|
|
26
16
|
};
|
|
27
17
|
|
|
28
|
-
export type SortKeyCallback<Item> = (item: Item) => unknown;
|
|
29
|
-
|
|
30
18
|
export type SortKeyWithCallback<Item> = {
|
|
31
|
-
callback:
|
|
19
|
+
callback: (item: Item) => Key;
|
|
32
20
|
direction: 'asc' | 'desc';
|
|
33
21
|
};
|
|
34
|
-
|
|
35
|
-
export type ValueCallback<Item> = ArrayCallback<Item, unknown>;
|
package/src/js/array/sort.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
SortKey,
|
|
3
|
-
SortKeyCallback,
|
|
4
|
-
SortKeyWithCallback,
|
|
5
|
-
} from '~/array/models';
|
|
1
|
+
import type {SortKey, SortKeyWithCallback} from '~/array/models';
|
|
6
2
|
import {isKey} from '~/is';
|
|
7
3
|
import type {Key, PlainObject} from '~/models';
|
|
8
4
|
import {compare} from '~/value/compare';
|
|
@@ -18,7 +14,17 @@ export function sort<Item>(array: Item[], descending?: boolean): Item[];
|
|
|
18
14
|
*/
|
|
19
15
|
export function sort<Item>(
|
|
20
16
|
array: Item[],
|
|
21
|
-
key: Key | SortKey<Item> |
|
|
17
|
+
key: Key | SortKey<Item> | ((item: Item) => Key),
|
|
18
|
+
descending?: boolean,
|
|
19
|
+
): Item[];
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* - Sort an array of items, using a `key` to sort by a specific value
|
|
23
|
+
* - Defaults to ascending, but can be changed by setting `descending` to `true`, or using a `SortKey`
|
|
24
|
+
*/
|
|
25
|
+
export function sort<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
26
|
+
array: Item[],
|
|
27
|
+
key: ItemKey | Key | SortKey<Item> | ((item: Item) => Key),
|
|
22
28
|
descending?: boolean,
|
|
23
29
|
): Item[];
|
|
24
30
|
|
|
@@ -28,7 +34,17 @@ export function sort<Item>(
|
|
|
28
34
|
*/
|
|
29
35
|
export function sort<Item>(
|
|
30
36
|
array: Item[],
|
|
31
|
-
keys: Array<Key | SortKey<Item> |
|
|
37
|
+
keys: Array<Key | SortKey<Item> | ((item: Item) => Key)>,
|
|
38
|
+
descending?: boolean,
|
|
39
|
+
): Item[];
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* - Sort an array of items, using multiple `keys` to sort by specific values
|
|
43
|
+
* - Defaults to ascending, but can be changed by setting `descending` to `true`, or using `SortKey`
|
|
44
|
+
*/
|
|
45
|
+
export function sort<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
46
|
+
array: Item[],
|
|
47
|
+
keys: Array<ItemKey | Key | SortKey<Item> | ((item: Item) => Key)>,
|
|
32
48
|
descending?: boolean,
|
|
33
49
|
): Item[];
|
|
34
50
|
|
package/src/js/array/to-map.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type {KeyCallback, ValueCallback} from '~/array/models';
|
|
2
1
|
import {getCallbacks} from '~/internal/array/callbacks';
|
|
3
|
-
import type {Key, KeyedValue} from '~/models';
|
|
2
|
+
import type {Key, KeyedValue, PlainObject} from '~/models';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Create a map from an array of items _(using their indices as keys)_
|
|
@@ -10,117 +9,124 @@ export function toMap<Item>(array: Item[]): Map<number, Item>;
|
|
|
10
9
|
/**
|
|
11
10
|
* Create a map from an array of items using a specific key
|
|
12
11
|
*/
|
|
13
|
-
export function toMap<Item,
|
|
12
|
+
export function toMap<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
14
13
|
array: Item[],
|
|
15
|
-
key:
|
|
16
|
-
): Map<KeyedValue<Item,
|
|
14
|
+
key: ItemKey,
|
|
15
|
+
): Map<KeyedValue<Item, ItemKey>, Item>;
|
|
17
16
|
|
|
18
17
|
/**
|
|
19
18
|
* Create a map from an array of items using a specific key, and grouping them into arrays
|
|
20
19
|
*/
|
|
21
|
-
export function toMap<Item,
|
|
20
|
+
export function toMap<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
22
21
|
array: Item[],
|
|
23
|
-
key:
|
|
22
|
+
key: ItemKey,
|
|
24
23
|
arrays: true,
|
|
25
|
-
): Map<KeyedValue<Item,
|
|
24
|
+
): Map<KeyedValue<Item, ItemKey>, Item[]>;
|
|
26
25
|
|
|
27
26
|
/**
|
|
28
27
|
* Create a map from an array of items using a specific key
|
|
29
28
|
*/
|
|
30
|
-
export function toMap<
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
): Map<ReturnType<
|
|
29
|
+
export function toMap<
|
|
30
|
+
Item,
|
|
31
|
+
ItemKey extends (item: Item, index: number, array: Item[]) => Key,
|
|
32
|
+
>(array: Item[], key: ItemKey): Map<ReturnType<ItemKey>, Item>;
|
|
34
33
|
|
|
35
34
|
/**
|
|
36
35
|
* Create a map from an array of items using a specific key, and grouping them into arrays
|
|
37
36
|
*/
|
|
38
|
-
export function toMap<
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
): Map<ReturnType<Key>, Item[]>;
|
|
37
|
+
export function toMap<
|
|
38
|
+
Item,
|
|
39
|
+
ItemKey extends (item: Item, index: number, array: Item[]) => Key,
|
|
40
|
+
>(array: Item[], key: ItemKey, arrays: true): Map<ReturnType<ItemKey>, Item[]>;
|
|
43
41
|
|
|
44
42
|
/**
|
|
45
43
|
* Create a map from an array of items using a specific key and value
|
|
46
44
|
*/
|
|
47
|
-
export function toMap<
|
|
45
|
+
export function toMap<
|
|
46
|
+
Item extends PlainObject,
|
|
47
|
+
ItemKey extends keyof Item,
|
|
48
|
+
ItemValue extends keyof Item,
|
|
49
|
+
>(
|
|
48
50
|
array: Item[],
|
|
49
|
-
key:
|
|
50
|
-
value:
|
|
51
|
-
): Map<KeyedValue<Item,
|
|
51
|
+
key: ItemKey,
|
|
52
|
+
value: ItemValue,
|
|
53
|
+
): Map<KeyedValue<Item, ItemKey>, KeyedValue<Item, ItemValue>>;
|
|
52
54
|
|
|
53
55
|
/**
|
|
54
56
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
55
57
|
*/
|
|
56
|
-
export function toMap<
|
|
58
|
+
export function toMap<
|
|
59
|
+
Item extends PlainObject,
|
|
60
|
+
ItemKey extends keyof Item,
|
|
61
|
+
ItemValue extends keyof Item,
|
|
62
|
+
>(
|
|
57
63
|
array: Item[],
|
|
58
|
-
key:
|
|
59
|
-
value:
|
|
64
|
+
key: ItemKey,
|
|
65
|
+
value: ItemValue,
|
|
60
66
|
arrays: true,
|
|
61
|
-
): Map<KeyedValue<Item,
|
|
67
|
+
): Map<KeyedValue<Item, ItemKey>, Array<KeyedValue<Item, ItemValue>>>;
|
|
62
68
|
|
|
63
69
|
/**
|
|
64
70
|
* Create a map from an array of items using a specific key and value
|
|
65
71
|
*/
|
|
66
72
|
export function toMap<
|
|
67
|
-
Item,
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
Item extends PlainObject,
|
|
74
|
+
ItemKey extends keyof Item,
|
|
75
|
+
ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
|
|
70
76
|
>(
|
|
71
77
|
array: Item[],
|
|
72
|
-
key:
|
|
73
|
-
value:
|
|
74
|
-
): Map<KeyedValue<Item,
|
|
78
|
+
key: ItemKey,
|
|
79
|
+
value: ItemValue,
|
|
80
|
+
): Map<KeyedValue<Item, ItemKey>, ReturnType<ItemValue>>;
|
|
75
81
|
|
|
76
82
|
/**
|
|
77
83
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
78
84
|
*/
|
|
79
85
|
export function toMap<
|
|
80
|
-
Item,
|
|
81
|
-
|
|
82
|
-
|
|
86
|
+
Item extends PlainObject,
|
|
87
|
+
ItemKey extends keyof Item,
|
|
88
|
+
ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
|
|
83
89
|
>(
|
|
84
90
|
array: Item[],
|
|
85
|
-
key:
|
|
86
|
-
value:
|
|
91
|
+
key: ItemKey,
|
|
92
|
+
value: ItemValue,
|
|
87
93
|
arrays: true,
|
|
88
|
-
): Map<KeyedValue<Item,
|
|
94
|
+
): Map<KeyedValue<Item, ItemKey>, Array<ReturnType<ItemValue>>>;
|
|
89
95
|
|
|
90
96
|
/**
|
|
91
97
|
* Create a map from an array of items using a specific key and value
|
|
92
98
|
*/
|
|
93
99
|
export function toMap<
|
|
94
|
-
Item,
|
|
95
|
-
|
|
96
|
-
|
|
100
|
+
Item extends PlainObject,
|
|
101
|
+
ItemKey extends (item: Item, index: number, array: Item[]) => Key,
|
|
102
|
+
ItemValue extends keyof Item,
|
|
97
103
|
>(
|
|
98
104
|
array: Item[],
|
|
99
|
-
key:
|
|
100
|
-
value:
|
|
101
|
-
): Map<ReturnType<
|
|
105
|
+
key: ItemKey,
|
|
106
|
+
value: ItemValue,
|
|
107
|
+
): Map<ReturnType<ItemKey>, KeyedValue<Item, ItemValue>>;
|
|
102
108
|
|
|
103
109
|
/**
|
|
104
110
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
105
111
|
*/
|
|
106
112
|
export function toMap<
|
|
107
|
-
Item,
|
|
108
|
-
|
|
109
|
-
|
|
113
|
+
Item extends PlainObject,
|
|
114
|
+
ItemKey extends (item: Item, index: number, array: Item[]) => Key,
|
|
115
|
+
ItemValue extends keyof Item,
|
|
110
116
|
>(
|
|
111
117
|
array: Item[],
|
|
112
|
-
key:
|
|
113
|
-
value:
|
|
118
|
+
key: ItemKey,
|
|
119
|
+
value: ItemValue,
|
|
114
120
|
arrays: true,
|
|
115
|
-
): Map<ReturnType<
|
|
121
|
+
): Map<ReturnType<ItemKey>, Array<KeyedValue<Item, ItemValue>>>;
|
|
116
122
|
|
|
117
123
|
/**
|
|
118
124
|
* Create a map from an array of items using a specific key and value
|
|
119
125
|
*/
|
|
120
126
|
export function toMap<
|
|
121
127
|
Item,
|
|
122
|
-
Key extends
|
|
123
|
-
Value extends
|
|
128
|
+
Key extends (item: Item, index: number, array: Item[]) => Key,
|
|
129
|
+
Value extends (item: Item, index: number, array: Item[]) => unknown,
|
|
124
130
|
>(
|
|
125
131
|
array: Item[],
|
|
126
132
|
key: Key,
|
|
@@ -132,8 +138,8 @@ export function toMap<
|
|
|
132
138
|
*/
|
|
133
139
|
export function toMap<
|
|
134
140
|
Item,
|
|
135
|
-
Key extends
|
|
136
|
-
Value extends
|
|
141
|
+
Key extends (item: Item, index: number, array: Item[]) => Key,
|
|
142
|
+
Value extends (item: Item, index: number, array: Item[]) => unknown,
|
|
137
143
|
>(
|
|
138
144
|
array: Item[],
|
|
139
145
|
key: Key,
|