@oscarpalmer/atoms 0.201.0 → 0.202.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/group-by.d.mts +13 -181
- package/dist/array/to-map.d.mts +15 -171
- package/dist/array/to-record.d.mts +15 -171
- package/dist/index.d.mts +62 -526
- package/dist/internal/subscription.d.mts +6 -6
- package/dist/models.d.mts +17 -1
- package/package.json +1 -1
|
@@ -1,33 +1,13 @@
|
|
|
1
|
-
import { Key,
|
|
1
|
+
import { Key, KeyOrCallback, KeyOrCallbackKey, KeyOrCallbackValue, Simplify } from "../models.mjs";
|
|
2
2
|
//#region src/array/group-by.d.ts
|
|
3
3
|
/**
|
|
4
|
-
* Create a record from an array of items using a specific key
|
|
5
|
-
*
|
|
6
|
-
* If multiple items have the same key, the latest item's value will be used
|
|
7
|
-
*
|
|
8
|
-
* @param array Array to group
|
|
9
|
-
* @param key Callback to get an item's grouping key
|
|
10
|
-
* @param value Callback to get an item's value
|
|
11
|
-
* @returns Record of keyed values
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* groupBy(
|
|
16
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
17
|
-
* item => item.value,
|
|
18
|
-
* item => item,
|
|
19
|
-
* ); // => {10: {id: 3, value: 10}, 20: {id: 2, value: 20}}
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
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>>>;
|
|
23
|
-
/**
|
|
24
|
-
* Create a record from an array of items using a specific key and value
|
|
4
|
+
* Create a record from an array of items using a specific key
|
|
25
5
|
*
|
|
26
6
|
* If multiple items have the same key, the latest item's value will be used
|
|
27
7
|
*
|
|
28
8
|
* @param array Array to group
|
|
29
|
-
* @param key Callback to
|
|
30
|
-
* @param value
|
|
9
|
+
* @param key Callback or key to use for grouping
|
|
10
|
+
* @param value Callback or key to use for value, defaulting to the item itself
|
|
31
11
|
* @returns Record of keyed values
|
|
32
12
|
*
|
|
33
13
|
* @example
|
|
@@ -35,58 +15,18 @@ declare function groupBy<Item, KeyCallback extends (item: Item, index: number, a
|
|
|
35
15
|
* groupBy(
|
|
36
16
|
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
37
17
|
* item => item.value,
|
|
38
|
-
* 'id'
|
|
39
|
-
* ); // => {10: 3, 20: 2}
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
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]>;
|
|
43
|
-
/**
|
|
44
|
-
* Create a record from an array of items using a specific key and value
|
|
45
|
-
*
|
|
46
|
-
* If multiple items have the same key, the latest item's value will be used
|
|
47
|
-
*
|
|
48
|
-
* @param array Array to group
|
|
49
|
-
* @param key Key to use for grouping
|
|
50
|
-
* @param value Callback to get an item's value
|
|
51
|
-
* @returns Record of keyed values
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```typescript
|
|
55
|
-
* groupBy(
|
|
56
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
57
|
-
* 'value',
|
|
58
18
|
* item => item,
|
|
59
19
|
* ); // => {10: {id: 3, value: 10}, 20: {id: 2, value: 20}}
|
|
60
20
|
* ```
|
|
61
21
|
*/
|
|
62
|
-
declare function groupBy<Item
|
|
63
|
-
/**
|
|
64
|
-
* Create a record from an array of items using a specific key and value
|
|
65
|
-
*
|
|
66
|
-
* If multiple items have the same key, the latest item's value will be used
|
|
67
|
-
*
|
|
68
|
-
* @param array Array to group
|
|
69
|
-
* @param key Key to use for grouping
|
|
70
|
-
* @param value Key to use for value
|
|
71
|
-
* @returns Record of keyed values
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* ```typescript
|
|
75
|
-
* groupBy(
|
|
76
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
77
|
-
* 'value',
|
|
78
|
-
* 'id'
|
|
79
|
-
* ); // => {10: 3, 20: 2}
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Simplify<Record<KeyedValue<Item, ItemKey>, Item[ItemValue]>>;
|
|
22
|
+
declare function groupBy<Item, KeyArg extends KeyOrCallback<Item, Key>, ValueArg extends KeyOrCallback<Item>>(array: Item[], key: KeyArg, value: ValueArg): Simplify<Record<KeyOrCallbackKey<Item, KeyArg>, KeyOrCallbackValue<Item, ValueArg>>>;
|
|
83
23
|
/**
|
|
84
24
|
* Create a record from an array of items using a specific key
|
|
85
25
|
*
|
|
86
26
|
* If multiple items have the same key, the latest item will be used
|
|
87
27
|
*
|
|
88
28
|
* @param array Array to group
|
|
89
|
-
* @param
|
|
29
|
+
* @param key Callback or key to use for grouping
|
|
90
30
|
* @returns Record of keyed items
|
|
91
31
|
*
|
|
92
32
|
* @example
|
|
@@ -97,25 +37,7 @@ declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item, I
|
|
|
97
37
|
* ); // => {10: {id: 3, value: 10}, 20: {id: 2, value: 20}}
|
|
98
38
|
* ```
|
|
99
39
|
*/
|
|
100
|
-
declare function groupBy<Item,
|
|
101
|
-
/**
|
|
102
|
-
* Create a record from an array of items using a specific key
|
|
103
|
-
*
|
|
104
|
-
* If multiple items have the same key, the latest item will be used
|
|
105
|
-
*
|
|
106
|
-
* @param array Array to group
|
|
107
|
-
* @param key Key to use for grouping
|
|
108
|
-
* @returns Record of keyed items
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* ```typescript
|
|
112
|
-
* groupBy(
|
|
113
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
114
|
-
* 'value',
|
|
115
|
-
* ); // => {10: {id: 3, value: 10}, 20: {id: 2, value: 20}}
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Simplify<Record<KeyedValue<Item, ItemKey>, Item>>;
|
|
40
|
+
declare function groupBy<Item, KeyArg extends KeyOrCallback<Item, Key>>(array: Item[], key: KeyArg): Simplify<Record<KeyOrCallbackKey<Item, KeyArg>, Item>>;
|
|
119
41
|
/**
|
|
120
42
|
* Create a record from an array of items _(using indices as keys)_
|
|
121
43
|
*
|
|
@@ -134,13 +56,13 @@ declare namespace groupBy {
|
|
|
134
56
|
var arrays: typeof groupArraysBy;
|
|
135
57
|
}
|
|
136
58
|
/**
|
|
137
|
-
* Create a record from an array of items using a specific key
|
|
59
|
+
* Create a record from an array of items using a specific key, grouping values into arrays
|
|
138
60
|
*
|
|
139
61
|
* _Available as `groupArraysBy` and `groupBy.arrays`_
|
|
140
62
|
*
|
|
141
63
|
* @param array Array to group
|
|
142
|
-
* @param key Callback to
|
|
143
|
-
* @param value Callback to
|
|
64
|
+
* @param key Callback or key to use for grouping
|
|
65
|
+
* @param value Callback or key to use for value, defaulting to the item itself
|
|
144
66
|
* @returns Record of keyed values
|
|
145
67
|
*
|
|
146
68
|
* @example
|
|
@@ -155,83 +77,14 @@ declare namespace groupBy {
|
|
|
155
77
|
* // }
|
|
156
78
|
* ```
|
|
157
79
|
*/
|
|
158
|
-
declare function groupArraysBy<Item,
|
|
159
|
-
/**
|
|
160
|
-
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
161
|
-
*
|
|
162
|
-
* _Available as `groupArraysBy` and `groupBy.arrays`_
|
|
163
|
-
*
|
|
164
|
-
* @param array Array to group
|
|
165
|
-
* @param key Callback to get an item's grouping key
|
|
166
|
-
* @param value Key to use for value
|
|
167
|
-
* @returns Record of keyed values
|
|
168
|
-
*
|
|
169
|
-
* @example
|
|
170
|
-
* ```typescript
|
|
171
|
-
* groupArraysBy(
|
|
172
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
173
|
-
* item => item.value,
|
|
174
|
-
* 'id',
|
|
175
|
-
* ); // => {
|
|
176
|
-
* // 10: [1, 3],
|
|
177
|
-
* // 20: [2],
|
|
178
|
-
* // }
|
|
179
|
-
* ```
|
|
180
|
-
*/
|
|
181
|
-
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][]>;
|
|
182
|
-
/**
|
|
183
|
-
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
184
|
-
*
|
|
185
|
-
* _Available as `groupArraysBy` and `groupBy.arrays`_
|
|
186
|
-
*
|
|
187
|
-
* @param array Array to group
|
|
188
|
-
* @param key Key to use for grouping
|
|
189
|
-
* @param value Callback to get an item's value
|
|
190
|
-
* @returns Record of keyed values
|
|
191
|
-
*
|
|
192
|
-
* @example
|
|
193
|
-
* ```typescript
|
|
194
|
-
* groupArraysBy(
|
|
195
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
196
|
-
* 'value',
|
|
197
|
-
* item => item,
|
|
198
|
-
* ); // => {
|
|
199
|
-
* // 10: [{id: 1, value: 10}, {id: 3, value: 10}],
|
|
200
|
-
* // 20: [{id: 2, value: 20}],
|
|
201
|
-
* // }
|
|
202
|
-
* ```
|
|
203
|
-
*/
|
|
204
|
-
declare function groupArraysBy<Item extends PlainObject, ItemKey extends keyof Item, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ValueCallback): Simplify<Record<KeyedValue<Item, ItemKey>, Array<ReturnType<ValueCallback>>>>;
|
|
205
|
-
/**
|
|
206
|
-
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
207
|
-
*
|
|
208
|
-
* _Available as `groupArraysBy` and `groupBy.arrays`_
|
|
209
|
-
*
|
|
210
|
-
* @param array Array to group
|
|
211
|
-
* @param key Key to use for grouping
|
|
212
|
-
* @param value Key to use for value
|
|
213
|
-
* @returns Record of keyed values
|
|
214
|
-
*
|
|
215
|
-
* @example
|
|
216
|
-
* ```typescript
|
|
217
|
-
* groupArraysBy(
|
|
218
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
219
|
-
* 'value',
|
|
220
|
-
* 'id',
|
|
221
|
-
* ); // => {
|
|
222
|
-
* // 10: [1, 3],
|
|
223
|
-
* // 20: [2],
|
|
224
|
-
* // }
|
|
225
|
-
* ```
|
|
226
|
-
*/
|
|
227
|
-
declare function groupArraysBy<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Simplify<Record<KeyedValue<Item, ItemKey>, Item[ItemValue][]>>;
|
|
80
|
+
declare function groupArraysBy<Item, KeyArg extends KeyOrCallback<Item, Key>, ValueArg extends KeyOrCallback<Item>>(array: Item[], key: KeyArg, value: ValueArg): Simplify<Record<KeyOrCallbackKey<Item, KeyArg>, Array<KeyOrCallbackValue<Item, ValueArg>>>>;
|
|
228
81
|
/**
|
|
229
82
|
* Create a record from an array of items using a specific key, grouping items into arrays
|
|
230
83
|
*
|
|
231
84
|
* _Available as `groupArraysBy` and `groupBy.arrays`_
|
|
232
85
|
*
|
|
233
86
|
* @param array Array to group
|
|
234
|
-
* @param
|
|
87
|
+
* @param key Callback or key to use for grouping
|
|
235
88
|
* @returns Record of keyed items
|
|
236
89
|
*
|
|
237
90
|
* @example
|
|
@@ -245,27 +98,6 @@ declare function groupArraysBy<Item extends PlainObject, ItemKey extends keyof I
|
|
|
245
98
|
* // }
|
|
246
99
|
* ```
|
|
247
100
|
*/
|
|
248
|
-
declare function groupArraysBy<Item,
|
|
249
|
-
/**
|
|
250
|
-
* Create a record from an array of items using a specific key, grouping items into arrays
|
|
251
|
-
*
|
|
252
|
-
* _Available as `groupArraysBy` and `groupBy.arrays`_
|
|
253
|
-
*
|
|
254
|
-
* @param array Array to group
|
|
255
|
-
* @param key Key to use for grouping
|
|
256
|
-
* @returns Record of keyed items
|
|
257
|
-
*
|
|
258
|
-
* @example
|
|
259
|
-
* ```typescript
|
|
260
|
-
* groupArraysBy(
|
|
261
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
262
|
-
* 'value',
|
|
263
|
-
* ); // => {
|
|
264
|
-
* // 10: [{id: 1, value: 10}, {id: 3, value: 10}],
|
|
265
|
-
* // 20: [{id: 2, value: 20}],
|
|
266
|
-
* // }
|
|
267
|
-
* ```
|
|
268
|
-
*/
|
|
269
|
-
declare function groupArraysBy<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Simplify<Record<KeyedValue<Item, ItemKey>, Item[]>>;
|
|
101
|
+
declare function groupArraysBy<Item, KeyArg extends KeyOrCallback<Item, Key>>(array: Item[], key: KeyArg): Simplify<Record<KeyOrCallbackKey<Item, KeyArg>, Item[]>>;
|
|
270
102
|
//#endregion
|
|
271
103
|
export { groupArraysBy, groupBy };
|
package/dist/array/to-map.d.mts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Key,
|
|
1
|
+
import { Key, KeyOrCallback, KeyOrCallbackKey, KeyOrCallbackValue } from "../models.mjs";
|
|
2
2
|
//#region src/array/to-map.d.ts
|
|
3
3
|
/**
|
|
4
|
-
* Create a _Map_ from an array of items using
|
|
4
|
+
* Create a _Map_ from an array of items using a specific key
|
|
5
5
|
*
|
|
6
6
|
* If multiple items have the same key, the latest item's value will be used
|
|
7
7
|
*
|
|
8
8
|
* @param array Array to convert
|
|
9
|
-
* @param key Callback to
|
|
10
|
-
* @param value Callback to
|
|
9
|
+
* @param key Callback or key to use for grouping
|
|
10
|
+
* @param value Callback or key to use for value, defaulting to the item itself
|
|
11
11
|
* @returns _Map_ of keyed values
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
@@ -19,74 +19,14 @@ import { Key, PlainObject } from "../models.mjs";
|
|
|
19
19
|
* ); // => Map { 10 => 3, 20 => 2 }
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
declare function toMap<Item,
|
|
22
|
+
declare function toMap<Item, KeyArg extends KeyOrCallback<Item, Key>, ValueArg extends KeyOrCallback<Item>>(array: Item[], key: KeyArg, value: ValueArg): Map<KeyOrCallbackKey<Item, KeyArg>, KeyOrCallbackValue<Item, ValueArg>>;
|
|
23
23
|
/**
|
|
24
|
-
* Create a _Map_ from an array of items using a
|
|
25
|
-
*
|
|
26
|
-
* If multiple items have the same key, the latest item's value will be used
|
|
27
|
-
*
|
|
28
|
-
* @param array Array to convert
|
|
29
|
-
* @param key Callback to get an item's grouping key
|
|
30
|
-
* @param value Key to use for value
|
|
31
|
-
* @returns _Map_ of keyed values
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```typescript
|
|
35
|
-
* toMap(
|
|
36
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
37
|
-
* item => item.value,
|
|
38
|
-
* 'id',
|
|
39
|
-
* ); // => Map { 10 => 3, 20 => 2 }
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
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]>;
|
|
43
|
-
/**
|
|
44
|
-
* Create a _Map_ from an array of items using a key and callback
|
|
45
|
-
*
|
|
46
|
-
* If multiple items have the same key, the latest item's value will be used
|
|
47
|
-
*
|
|
48
|
-
* @param array Array to convert
|
|
49
|
-
* @param key Key to use for grouping
|
|
50
|
-
* @param value Callback to get an item's value
|
|
51
|
-
* @returns _Map_ of keyed values
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```typescript
|
|
55
|
-
* toMap(
|
|
56
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
57
|
-
* 'value',
|
|
58
|
-
* item => item.id,
|
|
59
|
-
* ); // => Map { 10 => 3, 20 => 2 }
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ValueCallback): Map<Item[ItemKey], ReturnType<ValueCallback>>;
|
|
63
|
-
/**
|
|
64
|
-
* Create a _Map_ from an array of items using a key and value
|
|
65
|
-
*
|
|
66
|
-
* If multiple items have the same key, the latest item's value will be used
|
|
67
|
-
*
|
|
68
|
-
* @param array Array to convert
|
|
69
|
-
* @param key Key to use for grouping
|
|
70
|
-
* @param value Key to use for value
|
|
71
|
-
* @returns _Map_ of keyed values
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* ```typescript
|
|
75
|
-
* toMap(
|
|
76
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
77
|
-
* 'value',
|
|
78
|
-
* 'id',
|
|
79
|
-
* ); // => Map { 10 => 3, 20 => 2 }
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Map<Item[ItemKey], Item[ItemValue]>;
|
|
83
|
-
/**
|
|
84
|
-
* Create a _Map_ from an array of items using a callback
|
|
24
|
+
* Create a _Map_ from an array of items using a specific key
|
|
85
25
|
*
|
|
86
26
|
* If multiple items have the same key, the latest item will be used
|
|
87
27
|
*
|
|
88
28
|
* @param array Array to convert
|
|
89
|
-
* @param
|
|
29
|
+
* @param key Callback or key to use for grouping
|
|
90
30
|
* @returns _Map_ of keyed items
|
|
91
31
|
*
|
|
92
32
|
* @example
|
|
@@ -97,25 +37,7 @@ declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, Ite
|
|
|
97
37
|
* ); // => Map { 10 => {id: 3, value: 10}, 20 => {id: 2, value: 20} }
|
|
98
38
|
* ```
|
|
99
39
|
*/
|
|
100
|
-
declare function toMap<Item,
|
|
101
|
-
/**
|
|
102
|
-
* Create a _Map_ from an array of items using a key
|
|
103
|
-
*
|
|
104
|
-
* If multiple items have the same key, the latest item will be used
|
|
105
|
-
*
|
|
106
|
-
* @param array Array to convert
|
|
107
|
-
* @param key Key to use for grouping
|
|
108
|
-
* @returns _Map_ of keyed items
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* ```typescript
|
|
112
|
-
* toMap(
|
|
113
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
114
|
-
* 'value',
|
|
115
|
-
* ); // => Map { 10 => {id: 3, value: 10}, 20 => {id: 2, value: 20} }
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
declare function toMap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Map<Item[ItemKey], Item>;
|
|
40
|
+
declare function toMap<Item, KeyArg extends KeyOrCallback<Item, Key>>(array: Item[], key: KeyArg): Map<KeyOrCallbackKey<Item, KeyArg>, Item>;
|
|
119
41
|
/**
|
|
120
42
|
* Create a _Map_ from an array of items _(using indices as keys)_
|
|
121
43
|
*
|
|
@@ -134,13 +56,13 @@ declare namespace toMap {
|
|
|
134
56
|
var arrays: typeof toMapArrays;
|
|
135
57
|
}
|
|
136
58
|
/**
|
|
137
|
-
* Create a _Map_ from an array of items using
|
|
59
|
+
* Create a _Map_ from an array of items using a specific key, grouping values into arrays
|
|
138
60
|
*
|
|
139
61
|
* _Available as `toMapArrays` and `toMap.arrays`_
|
|
140
62
|
*
|
|
141
63
|
* @param array Array to convert
|
|
142
|
-
* @param key Callback to
|
|
143
|
-
* @param value Callback to
|
|
64
|
+
* @param key Callback or key to use for grouping
|
|
65
|
+
* @param value Callback or key to use for value, defaulting to the item itself
|
|
144
66
|
* @returns _Map_ of keyed arrays of values
|
|
145
67
|
*
|
|
146
68
|
* @example
|
|
@@ -152,74 +74,14 @@ declare namespace toMap {
|
|
|
152
74
|
* ); // => Map { 10 => [1, 3], 20 => [2] }
|
|
153
75
|
* ```
|
|
154
76
|
*/
|
|
155
|
-
declare function toMapArrays<Item,
|
|
77
|
+
declare function toMapArrays<Item, KeyArg extends KeyOrCallback<Item, Key>, ValueArg extends KeyOrCallback<Item>>(array: Item[], key: KeyArg, value: ValueArg): Map<KeyOrCallbackKey<Item, KeyArg>, Array<KeyOrCallbackValue<Item, ValueArg>>>;
|
|
156
78
|
/**
|
|
157
|
-
* Create a _Map_ from an array of items using a
|
|
79
|
+
* Create a _Map_ from an array of items using a specific key, grouping items into arrays
|
|
158
80
|
*
|
|
159
81
|
* _Available as `toMapArrays` and `toMap.arrays`_
|
|
160
82
|
*
|
|
161
83
|
* @param array Array to convert
|
|
162
|
-
* @param key Callback to
|
|
163
|
-
* @param value Key to use for value
|
|
164
|
-
* @returns _Map_ of keyed arrays of values
|
|
165
|
-
*
|
|
166
|
-
* @example
|
|
167
|
-
* ```typescript
|
|
168
|
-
* toMapArrays(
|
|
169
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
170
|
-
* item => item.value,
|
|
171
|
-
* 'id',
|
|
172
|
-
* ); // => Map { 10 => [1, 3], 20 => [2] }
|
|
173
|
-
* ```
|
|
174
|
-
*/
|
|
175
|
-
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][]>;
|
|
176
|
-
/**
|
|
177
|
-
* Create a _Map_ from an array of items using a key and callback, grouping values into arrays
|
|
178
|
-
*
|
|
179
|
-
* _Available as `toMapArrays` and `toMap.arrays`_
|
|
180
|
-
*
|
|
181
|
-
* @param array Array to convert
|
|
182
|
-
* @param key Key to use for grouping
|
|
183
|
-
* @param value Callback to get an item's value
|
|
184
|
-
* @returns _Map_ of keyed arrays of values
|
|
185
|
-
*
|
|
186
|
-
* @example
|
|
187
|
-
* ```typescript
|
|
188
|
-
* toMapArrays(
|
|
189
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
190
|
-
* 'value',
|
|
191
|
-
* item => item.id,
|
|
192
|
-
* ); // => Map { 10 => [1, 3], 20 => [2] }
|
|
193
|
-
* ```
|
|
194
|
-
*/
|
|
195
|
-
declare function toMapArrays<Item extends PlainObject, ItemKey extends keyof Item, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ValueCallback): Map<Item[ItemKey], Array<ReturnType<ValueCallback>>>;
|
|
196
|
-
/**
|
|
197
|
-
* Create a _Map_ from an array of items using a key and value, grouping values into arrays
|
|
198
|
-
*
|
|
199
|
-
* _Available as `toMapArrays` and `toMap.arrays`_
|
|
200
|
-
*
|
|
201
|
-
* @param array Array to convert
|
|
202
|
-
* @param key Key to use for grouping
|
|
203
|
-
* @param value Key to use for value
|
|
204
|
-
* @returns _Map_ of keyed arrays of values
|
|
205
|
-
*
|
|
206
|
-
* @example
|
|
207
|
-
* ```typescript
|
|
208
|
-
* toMapArrays(
|
|
209
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
210
|
-
* 'value',
|
|
211
|
-
* 'id',
|
|
212
|
-
* ); // => Map { 10 => [1, 3], 20 => [2] }
|
|
213
|
-
* ```
|
|
214
|
-
*/
|
|
215
|
-
declare function toMapArrays<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Map<Item[ItemKey], Item[ItemValue][]>;
|
|
216
|
-
/**
|
|
217
|
-
* Create a _Map_ from an array of items using a callback, grouping items into arrays
|
|
218
|
-
*
|
|
219
|
-
* _Available as `toMapArrays` and `toMap.arrays`_
|
|
220
|
-
*
|
|
221
|
-
* @param array Array to convert
|
|
222
|
-
* @param callback Callback to get an item's grouping key
|
|
84
|
+
* @param key Callback or key to use for grouping
|
|
223
85
|
* @returns _Map_ of keyed arrays of items
|
|
224
86
|
*
|
|
225
87
|
* @example
|
|
@@ -230,24 +92,6 @@ declare function toMapArrays<Item extends PlainObject, ItemKey extends keyof Ite
|
|
|
230
92
|
* ); // => Map { 10 => [{id: 1, value: 10}, {id: 3, value: 10}], 20 => [{id: 2, value: 20}] }
|
|
231
93
|
* ```
|
|
232
94
|
*/
|
|
233
|
-
declare function toMapArrays<Item,
|
|
234
|
-
/**
|
|
235
|
-
* Create a _Map_ from an array of items using a key, grouping items into arrays
|
|
236
|
-
*
|
|
237
|
-
* _Available as `toMapArrays` and `toMap.arrays`_
|
|
238
|
-
*
|
|
239
|
-
* @param array Array to convert
|
|
240
|
-
* @param key Key to use for grouping
|
|
241
|
-
* @returns _Map_ of keyed arrays of items
|
|
242
|
-
*
|
|
243
|
-
* @example
|
|
244
|
-
* ```typescript
|
|
245
|
-
* toMapArrays(
|
|
246
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
247
|
-
* 'value',
|
|
248
|
-
* ); // => Map { 10 => [{id: 1, value: 10}, {id: 3, value: 10}], 20 => [{id: 2, value: 20}] }
|
|
249
|
-
* ```
|
|
250
|
-
*/
|
|
251
|
-
declare function toMapArrays<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Map<Item[ItemKey], Item[]>;
|
|
95
|
+
declare function toMapArrays<Item, KeyArg extends KeyOrCallback<Item, Key>>(array: Item[], key: KeyArg): Map<KeyOrCallbackKey<Item, KeyArg>, Item[]>;
|
|
252
96
|
//#endregion
|
|
253
97
|
export { toMap, toMapArrays };
|