@oscarpalmer/atoms 0.184.2 → 0.186.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/difference.d.mts +29 -0
- package/dist/array/exists.d.mts +35 -0
- package/dist/array/filter.d.mts +72 -2
- package/dist/array/find.d.mts +70 -0
- package/dist/array/first.d.mts +77 -2
- package/dist/array/flatten.d.mts +6 -0
- package/dist/array/flatten.mjs +6 -0
- package/dist/array/from.d.mts +36 -0
- package/dist/array/get.d.mts +21 -13
- package/dist/array/group-by.d.mts +142 -0
- package/dist/array/index.d.mts +2 -2
- package/dist/array/index.mjs +2 -2
- package/dist/array/insert.d.mts +16 -0
- package/dist/array/intersection.d.mts +29 -0
- package/dist/array/last.d.mts +75 -2
- package/dist/array/{position.d.mts → match.d.mts} +168 -36
- package/dist/array/{position.mjs → match.mjs} +16 -16
- package/dist/array/move.d.mts +78 -8
- package/dist/array/move.mjs +11 -1
- package/dist/array/partition.d.mts +35 -0
- package/dist/array/push.d.mts +8 -0
- package/dist/array/push.mjs +8 -0
- package/dist/array/reverse.d.mts +1 -0
- package/dist/array/reverse.mjs +1 -0
- package/dist/array/select.d.mts +94 -8
- package/dist/array/single.d.mts +29 -0
- package/dist/array/slice.d.mts +106 -16
- package/dist/array/sort.d.mts +30 -4
- package/dist/array/sort.mjs +1 -1
- package/dist/array/splice.d.mts +48 -0
- package/dist/array/splice.mjs +2 -1
- package/dist/array/swap.d.mts +113 -8
- package/dist/array/swap.mjs +2 -1
- package/dist/array/to-map.d.mts +124 -0
- package/dist/array/to-record.d.mts +124 -0
- package/dist/array/to-set.d.mts +24 -0
- package/dist/array/toggle.d.mts +38 -3
- package/dist/array/union.d.mts +29 -0
- package/dist/array/unique.d.mts +24 -0
- package/dist/array/update.d.mts +38 -3
- package/dist/beacon.d.mts +12 -0
- package/dist/beacon.mjs +9 -0
- package/dist/color/instance.d.mts +8 -0
- package/dist/color/instance.mjs +3 -0
- package/dist/color/models.d.mts +30 -0
- package/dist/function/assert.d.mts +29 -8
- package/dist/function/assert.mjs +29 -8
- package/dist/function/memoize.d.mts +3 -0
- package/dist/function/memoize.mjs +3 -0
- package/dist/function/retry.d.mts +3 -0
- package/dist/function/retry.mjs +3 -0
- package/dist/function/work.mjs +1 -1
- package/dist/index.d.mts +2158 -288
- package/dist/index.mjs +294 -181
- package/dist/internal/array/chunk.d.mts +6 -0
- package/dist/internal/array/chunk.mjs +6 -0
- package/dist/internal/array/compact.d.mts +12 -0
- package/dist/internal/array/index-of.d.mts +70 -0
- package/dist/internal/math/aggregate.d.mts +29 -0
- package/dist/internal/value/compare.d.mts +2 -1
- package/dist/internal/value/equal.d.mts +5 -0
- package/dist/internal/value/get.d.mts +27 -5
- package/dist/internal/value/has.d.mts +7 -7
- package/dist/internal/value/has.mjs +1 -1
- package/dist/internal/value/misc.d.mts +2 -2
- package/dist/internal/value/misc.mjs +10 -4
- package/dist/logger.d.mts +11 -0
- package/dist/logger.mjs +11 -0
- package/dist/models.d.mts +14 -1
- package/dist/promise/helpers.mjs +1 -1
- package/dist/promise/index.d.mts +0 -6
- package/dist/promise/models.d.mts +36 -0
- package/dist/promise/models.mjs +6 -0
- package/dist/queue.d.mts +13 -1
- package/dist/queue.mjs +9 -0
- package/dist/result/index.d.mts +0 -8
- package/dist/result/index.mjs +0 -8
- package/dist/result/match.d.mts +4 -4
- package/dist/result/work/flow.d.mts +12 -36
- package/dist/result/work/pipe.d.mts +11 -33
- package/dist/sized/set.d.mts +3 -2
- package/dist/sized/set.mjs +3 -2
- package/dist/value/collection.d.mts +1 -1
- package/dist/value/handle.mjs +1 -1
- package/dist/value/merge.d.mts +28 -25
- package/dist/value/merge.mjs +29 -18
- package/dist/value/shake.d.mts +3 -0
- package/dist/value/smush.d.mts +3 -0
- package/dist/value/transform.d.mts +10 -1
- package/dist/value/unsmush.d.mts +2 -3
- package/package.json +5 -5
- package/src/array/difference.ts +33 -0
- package/src/array/exists.ts +35 -0
- package/src/array/filter.ts +72 -2
- package/src/array/find.ts +70 -0
- package/src/array/first.ts +77 -3
- package/src/array/flatten.ts +6 -0
- package/src/array/from.ts +40 -0
- package/src/array/get.ts +21 -15
- package/src/array/group-by.ts +142 -0
- package/src/array/index.ts +1 -1
- package/src/array/insert.ts +16 -2
- package/src/array/intersection.ts +33 -0
- package/src/array/last.ts +75 -2
- package/src/array/{position.ts → match.ts} +197 -65
- package/src/array/move.ts +87 -13
- package/src/array/partition.ts +35 -0
- package/src/array/push.ts +8 -2
- package/src/array/reverse.ts +5 -0
- package/src/array/select.ts +96 -13
- package/src/array/single.ts +29 -0
- package/src/array/slice.ts +114 -24
- package/src/array/sort.ts +30 -4
- package/src/array/splice.ts +52 -4
- package/src/array/swap.ts +122 -13
- package/src/array/to-map.ts +124 -0
- package/src/array/to-record.ts +124 -0
- package/src/array/to-set.ts +24 -0
- package/src/array/toggle.ts +42 -3
- package/src/array/union.ts +33 -0
- package/src/array/unique.ts +24 -0
- package/src/array/update.ts +38 -3
- package/src/beacon.ts +12 -0
- package/src/color/index.ts +0 -3
- package/src/color/instance.ts +9 -1
- package/src/color/models.ts +30 -0
- package/src/function/assert.ts +66 -7
- package/src/function/memoize.ts +3 -0
- package/src/function/once.ts +5 -1
- package/src/function/retry.ts +3 -0
- package/src/internal/array/chunk.ts +6 -0
- package/src/internal/array/compact.ts +12 -0
- package/src/internal/array/index-of.ts +70 -0
- package/src/internal/math/aggregate.ts +29 -0
- package/src/internal/string.ts +0 -2
- package/src/internal/value/compare.ts +2 -1
- package/src/internal/value/equal.ts +5 -0
- package/src/internal/value/get.ts +27 -5
- package/src/internal/value/has.ts +10 -10
- package/src/internal/value/misc.ts +24 -13
- package/src/logger.ts +11 -0
- package/src/models.ts +18 -0
- package/src/promise/index.ts +0 -6
- package/src/promise/models.ts +36 -0
- package/src/queue.ts +13 -1
- package/src/result/index.ts +0 -8
- package/src/result/match.ts +4 -4
- package/src/result/work/flow.ts +12 -36
- package/src/result/work/pipe.ts +11 -33
- package/src/sized/set.ts +4 -3
- package/src/value/collection.ts +1 -1
- package/src/value/merge.ts +88 -66
- package/src/value/shake.ts +3 -0
- package/src/value/smush.ts +3 -0
- package/src/value/transform.ts +10 -1
- package/src/value/unsmush.ts +2 -8
package/src/array/to-map.ts
CHANGED
|
@@ -43,10 +43,20 @@ function getMapValues(
|
|
|
43
43
|
* Create a Map from an array of items using callbacks
|
|
44
44
|
*
|
|
45
45
|
* If multiple items have the same key, the latest item's value will be used
|
|
46
|
+
*
|
|
46
47
|
* @param array Array to convert
|
|
47
48
|
* @param key Callback to get an item's grouping key
|
|
48
49
|
* @param value Callback to get an item's value
|
|
49
50
|
* @returns Map of keyed values
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* toMap(
|
|
55
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
56
|
+
* item => item.value,
|
|
57
|
+
* item => item.id,
|
|
58
|
+
* ); // => Map { 10 => 3, 20 => 2 }
|
|
59
|
+
* ```
|
|
50
60
|
*/
|
|
51
61
|
export function toMap<
|
|
52
62
|
Item,
|
|
@@ -62,10 +72,20 @@ export function toMap<
|
|
|
62
72
|
* Create a Map from an array of items using a callback and value
|
|
63
73
|
*
|
|
64
74
|
* If multiple items have the same key, the latest item's value will be used
|
|
75
|
+
*
|
|
65
76
|
* @param array Array to convert
|
|
66
77
|
* @param key Callback to get an item's grouping key
|
|
67
78
|
* @param value Key to use for value
|
|
68
79
|
* @returns Map of keyed values
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* toMap(
|
|
84
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
85
|
+
* item => item.value,
|
|
86
|
+
* 'id',
|
|
87
|
+
* ); // => Map { 10 => 3, 20 => 2 }
|
|
88
|
+
* ```
|
|
69
89
|
*/
|
|
70
90
|
export function toMap<
|
|
71
91
|
Item extends PlainObject,
|
|
@@ -77,10 +97,20 @@ export function toMap<
|
|
|
77
97
|
* Create a Map from an array of items using a key and callback
|
|
78
98
|
*
|
|
79
99
|
* If multiple items have the same key, the latest item's value will be used
|
|
100
|
+
*
|
|
80
101
|
* @param array Array to convert
|
|
81
102
|
* @param key Key to use for grouping
|
|
82
103
|
* @param value Callback to get an item's value
|
|
83
104
|
* @returns Map of keyed values
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* toMap(
|
|
109
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
110
|
+
* 'value',
|
|
111
|
+
* item => item.id,
|
|
112
|
+
* ); // => Map { 10 => 3, 20 => 2 }
|
|
113
|
+
* ```
|
|
84
114
|
*/
|
|
85
115
|
export function toMap<
|
|
86
116
|
Item extends PlainObject,
|
|
@@ -92,10 +122,20 @@ export function toMap<
|
|
|
92
122
|
* Create a Map from an array of items using a key and value
|
|
93
123
|
*
|
|
94
124
|
* If multiple items have the same key, the latest item's value will be used
|
|
125
|
+
*
|
|
95
126
|
* @param array Array to convert
|
|
96
127
|
* @param key Key to use for grouping
|
|
97
128
|
* @param value Key to use for value
|
|
98
129
|
* @returns Map of keyed values
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* toMap(
|
|
134
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
135
|
+
* 'value',
|
|
136
|
+
* 'id',
|
|
137
|
+
* ); // => Map { 10 => 3, 20 => 2 }
|
|
138
|
+
* ```
|
|
99
139
|
*/
|
|
100
140
|
export function toMap<
|
|
101
141
|
Item extends PlainObject,
|
|
@@ -107,9 +147,18 @@ export function toMap<
|
|
|
107
147
|
* Create a Map from an array of items using a callback
|
|
108
148
|
*
|
|
109
149
|
* If multiple items have the same key, the latest item will be used
|
|
150
|
+
*
|
|
110
151
|
* @param array Array to convert
|
|
111
152
|
* @param callback Callback to get an item's grouping key
|
|
112
153
|
* @returns Map of keyed items
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* toMap(
|
|
158
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
159
|
+
* item => item.value,
|
|
160
|
+
* ); // => Map { 10 => {id: 3, value: 10}, 20 => {id: 2, value: 20} }
|
|
161
|
+
* ```
|
|
113
162
|
*/
|
|
114
163
|
export function toMap<Item, Callback extends (item: Item, index: number, array: Item[]) => Key>(
|
|
115
164
|
array: Item[],
|
|
@@ -120,9 +169,18 @@ export function toMap<Item, Callback extends (item: Item, index: number, array:
|
|
|
120
169
|
* Create a Map from an array of items using a key
|
|
121
170
|
*
|
|
122
171
|
* If multiple items have the same key, the latest item will be used
|
|
172
|
+
*
|
|
123
173
|
* @param array Array to convert
|
|
124
174
|
* @param key Key to use for grouping
|
|
125
175
|
* @returns Map of keyed items
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* toMap(
|
|
180
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
181
|
+
* 'value',
|
|
182
|
+
* ); // => Map { 10 => {id: 3, value: 10}, 20 => {id: 2, value: 20} }
|
|
183
|
+
* ```
|
|
126
184
|
*/
|
|
127
185
|
export function toMap<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
128
186
|
array: Item[],
|
|
@@ -131,8 +189,16 @@ export function toMap<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
|
131
189
|
|
|
132
190
|
/**
|
|
133
191
|
* Create a Map from an array of items _(using indices as keys)_
|
|
192
|
+
*
|
|
134
193
|
* @param array Array to convert
|
|
135
194
|
* @returns Map of indiced items
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```typescript
|
|
198
|
+
* toMap(
|
|
199
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
200
|
+
* ); // => Map { 0 => {id: 1, value: 10}, 1 => {id: 2, value: 20}, 2 => {id: 3, value: 10} }
|
|
201
|
+
* ```
|
|
136
202
|
*/
|
|
137
203
|
export function toMap<Item>(array: Item[]): Map<number, Item>;
|
|
138
204
|
|
|
@@ -146,10 +212,20 @@ toMap.arrays = toMapArrays;
|
|
|
146
212
|
* Create a Map from an array of items using callbacks, grouping values into arrays
|
|
147
213
|
*
|
|
148
214
|
* Available as `toMapArrays` and `toMap.arrays`
|
|
215
|
+
*
|
|
149
216
|
* @param array Array to convert
|
|
150
217
|
* @param key Callback to get an item's grouping key
|
|
151
218
|
* @param value Callback to get an item's value
|
|
152
219
|
* @returns Map of keyed arrays of values
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* toMapArrays(
|
|
224
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
225
|
+
* item => item.value,
|
|
226
|
+
* item => item.id,
|
|
227
|
+
* ); // => Map { 10 => [1, 3], 20 => [2] }
|
|
228
|
+
* ```
|
|
153
229
|
*/
|
|
154
230
|
export function toMapArrays<
|
|
155
231
|
Item,
|
|
@@ -165,10 +241,20 @@ export function toMapArrays<
|
|
|
165
241
|
* Create a Map from an array of items using a callback and value, grouping values into arrays
|
|
166
242
|
*
|
|
167
243
|
* Available as `toMapArrays` and `toMap.arrays`
|
|
244
|
+
*
|
|
168
245
|
* @param array Array to convert
|
|
169
246
|
* @param key Callback to get an item's grouping key
|
|
170
247
|
* @param value Key to use for value
|
|
171
248
|
* @returns Map of keyed arrays of values
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```typescript
|
|
252
|
+
* toMapArrays(
|
|
253
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
254
|
+
* item => item.value,
|
|
255
|
+
* 'id',
|
|
256
|
+
* ); // => Map { 10 => [1, 3], 20 => [2] }
|
|
257
|
+
* ```
|
|
172
258
|
*/
|
|
173
259
|
export function toMapArrays<
|
|
174
260
|
Item extends PlainObject,
|
|
@@ -184,10 +270,20 @@ export function toMapArrays<
|
|
|
184
270
|
* Create a Map from an array of items using a key and callback, grouping values into arrays
|
|
185
271
|
*
|
|
186
272
|
* Available as `toMapArrays` and `toMap.arrays`
|
|
273
|
+
*
|
|
187
274
|
* @param array Array to convert
|
|
188
275
|
* @param key Key to use for grouping
|
|
189
276
|
* @param value Callback to get an item's value
|
|
190
277
|
* @returns Map of keyed arrays of values
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```typescript
|
|
281
|
+
* toMapArrays(
|
|
282
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
283
|
+
* 'value',
|
|
284
|
+
* item => item.id,
|
|
285
|
+
* ); // => Map { 10 => [1, 3], 20 => [2] }
|
|
286
|
+
* ```
|
|
191
287
|
*/
|
|
192
288
|
export function toMapArrays<
|
|
193
289
|
Item extends PlainObject,
|
|
@@ -203,10 +299,20 @@ export function toMapArrays<
|
|
|
203
299
|
* Create a Map from an array of items using a key and value, grouping values into arrays
|
|
204
300
|
*
|
|
205
301
|
* Available as `toMapArrays` and `toMap.arrays`
|
|
302
|
+
*
|
|
206
303
|
* @param array Array to convert
|
|
207
304
|
* @param key Key to use for grouping
|
|
208
305
|
* @param value Key to use for value
|
|
209
306
|
* @returns Map of keyed arrays of values
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```typescript
|
|
310
|
+
* toMapArrays(
|
|
311
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
312
|
+
* 'value',
|
|
313
|
+
* 'id',
|
|
314
|
+
* ); // => Map { 10 => [1, 3], 20 => [2] }
|
|
315
|
+
* ```
|
|
210
316
|
*/
|
|
211
317
|
export function toMapArrays<
|
|
212
318
|
Item extends PlainObject,
|
|
@@ -218,9 +324,18 @@ export function toMapArrays<
|
|
|
218
324
|
* Create a Map from an array of items using a callback, grouping items into arrays
|
|
219
325
|
*
|
|
220
326
|
* Available as `toMapArrays` and `toMap.arrays`
|
|
327
|
+
*
|
|
221
328
|
* @param array Array to convert
|
|
222
329
|
* @param callback Callback to get an item's grouping key
|
|
223
330
|
* @returns Map of keyed arrays of items
|
|
331
|
+
*
|
|
332
|
+
* @example
|
|
333
|
+
* ```typescript
|
|
334
|
+
* toMapArrays(
|
|
335
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
336
|
+
* item => item.value,
|
|
337
|
+
* ); // => Map { 10 => [{id: 1, value: 10}, {id: 3, value: 10}], 20 => [{id: 2, value: 20}] }
|
|
338
|
+
* ```
|
|
224
339
|
*/
|
|
225
340
|
export function toMapArrays<
|
|
226
341
|
Item,
|
|
@@ -231,9 +346,18 @@ export function toMapArrays<
|
|
|
231
346
|
* Create a Map from an array of items using a key, grouping items into arrays
|
|
232
347
|
*
|
|
233
348
|
* Available as `toMapArrays` and `toMap.arrays`
|
|
349
|
+
*
|
|
234
350
|
* @param array Array to convert
|
|
235
351
|
* @param key Key to use for grouping
|
|
236
352
|
* @returns Map of keyed arrays of items
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* ```typescript
|
|
356
|
+
* toMapArrays(
|
|
357
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
358
|
+
* 'value',
|
|
359
|
+
* ); // => Map { 10 => [{id: 1, value: 10}, {id: 3, value: 10}], 20 => [{id: 2, value: 20}] }
|
|
360
|
+
* ```
|
|
237
361
|
*/
|
|
238
362
|
export function toMapArrays<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
239
363
|
array: Item[],
|
package/src/array/to-record.ts
CHANGED
|
@@ -7,10 +7,20 @@ import type {Key, KeyedValue, PlainObject, Simplify} from '../models';
|
|
|
7
7
|
* Create a record from an array of items using callbacks
|
|
8
8
|
*
|
|
9
9
|
* If multiple items have the same key, the latest item will be used
|
|
10
|
+
*
|
|
10
11
|
* @param array Array to convert
|
|
11
12
|
* @param key Callback to get an item's grouping key
|
|
12
13
|
* @param value Callback to get an item's value
|
|
13
14
|
* @returns Record of keyed values
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* toRecord(
|
|
19
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
20
|
+
* item => item.value,
|
|
21
|
+
* item => item.id,
|
|
22
|
+
* ); // => { 10: 3, 20: 2 }
|
|
23
|
+
* ```
|
|
14
24
|
*/
|
|
15
25
|
export function toRecord<
|
|
16
26
|
Item,
|
|
@@ -26,10 +36,20 @@ export function toRecord<
|
|
|
26
36
|
* Create a record from an array of items using a callback and value
|
|
27
37
|
*
|
|
28
38
|
* If multiple items have the same key, the latest item will be used
|
|
39
|
+
*
|
|
29
40
|
* @param array Array to convert
|
|
30
41
|
* @param callback Callback to get an item's grouping key
|
|
31
42
|
* @param value Key to use for value
|
|
32
43
|
* @returns Record with keys
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* toRecord(
|
|
48
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
49
|
+
* item => item.value,
|
|
50
|
+
* 'id',
|
|
51
|
+
* ); // => { 10: 3, 20: 2 }
|
|
52
|
+
* ```
|
|
33
53
|
*/
|
|
34
54
|
export function toRecord<
|
|
35
55
|
Item extends PlainObject,
|
|
@@ -45,10 +65,20 @@ export function toRecord<
|
|
|
45
65
|
* Create a record from an array of items using a key and callback
|
|
46
66
|
*
|
|
47
67
|
* If multiple items have the same key, the latest item will be used
|
|
68
|
+
*
|
|
48
69
|
* @param array Array to convert
|
|
49
70
|
* @param key Key to use for grouping
|
|
50
71
|
* @param callback Callback to get an item's value
|
|
51
72
|
* @returns Record with keys
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* toRecord(
|
|
77
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
78
|
+
* 'value',
|
|
79
|
+
* item => item.id,
|
|
80
|
+
* ); // => { 10: 3, 20: 2 }
|
|
81
|
+
* ```
|
|
52
82
|
*/
|
|
53
83
|
export function toRecord<
|
|
54
84
|
Item extends PlainObject,
|
|
@@ -64,10 +94,20 @@ export function toRecord<
|
|
|
64
94
|
* Create a record from an array of items using a key and value
|
|
65
95
|
*
|
|
66
96
|
* If multiple items have the same key, the latest item will be used
|
|
97
|
+
*
|
|
67
98
|
* @param array Array to convert
|
|
68
99
|
* @param key Key to use for grouping
|
|
69
100
|
* @param value Key to use for value
|
|
70
101
|
* @returns Record of keyed values
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* toRecord(
|
|
106
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
107
|
+
* 'value',
|
|
108
|
+
* 'id',
|
|
109
|
+
* ); // => { 10: 3, 20: 2 }
|
|
110
|
+
* ```
|
|
71
111
|
*/
|
|
72
112
|
export function toRecord<
|
|
73
113
|
Item extends PlainObject,
|
|
@@ -83,9 +123,18 @@ export function toRecord<
|
|
|
83
123
|
* Create a record from an array of items using a callback
|
|
84
124
|
*
|
|
85
125
|
* If multiple items have the same key, the latest item will be used
|
|
126
|
+
*
|
|
86
127
|
* @param array Array to convert
|
|
87
128
|
* @param callback Callback to get an item's grouping key
|
|
88
129
|
* @returns Record of keyed values
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* toRecord(
|
|
134
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
135
|
+
* item => item.value,
|
|
136
|
+
* ); // => { 10: {id: 3, value: 10}, 20: {id: 2, value: 20} }
|
|
137
|
+
* ```
|
|
89
138
|
*/
|
|
90
139
|
export function toRecord<Item, Callback extends (item: Item, index: number, array: Item[]) => Key>(
|
|
91
140
|
array: Item[],
|
|
@@ -96,9 +145,18 @@ export function toRecord<Item, Callback extends (item: Item, index: number, arra
|
|
|
96
145
|
* Create a record from an array of items using a key
|
|
97
146
|
*
|
|
98
147
|
* If multiple items have the same key, the latest item will be used
|
|
148
|
+
*
|
|
99
149
|
* @param array Array to convert
|
|
100
150
|
* @param key Key to use for grouping
|
|
101
151
|
* @returns Record of keyed values
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* toRecord(
|
|
156
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
157
|
+
* 'value',
|
|
158
|
+
* ); // => { 10: {id: 3, value: 10}, 20: {id: 2, value: 20} }
|
|
159
|
+
* ```
|
|
102
160
|
*/
|
|
103
161
|
export function toRecord<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
104
162
|
array: Item[],
|
|
@@ -107,8 +165,16 @@ export function toRecord<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
|
107
165
|
|
|
108
166
|
/**
|
|
109
167
|
* Create a record from an array of items _(using indices as keys)_
|
|
168
|
+
*
|
|
110
169
|
* @param array Array to convert
|
|
111
170
|
* @returns Record of indiced values
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* toRecord(
|
|
175
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
176
|
+
* ); // => { 0: {id: 1, value: 10}, 1: {id: 2, value: 20}, 2: {id: 3, value: 10} }
|
|
177
|
+
* ```
|
|
112
178
|
*/
|
|
113
179
|
export function toRecord<Item>(array: Item[]): Record<number, Item>;
|
|
114
180
|
|
|
@@ -122,10 +188,20 @@ toRecord.arrays = toRecordArrays;
|
|
|
122
188
|
* Create a record from an array of items using callbacks, grouping values into arrays
|
|
123
189
|
*
|
|
124
190
|
* Available as `toRecordArrays` and `toRecord.arrays`
|
|
191
|
+
*
|
|
125
192
|
* @param array Array to convert
|
|
126
193
|
* @param key Callback to get an item's grouping key
|
|
127
194
|
* @param value Callback to get an item's value
|
|
128
195
|
* @returns Record of keyed arrays of values
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* toRecordArrays(
|
|
200
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
201
|
+
* item => item.value,
|
|
202
|
+
* item => item.id,
|
|
203
|
+
* ); // => { 10: [1, 3], 20: [2] }
|
|
204
|
+
* ```
|
|
129
205
|
*/
|
|
130
206
|
export function toRecordArrays<
|
|
131
207
|
Item,
|
|
@@ -141,10 +217,20 @@ export function toRecordArrays<
|
|
|
141
217
|
* Create a record from an array of items using a callback and value, grouping values into arrays
|
|
142
218
|
*
|
|
143
219
|
* Available as `toRecordArrays` and `toRecord.arrays`
|
|
220
|
+
*
|
|
144
221
|
* @param array Array to convert
|
|
145
222
|
* @param callback Callback to get an item's grouping key
|
|
146
223
|
* @param value Key to use for value
|
|
147
224
|
* @returns Record of keyed arrays of values
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```typescript
|
|
228
|
+
* toRecordArrays(
|
|
229
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
230
|
+
* item => item.value,
|
|
231
|
+
* 'id',
|
|
232
|
+
* ); // => { 10: [1, 3], 20: [2] }
|
|
233
|
+
* ```
|
|
148
234
|
*/
|
|
149
235
|
export function toRecordArrays<
|
|
150
236
|
Item extends PlainObject,
|
|
@@ -160,10 +246,20 @@ export function toRecordArrays<
|
|
|
160
246
|
* Create a record from an array of items using a key and callback, grouping values into arrays
|
|
161
247
|
*
|
|
162
248
|
* Available as `toRecordArrays` and `toRecord.arrays`
|
|
249
|
+
*
|
|
163
250
|
* @param array Array to convert
|
|
164
251
|
* @param key Key to use for grouping
|
|
165
252
|
* @param callback Callback to get an item's value
|
|
166
253
|
* @returns Record of keyed arrays of values
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* ```typescript
|
|
257
|
+
* toRecordArrays(
|
|
258
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
259
|
+
* 'value',
|
|
260
|
+
* item => item.id,
|
|
261
|
+
* ); // => { 10: [1, 3], 20: [2] }
|
|
262
|
+
* ```
|
|
167
263
|
*/
|
|
168
264
|
export function toRecordArrays<
|
|
169
265
|
Item extends PlainObject,
|
|
@@ -179,10 +275,20 @@ export function toRecordArrays<
|
|
|
179
275
|
* Create a record from an array of items using a key and value, grouping values into arrays
|
|
180
276
|
*
|
|
181
277
|
* Available as `toRecordArrays` and `toRecord.arrays`
|
|
278
|
+
*
|
|
182
279
|
* @param array Array to convert
|
|
183
280
|
* @param key Key to use for grouping
|
|
184
281
|
* @param value Key to use for value
|
|
185
282
|
* @returns Record of keyed arrays of values
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```typescript
|
|
286
|
+
* toRecordArrays(
|
|
287
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
288
|
+
* 'value',
|
|
289
|
+
* 'id',
|
|
290
|
+
* ); // => { 10: [1, 3], 20: [2] }
|
|
291
|
+
* ```
|
|
186
292
|
*/
|
|
187
293
|
export function toRecordArrays<
|
|
188
294
|
Item extends PlainObject,
|
|
@@ -198,9 +304,18 @@ export function toRecordArrays<
|
|
|
198
304
|
* Create a record from an array of items using a callback, grouping items into arrays
|
|
199
305
|
*
|
|
200
306
|
* Available as `toRecordArrays` and `toRecord.arrays`
|
|
307
|
+
*
|
|
201
308
|
* @param array Array to convert
|
|
202
309
|
* @param callback Callback to get an item's grouping key
|
|
203
310
|
* @returns Record of keyed arrays of items
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* ```typescript
|
|
314
|
+
* toRecordArrays(
|
|
315
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
316
|
+
* item => item.value,
|
|
317
|
+
* ); // => { 10: [{id: 1, value: 10}, {id: 3, value: 10}], 20: [{id: 2, value: 20}] }
|
|
318
|
+
* ```
|
|
204
319
|
*/
|
|
205
320
|
export function toRecordArrays<
|
|
206
321
|
Item,
|
|
@@ -211,9 +326,18 @@ export function toRecordArrays<
|
|
|
211
326
|
* Create a record from an array of items using a key, grouping items into arrays
|
|
212
327
|
*
|
|
213
328
|
* Available as `toRecordArrays` and `toRecord.arrays`
|
|
329
|
+
*
|
|
214
330
|
* @param array Array to convert
|
|
215
331
|
* @param key Key to use for grouping
|
|
216
332
|
* @returns Record of keyed arrays of items
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* ```typescript
|
|
336
|
+
* toRecordArrays(
|
|
337
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
338
|
+
* 'value',
|
|
339
|
+
* ); // => { 10: [{id: 1, value: 10}, {id: 3, value: 10}], 20: [{id: 2, value: 20}] }
|
|
340
|
+
* ```
|
|
217
341
|
*/
|
|
218
342
|
export function toRecordArrays<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
219
343
|
array: Item[],
|
package/src/array/to-set.ts
CHANGED
|
@@ -5,9 +5,18 @@ import type {PlainObject} from '../models';
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Create a Set from an array of items using a callback
|
|
8
|
+
*
|
|
8
9
|
* @param array Array to convert
|
|
9
10
|
* @param callback Callback to get an item's value
|
|
10
11
|
* @returns Set of values
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* toSet(
|
|
16
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
17
|
+
* item => item.id,
|
|
18
|
+
* ); // => Set { 1, 2, 3 }
|
|
19
|
+
* ```
|
|
11
20
|
*/
|
|
12
21
|
export function toSet<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(
|
|
13
22
|
array: Item[],
|
|
@@ -16,9 +25,18 @@ export function toSet<Item, Callback extends (item: Item, index: number, array:
|
|
|
16
25
|
|
|
17
26
|
/**
|
|
18
27
|
* Create a Set from an array of items using a key
|
|
28
|
+
*
|
|
19
29
|
* @param array Array to convert
|
|
20
30
|
* @param key Key to use for value
|
|
21
31
|
* @returns Set of values
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* toSet(
|
|
36
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
37
|
+
* 'id',
|
|
38
|
+
* ); // => Set { 1, 2, 3 }
|
|
39
|
+
* ```
|
|
22
40
|
*/
|
|
23
41
|
export function toSet<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
24
42
|
array: Item[],
|
|
@@ -27,8 +45,14 @@ export function toSet<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
|
27
45
|
|
|
28
46
|
/**
|
|
29
47
|
* Create a Set from an array of items
|
|
48
|
+
*
|
|
30
49
|
* @param array Array to convert
|
|
31
50
|
* @returns Set of items
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* toSet([1, 2, 3]); // => Set { 1, 2, 3 }
|
|
55
|
+
* ```
|
|
32
56
|
*/
|
|
33
57
|
export function toSet<Item>(array: Item[]): Set<Item>;
|
|
34
58
|
|
package/src/array/toggle.ts
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
import {updateInArray} from '../internal/array/update';
|
|
2
2
|
import type {PlainObject} from '../models';
|
|
3
3
|
|
|
4
|
+
// #region Functions
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
|
-
* Toggle an item in an array
|
|
7
|
+
* Toggle an item in an array
|
|
8
|
+
*
|
|
9
|
+
* If the item exists, it will be removed; if it doesn't, it will be added
|
|
10
|
+
*
|
|
6
11
|
* @param destination Array to toggle within
|
|
7
12
|
* @param toggled Toggled items
|
|
8
13
|
* @param callback Callback to find existing item
|
|
9
14
|
* @returns Original array
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* toggle(
|
|
19
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
20
|
+
* [{id: 2}, {id: 4}],
|
|
21
|
+
* item => item.id,
|
|
22
|
+
* ); // => [{id: 1}, {id: 3}, {id: 4}]
|
|
23
|
+
* ```
|
|
10
24
|
*/
|
|
11
25
|
export function toggle<Item>(
|
|
12
26
|
destination: Item[],
|
|
@@ -15,11 +29,23 @@ export function toggle<Item>(
|
|
|
15
29
|
): Item[];
|
|
16
30
|
|
|
17
31
|
/**
|
|
18
|
-
* Toggle an item in an array
|
|
32
|
+
* Toggle an item in an array
|
|
33
|
+
*
|
|
34
|
+
* If the item exists, it will be removed; if it doesn't, it will be added
|
|
35
|
+
*
|
|
19
36
|
* @param destination Array to toggle within
|
|
20
37
|
* @param toggled Toggled items
|
|
21
38
|
* @param key Key to find existing item
|
|
22
39
|
* @returns Original array
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* toggle(
|
|
44
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
45
|
+
* [{id: 2}, {id: 4}],
|
|
46
|
+
* 'id',
|
|
47
|
+
* ); // => [{id: 1}, {id: 3}, {id: 4}]
|
|
48
|
+
* ```
|
|
23
49
|
*/
|
|
24
50
|
export function toggle<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
25
51
|
destination: Item[],
|
|
@@ -28,13 +54,26 @@ export function toggle<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
|
28
54
|
): Item[];
|
|
29
55
|
|
|
30
56
|
/**
|
|
31
|
-
* Toggle an item in an array
|
|
57
|
+
* Toggle an item in an array
|
|
58
|
+
*
|
|
59
|
+
* If the item exists, it will be removed; if it doesn't, it will be added
|
|
60
|
+
*
|
|
32
61
|
* @param destination Array to toggle within
|
|
33
62
|
* @param toggled Toggled items
|
|
34
63
|
* @returns Original array
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* toggle(
|
|
68
|
+
* [1, 2, 3],
|
|
69
|
+
* [2, 4],
|
|
70
|
+
* ); // => [1, 3, 4]
|
|
71
|
+
* ```
|
|
35
72
|
*/
|
|
36
73
|
export function toggle<Item>(destination: Item[], toggled: Item[]): Item[];
|
|
37
74
|
|
|
38
75
|
export function toggle(array: unknown[], values: unknown[], key?: unknown): unknown[] {
|
|
39
76
|
return updateInArray(array, values, key, false);
|
|
40
77
|
}
|
|
78
|
+
|
|
79
|
+
// #endregion
|
package/src/array/union.ts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import {COMPARE_SETS_UNION, compareSets} from '../internal/array/sets';
|
|
2
2
|
|
|
3
|
+
// #region Functions
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Get the combined, unique values from two arrays
|
|
7
|
+
*
|
|
5
8
|
* @param first First array
|
|
6
9
|
* @param second Second array
|
|
7
10
|
* @param callback Callback to get an item's value for comparison
|
|
8
11
|
* @returns Combined, unique values from both arrays
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* union(
|
|
16
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
17
|
+
* [{id: 2}, {id: 4}],
|
|
18
|
+
* item => item.id,
|
|
19
|
+
* ); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}]
|
|
20
|
+
* ```
|
|
9
21
|
*/
|
|
10
22
|
export function union<First, Second>(
|
|
11
23
|
first: First[],
|
|
@@ -15,10 +27,20 @@ export function union<First, Second>(
|
|
|
15
27
|
|
|
16
28
|
/**
|
|
17
29
|
* Get the combined, unique values from two arrays
|
|
30
|
+
*
|
|
18
31
|
* @param first First array
|
|
19
32
|
* @param second Second array
|
|
20
33
|
* @param key Key to get an item's value for comparison
|
|
21
34
|
* @returns Combined, unique values from both arrays
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* union(
|
|
39
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
40
|
+
* [{id: 2}, {id: 4}],
|
|
41
|
+
* 'id',
|
|
42
|
+
* ); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}]
|
|
43
|
+
* ```
|
|
22
44
|
*/
|
|
23
45
|
export function union<
|
|
24
46
|
First extends Record<string, unknown>,
|
|
@@ -28,12 +50,23 @@ export function union<
|
|
|
28
50
|
|
|
29
51
|
/**
|
|
30
52
|
* Get the combined, unique values from two arrays
|
|
53
|
+
*
|
|
31
54
|
* @param first First array
|
|
32
55
|
* @param second Second array
|
|
33
56
|
* @returns Combined, unique values from both arrays
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* union(
|
|
61
|
+
* [1, 2, 3],
|
|
62
|
+
* [2, 4],
|
|
63
|
+
* ); // => [1, 2, 3, 4]
|
|
64
|
+
* ```
|
|
34
65
|
*/
|
|
35
66
|
export function union<First, Second>(first: First[], second: Second[]): (First | Second)[];
|
|
36
67
|
|
|
37
68
|
export function union(first: unknown[], second: unknown[], key?: unknown): unknown[] {
|
|
38
69
|
return compareSets(COMPARE_SETS_UNION, first, second, key);
|
|
39
70
|
}
|
|
71
|
+
|
|
72
|
+
// #endregion
|