@oscarpalmer/atoms 0.193.0 → 0.193.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/package.json +3 -4
- package/src/array/difference.ts +0 -73
- package/src/array/exists.ts +0 -93
- package/src/array/filter.ts +0 -182
- package/src/array/find.ts +0 -183
- package/src/array/first.ts +0 -196
- package/src/array/flatten.ts +0 -20
- package/src/array/from.ts +0 -129
- package/src/array/get.ts +0 -131
- package/src/array/group-by.ts +0 -369
- package/src/array/index.ts +0 -26
- package/src/array/insert.ts +0 -52
- package/src/array/intersection.ts +0 -72
- package/src/array/last.ts +0 -194
- package/src/array/match.ts +0 -436
- package/src/array/move.ts +0 -315
- package/src/array/partition.ts +0 -91
- package/src/array/push.ts +0 -23
- package/src/array/reverse.ts +0 -33
- package/src/array/select.ts +0 -260
- package/src/array/single.ts +0 -93
- package/src/array/slice.ts +0 -335
- package/src/array/sort.ts +0 -607
- package/src/array/splice.ts +0 -106
- package/src/array/swap.ts +0 -322
- package/src/array/to-map.ts +0 -371
- package/src/array/to-record.ts +0 -351
- package/src/array/to-set.ts +0 -80
- package/src/array/toggle.ts +0 -79
- package/src/array/union.ts +0 -72
- package/src/array/unique.ts +0 -67
- package/src/array/update.ts +0 -75
- package/src/beacon.ts +0 -378
- package/src/color/constants.ts +0 -137
- package/src/color/index.ts +0 -83
- package/src/color/instance.ts +0 -162
- package/src/color/misc/alpha.ts +0 -56
- package/src/color/misc/format.ts +0 -29
- package/src/color/misc/get.ts +0 -210
- package/src/color/misc/is.ts +0 -221
- package/src/color/misc/state.ts +0 -243
- package/src/color/models.ts +0 -389
- package/src/color/space/hex.ts +0 -184
- package/src/color/space/hsl.ts +0 -174
- package/src/color/space/hwb.ts +0 -153
- package/src/color/space/rgb.ts +0 -240
- package/src/function/assert.ts +0 -174
- package/src/function/index.ts +0 -2
- package/src/function/limit.ts +0 -83
- package/src/function/memoize.ts +0 -202
- package/src/function/once.ts +0 -200
- package/src/function/retry.ts +0 -175
- package/src/function/work.ts +0 -1007
- package/src/herald.ts +0 -216
- package/src/index.ts +0 -68
- package/src/internal/array/callbacks.ts +0 -46
- package/src/internal/array/chunk.ts +0 -51
- package/src/internal/array/compact.ts +0 -56
- package/src/internal/array/find.ts +0 -200
- package/src/internal/array/group.ts +0 -42
- package/src/internal/array/index-of.ts +0 -182
- package/src/internal/array/insert.ts +0 -80
- package/src/internal/array/overlap.ts +0 -35
- package/src/internal/array/sets.ts +0 -74
- package/src/internal/array/shuffle.ts +0 -33
- package/src/internal/array/update.ts +0 -52
- package/src/internal/function/misc.ts +0 -8
- package/src/internal/function/timer.ts +0 -168
- package/src/internal/is.ts +0 -244
- package/src/internal/math/aggregate.ts +0 -164
- package/src/internal/math/misc.ts +0 -28
- package/src/internal/number.ts +0 -129
- package/src/internal/random.ts +0 -49
- package/src/internal/result.ts +0 -92
- package/src/internal/sized.ts +0 -25
- package/src/internal/string.ts +0 -128
- package/src/internal/subscription.ts +0 -264
- package/src/internal/value/compare.ts +0 -170
- package/src/internal/value/equal.ts +0 -465
- package/src/internal/value/get.ts +0 -57
- package/src/internal/value/handlers.ts +0 -95
- package/src/internal/value/has.ts +0 -118
- package/src/internal/value/misc.ts +0 -125
- package/src/internal/value/partial.ts +0 -46
- package/src/internal/value/set.ts +0 -132
- package/src/is.ts +0 -182
- package/src/logger.ts +0 -230
- package/src/math.ts +0 -281
- package/src/models.ts +0 -286
- package/src/number.ts +0 -1
- package/src/promise/delay.ts +0 -62
- package/src/promise/helpers.ts +0 -96
- package/src/promise/index.ts +0 -300
- package/src/promise/misc.ts +0 -96
- package/src/promise/models.ts +0 -195
- package/src/promise/timed.ts +0 -91
- package/src/query.ts +0 -147
- package/src/queue.ts +0 -814
- package/src/random.ts +0 -125
- package/src/result/index.ts +0 -105
- package/src/result/match.ts +0 -124
- package/src/result/misc.ts +0 -129
- package/src/result/models.ts +0 -83
- package/src/result/work/flow.ts +0 -488
- package/src/result/work/pipe.ts +0 -496
- package/src/sized/map.ts +0 -110
- package/src/sized/set.ts +0 -107
- package/src/string/case.ts +0 -236
- package/src/string/fuzzy.ts +0 -444
- package/src/string/index.ts +0 -199
- package/src/string/match.ts +0 -80
- package/src/string/normalize.ts +0 -205
- package/src/string/template.ts +0 -161
- package/src/value/clone.ts +0 -319
- package/src/value/collection.ts +0 -63
- package/src/value/diff.ts +0 -232
- package/src/value/freeze.ts +0 -322
- package/src/value/handle.ts +0 -3
- package/src/value/index.ts +0 -5
- package/src/value/merge.ts +0 -278
- package/src/value/omit.ts +0 -20
- package/src/value/pick.ts +0 -20
- package/src/value/shake.ts +0 -45
- package/src/value/smush.ts +0 -89
- package/src/value/transform.ts +0 -153
- package/src/value/unsmush.ts +0 -84
package/src/array/group-by.ts
DELETED
|
@@ -1,369 +0,0 @@
|
|
|
1
|
-
import {groupValues} from '../internal/array/group';
|
|
2
|
-
import type {Key, KeyedValue, PlainObject, Simplify} from '../models';
|
|
3
|
-
|
|
4
|
-
// #region Functions
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Create a record from an array of items using a specific key and value
|
|
8
|
-
*
|
|
9
|
-
* If multiple items have the same key, the latest item's value will be used
|
|
10
|
-
*
|
|
11
|
-
* @param array Array to group
|
|
12
|
-
* @param key Callback to get an item's grouping key
|
|
13
|
-
* @param value Callback to get an item's value
|
|
14
|
-
* @returns Record of keyed values
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* groupBy(
|
|
19
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
20
|
-
* item => item.value,
|
|
21
|
-
* item => item,
|
|
22
|
-
* ); // => {10: {id: 3, value: 10}, 20: {id: 2, value: 20}}
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export function groupBy<
|
|
26
|
-
Item,
|
|
27
|
-
KeyCallback extends (item: Item, index: number, array: Item[]) => Key,
|
|
28
|
-
ValueCallback extends (item: Item, index: number, array: Item[]) => unknown,
|
|
29
|
-
>(
|
|
30
|
-
array: Item[],
|
|
31
|
-
key: KeyCallback,
|
|
32
|
-
value: ValueCallback,
|
|
33
|
-
): Simplify<Record<ReturnType<KeyCallback>, ReturnType<ValueCallback>>>;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Create a record from an array of items using a specific key and value
|
|
37
|
-
*
|
|
38
|
-
* If multiple items have the same key, the latest item's value will be used
|
|
39
|
-
*
|
|
40
|
-
* @param array Array to group
|
|
41
|
-
* @param key Callback to get an item's grouping key
|
|
42
|
-
* @param value Key to use for value
|
|
43
|
-
* @returns Record of keyed values
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```typescript
|
|
47
|
-
* groupBy(
|
|
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
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
export function groupBy<
|
|
55
|
-
Item extends PlainObject,
|
|
56
|
-
KeyCallback extends (item: Item, index: number, array: Item[]) => Key,
|
|
57
|
-
ItemValue extends keyof Item,
|
|
58
|
-
>(
|
|
59
|
-
array: Item[],
|
|
60
|
-
key: KeyCallback,
|
|
61
|
-
value: ItemValue,
|
|
62
|
-
): Record<ReturnType<KeyCallback>, Item[ItemValue]>;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Create a record from an array of items using a specific key and value
|
|
66
|
-
*
|
|
67
|
-
* If multiple items have the same key, the latest item's value will be used
|
|
68
|
-
*
|
|
69
|
-
* @param array Array to group
|
|
70
|
-
* @param key Key to use for grouping
|
|
71
|
-
* @param value Callback to get an item's value
|
|
72
|
-
* @returns Record of keyed values
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* ```typescript
|
|
76
|
-
* groupBy(
|
|
77
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
78
|
-
* 'value',
|
|
79
|
-
* item => item,
|
|
80
|
-
* ); // => {10: {id: 3, value: 10}, 20: {id: 2, value: 20}}
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
export function groupBy<
|
|
84
|
-
Item extends PlainObject,
|
|
85
|
-
ItemKey extends keyof Item,
|
|
86
|
-
ValueCallback extends (item: Item, index: number, array: Item[]) => unknown,
|
|
87
|
-
>(
|
|
88
|
-
array: Item[],
|
|
89
|
-
key: ItemKey,
|
|
90
|
-
value: ValueCallback,
|
|
91
|
-
): Simplify<Record<KeyedValue<Item, ItemKey>, ReturnType<ValueCallback>>>;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Create a record from an array of items using a specific key and value
|
|
95
|
-
*
|
|
96
|
-
* If multiple items have the same key, the latest item's value will be used
|
|
97
|
-
*
|
|
98
|
-
* @param array Array to group
|
|
99
|
-
* @param key Key to use for grouping
|
|
100
|
-
* @param value Key to use for value
|
|
101
|
-
* @returns Record of keyed values
|
|
102
|
-
*
|
|
103
|
-
* @example
|
|
104
|
-
* ```typescript
|
|
105
|
-
* groupBy(
|
|
106
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
107
|
-
* 'value',
|
|
108
|
-
* 'id'
|
|
109
|
-
* ); // => {10: 3, 20: 2}
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
export function groupBy<
|
|
113
|
-
Item extends PlainObject,
|
|
114
|
-
ItemKey extends keyof Item,
|
|
115
|
-
ItemValue extends keyof Item,
|
|
116
|
-
>(
|
|
117
|
-
array: Item[],
|
|
118
|
-
key: ItemKey,
|
|
119
|
-
value: ItemValue,
|
|
120
|
-
): Simplify<Record<KeyedValue<Item, ItemKey>, Item[ItemValue]>>;
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Create a record from an array of items using a specific key
|
|
124
|
-
*
|
|
125
|
-
* If multiple items have the same key, the latest item will be used
|
|
126
|
-
*
|
|
127
|
-
* @param array Array to group
|
|
128
|
-
* @param callback Callback to get an item's grouping key
|
|
129
|
-
* @returns Record of keyed items
|
|
130
|
-
*
|
|
131
|
-
* @example
|
|
132
|
-
* ```typescript
|
|
133
|
-
* groupBy(
|
|
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
|
-
* ```
|
|
138
|
-
*/
|
|
139
|
-
export function groupBy<Item, Callback extends (item: Item, index: number, array: Item[]) => Key>(
|
|
140
|
-
array: Item[],
|
|
141
|
-
callback: Callback,
|
|
142
|
-
): Record<ReturnType<Callback>, Item>;
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Create a record from an array of items using a specific key
|
|
146
|
-
*
|
|
147
|
-
* If multiple items have the same key, the latest item will be used
|
|
148
|
-
*
|
|
149
|
-
* @param array Array to group
|
|
150
|
-
* @param key Key to use for grouping
|
|
151
|
-
* @returns Record of keyed items
|
|
152
|
-
*
|
|
153
|
-
* @example
|
|
154
|
-
* ```typescript
|
|
155
|
-
* groupBy(
|
|
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
|
-
* ```
|
|
160
|
-
*/
|
|
161
|
-
export function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
162
|
-
array: Item[],
|
|
163
|
-
key: ItemKey,
|
|
164
|
-
): Simplify<Record<KeyedValue<Item, ItemKey>, Item>>;
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Create a record from an array of items _(using indices as keys)_
|
|
168
|
-
*
|
|
169
|
-
* @param array Array to group
|
|
170
|
-
* @returns Record of indiced items
|
|
171
|
-
*
|
|
172
|
-
* @example
|
|
173
|
-
* ```typescript
|
|
174
|
-
* groupBy(
|
|
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
|
-
* ```
|
|
178
|
-
*/
|
|
179
|
-
export function groupBy<Item>(array: Item[]): Record<number, Item>;
|
|
180
|
-
|
|
181
|
-
export function groupBy(array: unknown[], first?: unknown, second?: unknown): unknown {
|
|
182
|
-
return groupValues(array, first, second, false);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
groupBy.arrays = groupArraysBy;
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
189
|
-
*
|
|
190
|
-
* _Available as `groupArraysBy` and `groupBy.arrays`_
|
|
191
|
-
*
|
|
192
|
-
* @param array Array to group
|
|
193
|
-
* @param key Callback to get an item's grouping key
|
|
194
|
-
* @param value Callback to get an item's value
|
|
195
|
-
* @returns Record of keyed values
|
|
196
|
-
*
|
|
197
|
-
* @example
|
|
198
|
-
* ```typescript
|
|
199
|
-
* groupArraysBy(
|
|
200
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
201
|
-
* item => item.value,
|
|
202
|
-
* item => item,
|
|
203
|
-
* ); // => {
|
|
204
|
-
* // 10: [{id: 1, value: 10}, {id: 3, value: 10}],
|
|
205
|
-
* // 20: [{id: 2, value: 20}],
|
|
206
|
-
* // }
|
|
207
|
-
* ```
|
|
208
|
-
*/
|
|
209
|
-
export function groupArraysBy<
|
|
210
|
-
Item,
|
|
211
|
-
KeyCallback extends (item: Item, index: number, array: Item[]) => Key,
|
|
212
|
-
ValueCallback extends (item: Item, index: number, array: Item[]) => unknown,
|
|
213
|
-
>(
|
|
214
|
-
array: Item[],
|
|
215
|
-
key: KeyCallback,
|
|
216
|
-
value: ValueCallback,
|
|
217
|
-
): Record<ReturnType<KeyCallback>, ReturnType<ValueCallback>[]>;
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
221
|
-
*
|
|
222
|
-
* _Available as `groupArraysBy` and `groupBy.arrays`_
|
|
223
|
-
*
|
|
224
|
-
* @param array Array to group
|
|
225
|
-
* @param key Callback to get an item's grouping key
|
|
226
|
-
* @param value Key to use for value
|
|
227
|
-
* @returns Record of keyed values
|
|
228
|
-
*
|
|
229
|
-
* @example
|
|
230
|
-
* ```typescript
|
|
231
|
-
* groupArraysBy(
|
|
232
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
233
|
-
* item => item.value,
|
|
234
|
-
* 'id',
|
|
235
|
-
* ); // => {
|
|
236
|
-
* // 10: [1, 3],
|
|
237
|
-
* // 20: [2],
|
|
238
|
-
* // }
|
|
239
|
-
* ```
|
|
240
|
-
*/
|
|
241
|
-
export function groupArraysBy<
|
|
242
|
-
Item extends PlainObject,
|
|
243
|
-
KeyCallback extends (item: Item, index: number, array: Item[]) => Key,
|
|
244
|
-
ItemValue extends keyof Item,
|
|
245
|
-
>(
|
|
246
|
-
array: Item[],
|
|
247
|
-
key: KeyCallback,
|
|
248
|
-
value: ItemValue,
|
|
249
|
-
): Record<ReturnType<KeyCallback>, Item[ItemValue][]>;
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
253
|
-
*
|
|
254
|
-
* _Available as `groupArraysBy` and `groupBy.arrays`_
|
|
255
|
-
*
|
|
256
|
-
* @param array Array to group
|
|
257
|
-
* @param key Key to use for grouping
|
|
258
|
-
* @param value Callback to get an item's value
|
|
259
|
-
* @returns Record of keyed values
|
|
260
|
-
*
|
|
261
|
-
* @example
|
|
262
|
-
* ```typescript
|
|
263
|
-
* groupArraysBy(
|
|
264
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
265
|
-
* 'value',
|
|
266
|
-
* item => item,
|
|
267
|
-
* ); // => {
|
|
268
|
-
* // 10: [{id: 1, value: 10}, {id: 3, value: 10}],
|
|
269
|
-
* // 20: [{id: 2, value: 20}],
|
|
270
|
-
* // }
|
|
271
|
-
* ```
|
|
272
|
-
*/
|
|
273
|
-
export function groupArraysBy<
|
|
274
|
-
Item extends PlainObject,
|
|
275
|
-
ItemKey extends keyof Item,
|
|
276
|
-
ValueCallback extends (item: Item, index: number, array: Item[]) => unknown,
|
|
277
|
-
>(
|
|
278
|
-
array: Item[],
|
|
279
|
-
key: ItemKey,
|
|
280
|
-
value: ValueCallback,
|
|
281
|
-
): Simplify<Record<KeyedValue<Item, ItemKey>, ReturnType<ValueCallback>[]>>;
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
285
|
-
*
|
|
286
|
-
* _Available as `groupArraysBy` and `groupBy.arrays`_
|
|
287
|
-
*
|
|
288
|
-
* @param array Array to group
|
|
289
|
-
* @param key Key to use for grouping
|
|
290
|
-
* @param value Key to use for value
|
|
291
|
-
* @returns Record of keyed values
|
|
292
|
-
*
|
|
293
|
-
* @example
|
|
294
|
-
* ```typescript
|
|
295
|
-
* groupArraysBy(
|
|
296
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
297
|
-
* 'value',
|
|
298
|
-
* 'id',
|
|
299
|
-
* ); // => {
|
|
300
|
-
* // 10: [1, 3],
|
|
301
|
-
* // 20: [2],
|
|
302
|
-
* // }
|
|
303
|
-
* ```
|
|
304
|
-
*/
|
|
305
|
-
export function groupArraysBy<
|
|
306
|
-
Item extends PlainObject,
|
|
307
|
-
ItemKey extends keyof Item,
|
|
308
|
-
ItemValue extends keyof Item,
|
|
309
|
-
>(
|
|
310
|
-
array: Item[],
|
|
311
|
-
key: ItemKey,
|
|
312
|
-
value: ItemValue,
|
|
313
|
-
): Simplify<Record<KeyedValue<Item, ItemKey>, Item[ItemValue][]>>;
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* Create a record from an array of items using a specific key, grouping items into arrays
|
|
317
|
-
*
|
|
318
|
-
* _Available as `groupArraysBy` and `groupBy.arrays`_
|
|
319
|
-
*
|
|
320
|
-
* @param array Array to group
|
|
321
|
-
* @param callback Callback to get an item's grouping key
|
|
322
|
-
* @returns Record of keyed items
|
|
323
|
-
*
|
|
324
|
-
* @example
|
|
325
|
-
* ```typescript
|
|
326
|
-
* groupArraysBy(
|
|
327
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
328
|
-
* item => item.value,
|
|
329
|
-
* ); // => {
|
|
330
|
-
* // 10: [{id: 1, value: 10}, {id: 3, value: 10}],
|
|
331
|
-
* // 20: [{id: 2, value: 20}],
|
|
332
|
-
* // }
|
|
333
|
-
* ```
|
|
334
|
-
*/
|
|
335
|
-
export function groupArraysBy<
|
|
336
|
-
Item,
|
|
337
|
-
Callback extends (item: Item, index: number, array: Item[]) => Key,
|
|
338
|
-
>(array: Item[], callback: Callback): Record<ReturnType<Callback>, Item[]>;
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* Create a record from an array of items using a specific key, grouping items into arrays
|
|
342
|
-
*
|
|
343
|
-
* _Available as `groupArraysBy` and `groupBy.arrays`_
|
|
344
|
-
*
|
|
345
|
-
* @param array Array to group
|
|
346
|
-
* @param key Key to use for grouping
|
|
347
|
-
* @returns Record of keyed items
|
|
348
|
-
*
|
|
349
|
-
* @example
|
|
350
|
-
* ```typescript
|
|
351
|
-
* groupArraysBy(
|
|
352
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
353
|
-
* 'value',
|
|
354
|
-
* ); // => {
|
|
355
|
-
* // 10: [{id: 1, value: 10}, {id: 3, value: 10}],
|
|
356
|
-
* // 20: [{id: 2, value: 20}],
|
|
357
|
-
* // }
|
|
358
|
-
* ```
|
|
359
|
-
*/
|
|
360
|
-
export function groupArraysBy<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
361
|
-
array: Item[],
|
|
362
|
-
key: ItemKey,
|
|
363
|
-
): Simplify<Record<KeyedValue<Item, ItemKey>, Item[]>>;
|
|
364
|
-
|
|
365
|
-
export function groupArraysBy(array: unknown[], first?: unknown, second?: unknown): unknown {
|
|
366
|
-
return groupValues(array, first, second, true);
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
// #endregion
|
package/src/array/index.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export * from '../internal/array/chunk';
|
|
2
|
-
export * from '../internal/array/compact';
|
|
3
|
-
export * from '../internal/array/index-of';
|
|
4
|
-
export * from '../internal/array/shuffle';
|
|
5
|
-
|
|
6
|
-
export * from './difference';
|
|
7
|
-
export * from './exists';
|
|
8
|
-
export * from './find';
|
|
9
|
-
export * from './flatten';
|
|
10
|
-
export * from './from';
|
|
11
|
-
export * from './get';
|
|
12
|
-
export * from './insert';
|
|
13
|
-
export * from './intersection';
|
|
14
|
-
export * from './partition';
|
|
15
|
-
export * from './match';
|
|
16
|
-
export * from './push';
|
|
17
|
-
export * from './reverse';
|
|
18
|
-
export * from './select';
|
|
19
|
-
export * from './single';
|
|
20
|
-
export * from './slice';
|
|
21
|
-
export * from './splice';
|
|
22
|
-
export * from './to-set';
|
|
23
|
-
export * from './toggle';
|
|
24
|
-
export * from './union';
|
|
25
|
-
export * from './unique';
|
|
26
|
-
export * from './update';
|
package/src/array/insert.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import {INSERT_TYPE_INSERT, insertValues} from '../internal/array/insert';
|
|
2
|
-
|
|
3
|
-
// #region Functions
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Insert items into an array at a specified index
|
|
7
|
-
*
|
|
8
|
-
* _(Uses chunking to avoid call stack size being exceeded)_
|
|
9
|
-
*
|
|
10
|
-
* @param array Original array
|
|
11
|
-
* @param index Index to insert at
|
|
12
|
-
* @param items Inserted items
|
|
13
|
-
* @returns Updated array
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* insert([1, 2, 3], 1, [4, 5]); // => [1, 4, 5, 2, 3]
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export function insert<Item>(array: Item[], index: number, items: Item[]): Item[];
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Insert items into an array _(at the end)_
|
|
24
|
-
*
|
|
25
|
-
* _(Uses chunking to avoid call stack size being exceeded)_
|
|
26
|
-
*
|
|
27
|
-
* @param array Original array
|
|
28
|
-
* @param items Inserted items
|
|
29
|
-
* @returns Updated array
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```typescript
|
|
33
|
-
* insert([1, 2, 3], [4, 5]); // => [1, 2, 3, 4, 5]
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export function insert<Item>(array: Item[], items: Item[]): Item[];
|
|
37
|
-
|
|
38
|
-
export function insert(
|
|
39
|
-
array: unknown[],
|
|
40
|
-
indexOrItems: number | unknown[],
|
|
41
|
-
items?: unknown[],
|
|
42
|
-
): unknown[] {
|
|
43
|
-
return insertValues(
|
|
44
|
-
INSERT_TYPE_INSERT,
|
|
45
|
-
array,
|
|
46
|
-
items == null ? indexOrItems : items,
|
|
47
|
-
typeof indexOrItems === 'number' ? indexOrItems : array?.length,
|
|
48
|
-
0,
|
|
49
|
-
) as unknown[];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// #endregion
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import {COMPARE_SETS_INTERSECTION, compareSets} from '../internal/array/sets';
|
|
2
|
-
|
|
3
|
-
// #region Functions
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Get the common values between two arrays
|
|
7
|
-
*
|
|
8
|
-
* @param first First array
|
|
9
|
-
* @param second Second array
|
|
10
|
-
* @param callback Callback to get an item's value for comparison
|
|
11
|
-
* @returns Common values from both arrays
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* intersection(
|
|
16
|
-
* [{id: 1}, {id: 2}, {id: 3}],
|
|
17
|
-
* [{id: 2}, {id: 3}, {id: 4}],
|
|
18
|
-
* item => item.id,
|
|
19
|
-
* ); // => [{id: 2}, {id: 3}]
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export function intersection<First, Second>(
|
|
23
|
-
first: First[],
|
|
24
|
-
second: Second[],
|
|
25
|
-
callback: (item: First | Second) => unknown,
|
|
26
|
-
): First[];
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Get the common values between two arrays
|
|
30
|
-
*
|
|
31
|
-
* @param first First array
|
|
32
|
-
* @param second Second array
|
|
33
|
-
* @param key Key to get an item's value for comparison
|
|
34
|
-
* @returns Common values from both arrays
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```typescript
|
|
38
|
-
* intersection(
|
|
39
|
-
* [{id: 1}, {id: 2}, {id: 3}],
|
|
40
|
-
* [{id: 2}, {id: 3}, {id: 4}],
|
|
41
|
-
* 'id',
|
|
42
|
-
* ); // => [{id: 2}, {id: 3}]
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
export function intersection<
|
|
46
|
-
First extends Record<string, unknown>,
|
|
47
|
-
Second extends Record<string, unknown>,
|
|
48
|
-
SharedKey extends keyof First & keyof Second,
|
|
49
|
-
>(first: First[], second: Second[], key: SharedKey): First[];
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Get the common values between two arrays
|
|
53
|
-
*
|
|
54
|
-
* @param first First array
|
|
55
|
-
* @param second Second array
|
|
56
|
-
* @returns Common values from both arrays
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```typescript
|
|
60
|
-
* intersection(
|
|
61
|
-
* [1, 2, 3],
|
|
62
|
-
* [2, 3, 4],
|
|
63
|
-
* ); // => [2, 3]
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
export function intersection<First, Second>(first: First[], second: Second[]): First[];
|
|
67
|
-
|
|
68
|
-
export function intersection(first: unknown[], second: unknown[], key?: unknown): unknown[] {
|
|
69
|
-
return compareSets(COMPARE_SETS_INTERSECTION, first, second, key);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// #endregion
|
package/src/array/last.ts
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import {findAbsoluteValueOrDefault} from '../internal/array/find';
|
|
2
|
-
import type {PlainObject} from '../models';
|
|
3
|
-
|
|
4
|
-
// #region Functions
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Get the last items matching the given value
|
|
8
|
-
*
|
|
9
|
-
* @param array Array to search in
|
|
10
|
-
* @param callback Callback to get an item's value for matching
|
|
11
|
-
* @param value Value to match against
|
|
12
|
-
* @returns Last item that matches the value, or `undefined` if no match is found
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* last(
|
|
17
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
18
|
-
* item => item.value,
|
|
19
|
-
* 10,
|
|
20
|
-
* ); // => {id: 3, value: 10}
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export function last<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(
|
|
24
|
-
array: Item[],
|
|
25
|
-
callback: Callback,
|
|
26
|
-
value: ReturnType<Callback>,
|
|
27
|
-
): Item | undefined;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Get the first item matching the given value by key
|
|
31
|
-
*
|
|
32
|
-
* @param array Array to search in
|
|
33
|
-
* @param key Key to get an item's value for matching
|
|
34
|
-
* @param value Value to match against
|
|
35
|
-
* @returns Last item that matches the value, or `undefined` if no match is found
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```typescript
|
|
39
|
-
* last(
|
|
40
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
41
|
-
* 'value',
|
|
42
|
-
* 10,
|
|
43
|
-
* ); // => {id: 3, value: 10}
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
export function last<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
47
|
-
array: Item[],
|
|
48
|
-
key: ItemKey,
|
|
49
|
-
value: Item[ItemKey],
|
|
50
|
-
): Item | undefined;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Get the last item matching the filter
|
|
54
|
-
*
|
|
55
|
-
* @param array Array to search in
|
|
56
|
-
* @param filter Filter callback to match items
|
|
57
|
-
* @returns Last item that matches the filter, or `undefined` if no match is found
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```typescript
|
|
61
|
-
* last(
|
|
62
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
63
|
-
* item => item.value === 10,
|
|
64
|
-
* ); // => {id: 3, value: 10}
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
export function last<Item>(
|
|
68
|
-
array: Item[],
|
|
69
|
-
filter: (item: Item, index: number, array: Item[]) => boolean,
|
|
70
|
-
): Item | undefined;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Get the last item from an array
|
|
74
|
-
*
|
|
75
|
-
* @param array Array to get from
|
|
76
|
-
* @returns Last item from the array, or `undefined` if the array is empty
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* ```typescript
|
|
80
|
-
* last([1, 2, 3]); // => 3
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
export function last<Item>(array: Item[]): Item | undefined;
|
|
84
|
-
|
|
85
|
-
export function last(array: unknown[], ...parameters: unknown[]): unknown {
|
|
86
|
-
return findAbsoluteValueOrDefault(array, parameters, undefined, false, true);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
last.default = lastOrDefault;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Get the last item matching the given value
|
|
93
|
-
*
|
|
94
|
-
* _Available as `lastOrDefault` and `last.default`_
|
|
95
|
-
*
|
|
96
|
-
* @param array Array to search in
|
|
97
|
-
* @param defaultValue Default value to return if no match is found
|
|
98
|
-
* @param callback Callback to get an item's value for matching
|
|
99
|
-
* @param value Value to match against
|
|
100
|
-
* @returns Last item that matches the value, or the default value if no match is found
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```typescript
|
|
104
|
-
* lastOrDefault(
|
|
105
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
106
|
-
* {id: -1, value: 30},
|
|
107
|
-
* item => item.value,
|
|
108
|
-
* 30,
|
|
109
|
-
* ); // => {id: -1, value: 30}
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
export function lastOrDefault<
|
|
113
|
-
Item,
|
|
114
|
-
Callback extends (item: Item, index: number, array: Item[]) => unknown,
|
|
115
|
-
>(array: Item[], defaultValue: Item, callback: Callback, value: ReturnType<Callback>): Item;
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Get the last item matching the given value by key
|
|
119
|
-
*
|
|
120
|
-
* _Available as `lastOrDefault` and `last.default`_
|
|
121
|
-
*
|
|
122
|
-
* @param array Array to search in
|
|
123
|
-
* @param defaultValue Default value to return if no match is found
|
|
124
|
-
* @param key Key to get an item's value for matching
|
|
125
|
-
* @param value Value to match against
|
|
126
|
-
* @returns Last item that matches the value, or the default value if no match is found
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* ```typescript
|
|
130
|
-
* lastOrDefault(
|
|
131
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
132
|
-
* {id: -1, value: 30},
|
|
133
|
-
* 'value',
|
|
134
|
-
* 30,
|
|
135
|
-
* ); // => {id: -1, value: 30}
|
|
136
|
-
* ```
|
|
137
|
-
*/
|
|
138
|
-
export function lastOrDefault<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
139
|
-
array: Item[],
|
|
140
|
-
defaultValue: Item,
|
|
141
|
-
key: ItemKey,
|
|
142
|
-
value: Item[ItemKey],
|
|
143
|
-
): Item;
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Get the last item matching the filter
|
|
147
|
-
*
|
|
148
|
-
* _Available as `lastOrDefault` and `last.default`_
|
|
149
|
-
*
|
|
150
|
-
* @param array Array to search in
|
|
151
|
-
* @param defaultValue Default value to return if no match is found
|
|
152
|
-
* @param filter Filter callback to match items
|
|
153
|
-
* @returns Last item that matches the filter, or the default value if no match is found
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
* ```typescript
|
|
157
|
-
* lastOrDefault(
|
|
158
|
-
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
159
|
-
* {id: -1, value: 30},
|
|
160
|
-
* item => item.value === 30,
|
|
161
|
-
* ); // => {id: -1, value: 30}
|
|
162
|
-
* ```
|
|
163
|
-
*/
|
|
164
|
-
export function lastOrDefault<Item>(
|
|
165
|
-
array: Item[],
|
|
166
|
-
defaultValue: Item,
|
|
167
|
-
filter: (item: Item, index: number, array: Item[]) => boolean,
|
|
168
|
-
): Item;
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Get the last item from an array
|
|
172
|
-
*
|
|
173
|
-
* _Available as `lastOrDefault` and `last.default`_
|
|
174
|
-
*
|
|
175
|
-
* @param array Array to get from
|
|
176
|
-
* @param defaultValue Default value to return if the array is empty
|
|
177
|
-
* @returns Last item from the array, or the default value if the array is empty
|
|
178
|
-
*
|
|
179
|
-
* @example
|
|
180
|
-
* ```typescript
|
|
181
|
-
* lastOrDefault([], {id: -1, value: 30}); // => {id: -1, value: 30}
|
|
182
|
-
* ```
|
|
183
|
-
*/
|
|
184
|
-
export function lastOrDefault<Item>(array: Item[], defaultValue: Item): Item;
|
|
185
|
-
|
|
186
|
-
export function lastOrDefault(
|
|
187
|
-
array: unknown[],
|
|
188
|
-
defaultValue: unknown,
|
|
189
|
-
...parameters: unknown[]
|
|
190
|
-
): unknown {
|
|
191
|
-
return findAbsoluteValueOrDefault(array, parameters, defaultValue, true, true);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// #endregion
|