@oscarpalmer/atoms 0.185.0 → 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/insert.d.mts +16 -0
- package/dist/array/intersection.d.mts +29 -0
- package/dist/array/last.d.mts +75 -2
- package/dist/array/match.d.mts +161 -32
- package/dist/array/move.d.mts +78 -8
- package/dist/array/move.mjs +10 -0
- 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 +21 -0
- 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 +1 -0
- 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/index.d.mts +1892 -135
- package/dist/index.mjs +64 -18
- 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/get.d.mts +25 -3
- package/dist/internal/value/has.d.mts +4 -4
- package/dist/models.d.mts +14 -1
- package/dist/value/collection.d.mts +1 -1
- package/dist/value/merge.d.mts +28 -25
- package/dist/value/merge.mjs +29 -18
- package/dist/value/transform.d.mts +1 -1
- package/dist/value/unsmush.d.mts +1 -5
- package/package.json +5 -5
- package/src/array/difference.ts +29 -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 +36 -0
- package/src/array/get.ts +21 -15
- package/src/array/group-by.ts +142 -0
- package/src/array/insert.ts +16 -2
- package/src/array/intersection.ts +29 -0
- package/src/array/last.ts +75 -2
- package/src/array/match.ts +171 -42
- package/src/array/move.ts +82 -12
- package/src/array/partition.ts +35 -0
- package/src/array/push.ts +8 -2
- package/src/array/reverse.ts +1 -0
- package/src/array/select.ts +94 -13
- package/src/array/single.ts +29 -0
- package/src/array/slice.ts +114 -24
- package/src/array/sort.ts +21 -0
- package/src/array/splice.ts +52 -4
- package/src/array/swap.ts +117 -12
- 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 +38 -3
- package/src/array/union.ts +29 -0
- package/src/array/unique.ts +24 -0
- package/src/array/update.ts +38 -3
- 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/get.ts +25 -3
- package/src/internal/value/has.ts +4 -4
- package/src/models.ts +18 -0
- package/src/value/collection.ts +1 -1
- package/src/value/merge.ts +88 -66
- package/src/value/transform.ts +1 -1
- package/src/value/unsmush.ts +1 -10
package/dist/index.d.mts
CHANGED
|
@@ -143,74 +143,157 @@ type ToString<Value> = Value extends string | number ? `${Value}` : never;
|
|
|
143
143
|
* A union type of all typed arrays
|
|
144
144
|
*/
|
|
145
145
|
type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
|
|
146
|
+
/**
|
|
147
|
+
* Converts a union type to an intersection type
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* type A = {a: string};
|
|
152
|
+
* type B = {b: number};
|
|
153
|
+
* type C = UnionToIntersection<A | B>; // {a: string} & {b: number}
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
156
|
+
* Thanks, type-fest!
|
|
157
|
+
*/
|
|
158
|
+
type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Union) => void : never) extends ((mergedIntersection: infer Intersection) => void) ? Intersection & Union : never;
|
|
146
159
|
//#endregion
|
|
147
160
|
//#region src/array/filter.d.ts
|
|
148
161
|
/**
|
|
149
|
-
* Get a filtered array of items that do not match the
|
|
162
|
+
* Get a filtered array of items that do not match the value
|
|
150
163
|
*
|
|
151
164
|
* Available as `exclude` and `filter.remove`
|
|
165
|
+
*
|
|
152
166
|
* @param array Array to search in
|
|
153
167
|
* @param callback Callback to get an item's value for matching
|
|
154
168
|
* @param value Value to match against
|
|
155
169
|
* @returns Filtered array of items that do not match the filter
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* exclude(
|
|
174
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
175
|
+
* item => item.id,
|
|
176
|
+
* 2,
|
|
177
|
+
* ); // => [{id: 1}, {id: 3}]
|
|
178
|
+
* ```
|
|
156
179
|
*/
|
|
157
180
|
declare function exclude<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): unknown[];
|
|
158
181
|
/**
|
|
159
|
-
* Get a filtered array of items that do not match the
|
|
182
|
+
* Get a filtered array of items that do not match the value
|
|
160
183
|
*
|
|
161
184
|
* Available as `exclude` and `filter.remove`
|
|
185
|
+
*
|
|
162
186
|
* @param array Array to search in
|
|
163
187
|
* @param key Key to get an item's value for matching
|
|
164
188
|
* @param value Value to match against
|
|
165
189
|
* @returns Filtered array of items that do not match the filter
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```typescript
|
|
193
|
+
* exclude(
|
|
194
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
195
|
+
* 'id',
|
|
196
|
+
* 2,
|
|
197
|
+
* ); // => [{id: 1}, {id: 3}]
|
|
198
|
+
* ```
|
|
166
199
|
*/
|
|
167
200
|
declare function exclude<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): unknown[];
|
|
168
201
|
/**
|
|
169
202
|
* Get a filtered array of items that do not match the filter
|
|
170
203
|
*
|
|
171
204
|
* Available as `exclude` and `filter.remove`
|
|
205
|
+
*
|
|
172
206
|
* @param array Array to search in
|
|
173
207
|
* @param filter Filter callback to match items
|
|
174
208
|
* @returns Filtered array of items that do not match the filter
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```typescript
|
|
212
|
+
* exclude(
|
|
213
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
214
|
+
* item => item.id === 2,
|
|
215
|
+
* ); // => [{id: 1}, {id: 3}]
|
|
216
|
+
* ```
|
|
175
217
|
*/
|
|
176
218
|
declare function exclude<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): unknown[];
|
|
177
219
|
/**
|
|
178
220
|
* Get a filtered array of items that do not match the given item
|
|
179
221
|
*
|
|
180
222
|
* Available as `exclude` and `filter.remove`
|
|
223
|
+
*
|
|
181
224
|
* @param array Array to search in
|
|
182
225
|
* @param item Item to match against
|
|
183
226
|
* @returns Filtered array of items that do not match the given item
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```typescript
|
|
230
|
+
* exclude([1, 2, 3], 2); // => [1, 3]
|
|
231
|
+
* ```
|
|
184
232
|
*/
|
|
185
233
|
declare function exclude<Item>(array: Item[], item: Item): unknown[];
|
|
186
234
|
/**
|
|
187
235
|
* Get a filtered array of items
|
|
236
|
+
*
|
|
188
237
|
* @param array Array to search in
|
|
189
238
|
* @param callback Callback to get an item's value for matching
|
|
190
239
|
* @param value Value to match against
|
|
191
240
|
* @returns Filtered array of items
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* filter(
|
|
245
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
246
|
+
* item => item.id,
|
|
247
|
+
* 2,
|
|
248
|
+
* ); // => [{id: 2}]
|
|
249
|
+
* ```
|
|
192
250
|
*/
|
|
193
251
|
declare function filter<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[];
|
|
194
252
|
/**
|
|
195
253
|
* Get a filtered array of items
|
|
254
|
+
*
|
|
196
255
|
* @param array Array to search in
|
|
197
256
|
* @param key Key to get an item's value for matching
|
|
198
257
|
* @param value Value to match against
|
|
199
258
|
* @returns Filtered array of items
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```typescript
|
|
262
|
+
* filter(
|
|
263
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
264
|
+
* 'id',
|
|
265
|
+
* 2,
|
|
266
|
+
* ); // => [{id: 2}]
|
|
267
|
+
* ```
|
|
200
268
|
*/
|
|
201
269
|
declare function filter<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[];
|
|
202
270
|
/**
|
|
203
271
|
* Get a filtered array of items matching the filter
|
|
272
|
+
*
|
|
204
273
|
* @param array Array to search in
|
|
205
274
|
* @param filter Filter callback to match items
|
|
206
275
|
* @returns Filtered array of items
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```typescript
|
|
279
|
+
* filter(
|
|
280
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
281
|
+
* item => item.id === 2,
|
|
282
|
+
* ); // => [{id: 2}]
|
|
283
|
+
* ```
|
|
207
284
|
*/
|
|
208
285
|
declare function filter<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item[];
|
|
209
286
|
/**
|
|
210
287
|
* Get a filtered array of items matching the given item
|
|
288
|
+
*
|
|
211
289
|
* @param array Array to search in
|
|
212
290
|
* @param item Item to match against
|
|
213
291
|
* @returns Filtered array of items
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```typescript
|
|
295
|
+
* filter([1, 2, 3], 2); // => [2]
|
|
296
|
+
* ```
|
|
214
297
|
*/
|
|
215
298
|
declare function filter<Item>(array: Item[], item: Item): Item[];
|
|
216
299
|
declare namespace filter {
|
|
@@ -220,31 +303,68 @@ declare namespace filter {
|
|
|
220
303
|
//#region src/array/first.d.ts
|
|
221
304
|
/**
|
|
222
305
|
* Get the first item matching the given value
|
|
306
|
+
*
|
|
223
307
|
* @param array Array to search in
|
|
224
308
|
* @param callback Callback to get an item's value for matching
|
|
225
309
|
* @param value Value to match against
|
|
226
310
|
* @returns First item that matches the value, or `undefined` if no match is found
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* ```typescript
|
|
314
|
+
* first(
|
|
315
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
316
|
+
* item => item.value,
|
|
317
|
+
* 10,
|
|
318
|
+
* ); // => {id: 1, value: 10}
|
|
319
|
+
* ```
|
|
227
320
|
*/
|
|
228
321
|
declare function first<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item | undefined;
|
|
229
322
|
/**
|
|
230
323
|
* Get the first item matching the given value by key
|
|
324
|
+
*
|
|
231
325
|
* @param array Array to search in
|
|
232
326
|
* @param key Key to get an item's value for matching
|
|
233
327
|
* @param value Value to match against
|
|
234
328
|
* @returns First item that matches the value, or `undefined` if no match is found
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* ```typescript
|
|
332
|
+
* first(
|
|
333
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
334
|
+
* 'value',
|
|
335
|
+
* 10,
|
|
336
|
+
* ); // => {id: 1, value: 10}
|
|
337
|
+
* ```
|
|
235
338
|
*/
|
|
236
339
|
declare function first<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
|
|
237
340
|
/**
|
|
238
341
|
* Get the first item matching the filter
|
|
342
|
+
*
|
|
239
343
|
* @param array Array to search in
|
|
240
344
|
* @param filter Filter callback to match items
|
|
241
345
|
* @returns First item that matches the filter, or `undefined` if no match is found
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* ```typescript
|
|
349
|
+
* first(
|
|
350
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
351
|
+
* item => item.value === 10,
|
|
352
|
+
* ); // => {id: 1, value: 10}
|
|
353
|
+
* ```
|
|
242
354
|
*/
|
|
243
355
|
declare function first<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item | undefined;
|
|
244
356
|
/**
|
|
245
357
|
* Get the first item from an array
|
|
358
|
+
*
|
|
246
359
|
* @param array Array to get from
|
|
247
|
-
* @
|
|
360
|
+
* @returns First item from the array, or `undefined` if the array is empty
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* ```typescript
|
|
364
|
+
* first(
|
|
365
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
366
|
+
* ); // => {id: 1, value: 10}
|
|
367
|
+
* ```
|
|
248
368
|
*/
|
|
249
369
|
declare function first<Item>(array: Item[]): Item | undefined;
|
|
250
370
|
declare namespace first {
|
|
@@ -255,41 +375,79 @@ declare namespace first {
|
|
|
255
375
|
* Get the first item matching the given value, or a default value if no match is found
|
|
256
376
|
*
|
|
257
377
|
* Available as `firstOrDefault` and `first.default`
|
|
378
|
+
*
|
|
258
379
|
* @param array Array to search in
|
|
259
380
|
* @param defaultValue Default value to return if no match is found
|
|
260
381
|
* @param callback Callback to get an item's value for matching
|
|
261
382
|
* @param value Value to match against
|
|
262
383
|
* @returns First item that matches the value, or the default value if no match is found
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* ```typescript
|
|
387
|
+
* firstOrDefault(
|
|
388
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
389
|
+
* {id: -1, value: 30},
|
|
390
|
+
* item => item.value,
|
|
391
|
+
* 30,
|
|
392
|
+
* ); // => {id: -1, value: 30}
|
|
393
|
+
* ```
|
|
263
394
|
*/
|
|
264
395
|
declare function firstOrDefault<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], defaultValue: Item, callback: Callback, value: ReturnType<Callback>): Item;
|
|
265
396
|
/**
|
|
266
397
|
* Get the first item matching the given value by key, or a default value if no match is found
|
|
267
398
|
*
|
|
268
399
|
* Available as `firstOrDefault` and `first.default`
|
|
400
|
+
*
|
|
269
401
|
* @param array Array to search in
|
|
270
402
|
* @param defaultValue Default value to return if no match is found
|
|
271
403
|
* @param key Key to get an item's value for matching
|
|
272
404
|
* @param value Value to match against
|
|
273
405
|
* @returns First item that matches the value, or the default value if no match is found
|
|
406
|
+
*
|
|
407
|
+
* @example
|
|
408
|
+
* ```typescript
|
|
409
|
+
* firstOrDefault(
|
|
410
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
411
|
+
* {id: -1, value: 30},
|
|
412
|
+
* 'value',
|
|
413
|
+
* 30,
|
|
414
|
+
* ); // => {id: -1, value: 30}
|
|
415
|
+
* ```
|
|
274
416
|
*/
|
|
275
417
|
declare function firstOrDefault<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], defaultValue: Item, key: ItemKey, value: Item[ItemKey]): Item;
|
|
276
418
|
/**
|
|
277
419
|
* Get the first item matching the filter, or a default value if no match is found
|
|
278
420
|
*
|
|
279
421
|
* Available as `firstOrDefault` and `first.default`
|
|
422
|
+
*
|
|
280
423
|
* @param array Array to search in
|
|
281
424
|
* @param defaultValue Default value to return if no match is found
|
|
282
425
|
* @param filter Filter callback to match items
|
|
283
426
|
* @returns First item that matches the filter, or the default value if no match is found
|
|
427
|
+
*
|
|
428
|
+
* @example
|
|
429
|
+
* ```typescript
|
|
430
|
+
* firstOrDefault(
|
|
431
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
432
|
+
* {id: -1, value: 30},
|
|
433
|
+
* item => item.value === 30,
|
|
434
|
+
* ); // => {id: -1, value: 30}
|
|
435
|
+
* ```
|
|
284
436
|
*/
|
|
285
437
|
declare function firstOrDefault<Item>(array: Item[], defaultValue: Item, filter: (item: Item, index: number, array: Item[]) => boolean): Item;
|
|
286
438
|
/**
|
|
287
439
|
* Get the first item from an array, or a default value if the array is empty
|
|
288
440
|
*
|
|
289
441
|
* Available as `firstOrDefault` and `first.default`
|
|
442
|
+
*
|
|
290
443
|
* @param array Array to get from
|
|
291
444
|
* @param defaultValue Default value to return if the array is empty
|
|
292
|
-
* @
|
|
445
|
+
* @returns First item from the array, or the default value if the array is empty
|
|
446
|
+
*
|
|
447
|
+
* @example
|
|
448
|
+
* ```typescript
|
|
449
|
+
* firstOrDefault([], {id: -1, value: 30}); // => {id: -1, value: 30}
|
|
450
|
+
* ```
|
|
293
451
|
*/
|
|
294
452
|
declare function firstOrDefault<Item>(array: Item[], defaultValue: Item): Item;
|
|
295
453
|
//#endregion
|
|
@@ -298,64 +456,130 @@ declare function firstOrDefault<Item>(array: Item[], defaultValue: Item): Item;
|
|
|
298
456
|
* Create a record from an array of items using a specific key and value
|
|
299
457
|
*
|
|
300
458
|
* If multiple items have the same key, the latest item's value will be used
|
|
459
|
+
*
|
|
301
460
|
* @param array Array to group
|
|
302
461
|
* @param key Callback to get an item's grouping key
|
|
303
462
|
* @param value Callback to get an item's value
|
|
304
463
|
* @returns Record of keyed values
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
* ```typescript
|
|
467
|
+
* groupBy(
|
|
468
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
469
|
+
* item => item.value,
|
|
470
|
+
* item => item,
|
|
471
|
+
* ); // => {10: {id: 3, value: 10}, 20: {id: 2, value: 20}}
|
|
472
|
+
* ```
|
|
305
473
|
*/
|
|
306
474
|
declare function groupBy<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key$1, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Simplify<Record<ReturnType<KeyCallback>, ReturnType<ValueCallback>>>;
|
|
307
475
|
/**
|
|
308
476
|
* Create a record from an array of items using a specific key and value
|
|
309
477
|
*
|
|
310
478
|
* If multiple items have the same key, the latest item's value will be used
|
|
479
|
+
*
|
|
311
480
|
* @param array Array to group
|
|
312
481
|
* @param key Callback to get an item's grouping key
|
|
313
482
|
* @param value Key to use for value
|
|
314
483
|
* @returns Record of keyed values
|
|
484
|
+
*
|
|
485
|
+
* @example
|
|
486
|
+
* ```typescript
|
|
487
|
+
* groupBy(
|
|
488
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
489
|
+
* item => item.value,
|
|
490
|
+
* 'id'
|
|
491
|
+
* ); // => {10: 3, 20: 2}
|
|
492
|
+
* ```
|
|
315
493
|
*/
|
|
316
494
|
declare function groupBy<Item extends PlainObject, KeyCallback extends (item: Item, index: number, array: Item[]) => Key$1, ItemValue extends keyof Item>(array: Item[], key: KeyCallback, value: ItemValue): Record<ReturnType<KeyCallback>, Item[ItemValue]>;
|
|
317
495
|
/**
|
|
318
496
|
* Create a record from an array of items using a specific key and value
|
|
319
497
|
*
|
|
320
498
|
* If multiple items have the same key, the latest item's value will be used
|
|
499
|
+
*
|
|
321
500
|
* @param array Array to group
|
|
322
501
|
* @param key Key to use for grouping
|
|
323
502
|
* @param value Callback to get an item's value
|
|
324
503
|
* @returns Record of keyed values
|
|
504
|
+
*
|
|
505
|
+
* @example
|
|
506
|
+
* ```typescript
|
|
507
|
+
* groupBy(
|
|
508
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
509
|
+
* 'value',
|
|
510
|
+
* item => item,
|
|
511
|
+
* ); // => {10: {id: 3, value: 10}, 20: {id: 2, value: 20}}
|
|
512
|
+
* ```
|
|
325
513
|
*/
|
|
326
514
|
declare function groupBy<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>, ReturnType<ValueCallback>>>;
|
|
327
515
|
/**
|
|
328
516
|
* Create a record from an array of items using a specific key and value
|
|
329
517
|
*
|
|
330
518
|
* If multiple items have the same key, the latest item's value will be used
|
|
519
|
+
*
|
|
331
520
|
* @param array Array to group
|
|
332
521
|
* @param key Key to use for grouping
|
|
333
522
|
* @param value Key to use for value
|
|
334
523
|
* @returns Record of keyed values
|
|
524
|
+
*
|
|
525
|
+
* @example
|
|
526
|
+
* ```typescript
|
|
527
|
+
* groupBy(
|
|
528
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
529
|
+
* 'value',
|
|
530
|
+
* 'id'
|
|
531
|
+
* ); // => {10: 3, 20: 2}
|
|
532
|
+
* ```
|
|
335
533
|
*/
|
|
336
534
|
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]>>;
|
|
337
535
|
/**
|
|
338
536
|
* Create a record from an array of items using a specific key
|
|
339
537
|
*
|
|
340
538
|
* If multiple items have the same key, the latest item will be used
|
|
539
|
+
*
|
|
341
540
|
* @param array Array to group
|
|
342
541
|
* @param callback Callback to get an item's grouping key
|
|
343
542
|
* @returns Record of keyed items
|
|
543
|
+
*
|
|
544
|
+
* @example
|
|
545
|
+
* ```typescript
|
|
546
|
+
* groupBy(
|
|
547
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
548
|
+
* item => item.value,
|
|
549
|
+
* ); // => {10: {id: 3, value: 10}, 20: {id: 2, value: 20}}
|
|
550
|
+
* ```
|
|
344
551
|
*/
|
|
345
552
|
declare function groupBy<Item, Callback extends (item: Item, index: number, array: Item[]) => Key$1>(array: Item[], callback: Callback): Record<ReturnType<Callback>, Item>;
|
|
346
553
|
/**
|
|
347
554
|
* Create a record from an array of items using a specific key
|
|
348
555
|
*
|
|
349
556
|
* If multiple items have the same key, the latest item will be used
|
|
557
|
+
*
|
|
350
558
|
* @param array Array to group
|
|
351
559
|
* @param key Key to use for grouping
|
|
352
560
|
* @returns Record of keyed items
|
|
561
|
+
*
|
|
562
|
+
* @example
|
|
563
|
+
* ```typescript
|
|
564
|
+
* groupBy(
|
|
565
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
566
|
+
* 'value',
|
|
567
|
+
* ); // => {10: {id: 3, value: 10}, 20: {id: 2, value: 20}}
|
|
568
|
+
* ```
|
|
353
569
|
*/
|
|
354
570
|
declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Simplify<Record<KeyedValue<Item, ItemKey>, Item>>;
|
|
355
571
|
/**
|
|
356
572
|
* Create a record from an array of items _(using indices as keys)_
|
|
573
|
+
*
|
|
357
574
|
* @param array Array to group
|
|
358
575
|
* @returns Record of indiced items
|
|
576
|
+
*
|
|
577
|
+
* @example
|
|
578
|
+
* ```typescript
|
|
579
|
+
* groupBy(
|
|
580
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
581
|
+
* ); // => {0: {id: 1, value: 10}, 1: {id: 2, value: 20}, 2: {id: 3, value: 10}}
|
|
582
|
+
* ```
|
|
359
583
|
*/
|
|
360
584
|
declare function groupBy<Item>(array: Item[]): Record<number, Item>;
|
|
361
585
|
declare namespace groupBy {
|
|
@@ -365,114 +589,243 @@ declare namespace groupBy {
|
|
|
365
589
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
366
590
|
*
|
|
367
591
|
* Available as `groupArraysBy` and `groupBy.arrays`
|
|
592
|
+
*
|
|
368
593
|
* @param array Array to group
|
|
369
594
|
* @param key Callback to get an item's grouping key
|
|
370
595
|
* @param value Callback to get an item's value
|
|
371
596
|
* @returns Record of keyed values
|
|
597
|
+
*
|
|
598
|
+
* @example
|
|
599
|
+
* ```typescript
|
|
600
|
+
* groupArraysBy(
|
|
601
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
602
|
+
* item => item.value,
|
|
603
|
+
* item => item,
|
|
604
|
+
* ); // => {
|
|
605
|
+
* // 10: [{id: 1, value: 10}, {id: 3, value: 10}],
|
|
606
|
+
* // 20: [{id: 2, value: 20}],
|
|
607
|
+
* // }
|
|
608
|
+
* ```
|
|
372
609
|
*/
|
|
373
610
|
declare function groupArraysBy<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key$1, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Record<ReturnType<KeyCallback>, ReturnType<ValueCallback>[]>;
|
|
374
611
|
/**
|
|
375
612
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
376
613
|
*
|
|
377
614
|
* Available as `groupArraysBy` and `groupBy.arrays`
|
|
615
|
+
*
|
|
378
616
|
* @param array Array to group
|
|
379
617
|
* @param key Callback to get an item's grouping key
|
|
380
618
|
* @param value Key to use for value
|
|
381
619
|
* @returns Record of keyed values
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
* ```typescript
|
|
623
|
+
* groupArraysBy(
|
|
624
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
625
|
+
* item => item.value,
|
|
626
|
+
* 'id',
|
|
627
|
+
* ); // => {
|
|
628
|
+
* // 10: [1, 3],
|
|
629
|
+
* // 20: [2],
|
|
630
|
+
* // }
|
|
631
|
+
* ```
|
|
382
632
|
*/
|
|
383
633
|
declare function groupArraysBy<Item extends PlainObject, KeyCallback extends (item: Item, index: number, array: Item[]) => Key$1, ItemValue extends keyof Item>(array: Item[], key: KeyCallback, value: ItemValue): Record<ReturnType<KeyCallback>, Item[ItemValue][]>;
|
|
384
634
|
/**
|
|
385
635
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
386
636
|
*
|
|
387
637
|
* Available as `groupArraysBy` and `groupBy.arrays`
|
|
638
|
+
*
|
|
388
639
|
* @param array Array to group
|
|
389
640
|
* @param key Key to use for grouping
|
|
390
641
|
* @param value Callback to get an item's value
|
|
391
642
|
* @returns Record of keyed values
|
|
643
|
+
*
|
|
644
|
+
* @example
|
|
645
|
+
* ```typescript
|
|
646
|
+
* groupArraysBy(
|
|
647
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
648
|
+
* 'value',
|
|
649
|
+
* item => item,
|
|
650
|
+
* ); // => {
|
|
651
|
+
* // 10: [{id: 1, value: 10}, {id: 3, value: 10}],
|
|
652
|
+
* // 20: [{id: 2, value: 20}],
|
|
653
|
+
* // }
|
|
654
|
+
* ```
|
|
392
655
|
*/
|
|
393
656
|
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>, ReturnType<ValueCallback>[]>>;
|
|
394
657
|
/**
|
|
395
658
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
396
659
|
*
|
|
397
660
|
* Available as `groupArraysBy` and `groupBy.arrays`
|
|
661
|
+
*
|
|
398
662
|
* @param array Array to group
|
|
399
663
|
* @param key Key to use for grouping
|
|
400
664
|
* @param value Key to use for value
|
|
401
665
|
* @returns Record of keyed values
|
|
666
|
+
*
|
|
667
|
+
* @example
|
|
668
|
+
* ```typescript
|
|
669
|
+
* groupArraysBy(
|
|
670
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
671
|
+
* 'value',
|
|
672
|
+
* 'id',
|
|
673
|
+
* ); // => {
|
|
674
|
+
* // 10: [1, 3],
|
|
675
|
+
* // 20: [2],
|
|
676
|
+
* // }
|
|
677
|
+
* ```
|
|
402
678
|
*/
|
|
403
679
|
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][]>>;
|
|
404
680
|
/**
|
|
405
681
|
* Create a record from an array of items using a specific key, grouping items into arrays
|
|
406
682
|
*
|
|
407
683
|
* Available as `groupArraysBy` and `groupBy.arrays`
|
|
684
|
+
*
|
|
408
685
|
* @param array Array to group
|
|
409
686
|
* @param callback Callback to get an item's grouping key
|
|
410
687
|
* @returns Record of keyed items
|
|
688
|
+
*
|
|
689
|
+
* @example
|
|
690
|
+
* ```typescript
|
|
691
|
+
* groupArraysBy(
|
|
692
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
693
|
+
* item => item.value,
|
|
694
|
+
* ); // => {
|
|
695
|
+
* // 10: [{id: 1, value: 10}, {id: 3, value: 10}],
|
|
696
|
+
* // 20: [{id: 2, value: 20}],
|
|
697
|
+
* // }
|
|
698
|
+
* ```
|
|
411
699
|
*/
|
|
412
700
|
declare function groupArraysBy<Item, Callback extends (item: Item, index: number, array: Item[]) => Key$1>(array: Item[], callback: Callback): Record<ReturnType<Callback>, Item[]>;
|
|
413
701
|
/**
|
|
414
702
|
* Create a record from an array of items using a specific key, grouping items into arrays
|
|
415
703
|
*
|
|
416
704
|
* Available as `groupArraysBy` and `groupBy.arrays`
|
|
705
|
+
*
|
|
417
706
|
* @param array Array to group
|
|
418
707
|
* @param key Key to use for grouping
|
|
419
708
|
* @returns Record of keyed items
|
|
709
|
+
*
|
|
710
|
+
* @example
|
|
711
|
+
* ```typescript
|
|
712
|
+
* groupArraysBy(
|
|
713
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
714
|
+
* 'value',
|
|
715
|
+
* ); // => {
|
|
716
|
+
* // 10: [{id: 1, value: 10}, {id: 3, value: 10}],
|
|
717
|
+
* // 20: [{id: 2, value: 20}],
|
|
718
|
+
* // }
|
|
719
|
+
* ```
|
|
420
720
|
*/
|
|
421
721
|
declare function groupArraysBy<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Simplify<Record<KeyedValue<Item, ItemKey>, Item[]>>;
|
|
422
722
|
//#endregion
|
|
423
723
|
//#region src/internal/array/chunk.d.ts
|
|
424
724
|
/**
|
|
425
725
|
* Chunk an array into smaller arrays
|
|
726
|
+
*
|
|
426
727
|
* @param array Array to chunk
|
|
427
728
|
* @param size Size of each chunk _(minimum is `1`, maximum is `5000`; defaults to `5000`)_
|
|
428
729
|
* @returns Array of arrays
|
|
730
|
+
*
|
|
731
|
+
* @example
|
|
732
|
+
* ```typescript
|
|
733
|
+
* chunk([1, 2, 3, 4, 5], 2); // => [[1, 2], [3, 4], [5]]
|
|
734
|
+
* ```
|
|
429
735
|
*/
|
|
430
736
|
declare function chunk<Item>(array: Item[], size?: number): Item[][];
|
|
431
737
|
//#endregion
|
|
432
738
|
//#region src/internal/array/compact.d.ts
|
|
433
739
|
/**
|
|
434
740
|
* Compact an array _(removing all false-y values)_
|
|
741
|
+
*
|
|
435
742
|
* @param array Array to compact
|
|
436
743
|
* @param strict True to remove all false-y values
|
|
437
744
|
* @returns Compacted array
|
|
745
|
+
*
|
|
746
|
+
* @example
|
|
747
|
+
* ```typescript
|
|
748
|
+
* compact([0, 1, '', 'hello', false, true, null, undefined]); // => [1, 'hello', true]
|
|
749
|
+
* ```
|
|
438
750
|
*/
|
|
439
751
|
declare function compact<Item>(array: Item[], strict: true): Exclude<Item, 0 | '' | false | null | undefined>[];
|
|
440
752
|
/**
|
|
441
753
|
* Compact an array _(removing all `null` and `undefined` values)_
|
|
754
|
+
*
|
|
442
755
|
* @param array Array to compact
|
|
443
756
|
* @returns Compacted array
|
|
757
|
+
*
|
|
758
|
+
* @example
|
|
759
|
+
* ```typescript
|
|
760
|
+
* compact([0, 1, '', 'hello', false, true, null, undefined]); // => [0, 1, '', 'hello', false, true]
|
|
761
|
+
* ```
|
|
444
762
|
*/
|
|
445
763
|
declare function compact<Item>(array: Item[]): Exclude<Item, null | undefined>[];
|
|
446
764
|
//#endregion
|
|
447
765
|
//#region src/internal/array/index-of.d.ts
|
|
448
766
|
/**
|
|
449
767
|
* Get the index of the first matching item by callback
|
|
768
|
+
*
|
|
450
769
|
* @param array Array to search in
|
|
451
770
|
* @param callback Callback to get an item's value
|
|
452
771
|
* @param value Value to match against
|
|
453
772
|
* @returns Index of the first matching item, or `-1` if no match is found
|
|
773
|
+
*
|
|
774
|
+
* @example
|
|
775
|
+
* ```typescript
|
|
776
|
+
* indexOf(
|
|
777
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
778
|
+
* item => item.id,
|
|
779
|
+
* 2,
|
|
780
|
+
* ); // => 1
|
|
781
|
+
* ```
|
|
454
782
|
*/
|
|
455
783
|
declare function indexOf<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): number;
|
|
456
784
|
/**
|
|
457
785
|
* Get the index of the first matching item by key
|
|
786
|
+
*
|
|
458
787
|
* @param array Array to search in
|
|
459
788
|
* @param key Key to match items by
|
|
460
789
|
* @param value Value to match against
|
|
461
790
|
* @returns Index of the first matching item, or `-1` if no match is found
|
|
791
|
+
*
|
|
792
|
+
* @example
|
|
793
|
+
* ```typescript
|
|
794
|
+
* indexOf(
|
|
795
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
796
|
+
* 'id',
|
|
797
|
+
* 2,
|
|
798
|
+
* ); // => 1
|
|
799
|
+
* ```
|
|
462
800
|
*/
|
|
463
801
|
declare function indexOf<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): number;
|
|
464
802
|
/**
|
|
465
803
|
* Get the index of the first item matching the filter
|
|
804
|
+
*
|
|
466
805
|
* @param array Array to search in
|
|
467
806
|
* @param filter Filter callback to match items
|
|
468
807
|
* @returns Index of the first matching item, or `-1` if no match is found
|
|
808
|
+
*
|
|
809
|
+
* @example
|
|
810
|
+
* ```typescript
|
|
811
|
+
* indexOf(
|
|
812
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
813
|
+
* item => item.id === 2,
|
|
814
|
+
* ); // => 1
|
|
815
|
+
* ```
|
|
469
816
|
*/
|
|
470
817
|
declare function indexOf<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): number;
|
|
471
818
|
/**
|
|
472
819
|
* Get the index of the first item matching the given item
|
|
820
|
+
*
|
|
473
821
|
* @param array Array to search in
|
|
474
822
|
* @param item Item to match against
|
|
475
823
|
* @returns Index of the first matching item, or `-1` if no match is found
|
|
824
|
+
*
|
|
825
|
+
* @example
|
|
826
|
+
* ```typescript
|
|
827
|
+
* indexOf([1, 2, 3, 4, 5], 3); // => 2
|
|
828
|
+
* ```
|
|
476
829
|
*/
|
|
477
830
|
declare function indexOf<Item>(array: Item[], item: Item): number;
|
|
478
831
|
declare namespace indexOf {
|
|
@@ -482,38 +835,73 @@ declare namespace indexOf {
|
|
|
482
835
|
* Get the index of the last matching item by callback
|
|
483
836
|
*
|
|
484
837
|
* Available as `lastIndexOf` and `indexOf.last`
|
|
838
|
+
*
|
|
485
839
|
* @param array Array to search in
|
|
486
840
|
* @param callback Callback to get an item's value
|
|
487
841
|
* @param value Value to match against
|
|
488
842
|
* @returns Index of the last matching item, or `-1` if no match is found
|
|
843
|
+
*
|
|
844
|
+
* @example
|
|
845
|
+
* ```typescript
|
|
846
|
+
* lastIndexOf(
|
|
847
|
+
* [{id: 1}, {id: 2}, {id: 3}, {id: 2}],
|
|
848
|
+
* item => item.id,
|
|
849
|
+
* 2,
|
|
850
|
+
* ); // => 3
|
|
851
|
+
* ```
|
|
489
852
|
*/
|
|
490
853
|
declare function lastIndexOf<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): number;
|
|
491
854
|
/**
|
|
492
855
|
* Get the index of the last matching item by key
|
|
493
856
|
*
|
|
494
857
|
* Available as `lastIndexOf` and `indexOf.last`
|
|
858
|
+
*
|
|
495
859
|
* @param array Array to search in
|
|
496
860
|
* @param key Key to match items by
|
|
497
861
|
* @param value Value to match against
|
|
498
862
|
* @returns Index of the last matching item, or `-1` if no match is found
|
|
863
|
+
*
|
|
864
|
+
* @example
|
|
865
|
+
* ```typescript
|
|
866
|
+
* lastIndexOf(
|
|
867
|
+
* [{id: 1}, {id: 2}, {id: 3}, {id: 2}],
|
|
868
|
+
* 'id',
|
|
869
|
+
* 2,
|
|
870
|
+
* ); // => 3
|
|
871
|
+
* ```
|
|
499
872
|
*/
|
|
500
873
|
declare function lastIndexOf<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): number;
|
|
501
874
|
/**
|
|
502
875
|
* Get the index of the last item matching the filter
|
|
503
876
|
*
|
|
504
877
|
* Available as `lastIndexOf` and `indexOf.last`
|
|
878
|
+
*
|
|
505
879
|
* @param array Array to search in
|
|
506
880
|
* @param filter Filter callback to match items
|
|
507
881
|
* @returns Index of the last matching item, or `-1` if no match is found
|
|
882
|
+
*
|
|
883
|
+
* @example
|
|
884
|
+
* ```typescript
|
|
885
|
+
* lastIndexOf(
|
|
886
|
+
* [{id: 1}, {id: 2}, {id: 3}, {id: 2}],
|
|
887
|
+
* item => item.id === 2,
|
|
888
|
+
* ); // => 3
|
|
889
|
+
* ```
|
|
508
890
|
*/
|
|
509
891
|
declare function lastIndexOf<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): number;
|
|
510
892
|
/**
|
|
511
893
|
* Get the index of the last item matching the given item
|
|
512
894
|
*
|
|
513
895
|
* Available as `lastIndexOf` and `indexOf.last`
|
|
896
|
+
*
|
|
514
897
|
* @param array Array to search in
|
|
515
898
|
* @param item Item to match against
|
|
516
899
|
* @returns Index of the last matching item, or `-1` if no match is found
|
|
900
|
+
*
|
|
901
|
+
* @example
|
|
902
|
+
* ```typescript
|
|
903
|
+
* lastIndexOf([1, 2, 3, 2, 1], 2); // => 3
|
|
904
|
+
* ```
|
|
517
905
|
*/
|
|
518
906
|
declare function lastIndexOf<Item>(array: Item[], item: Item): number;
|
|
519
907
|
//#endregion
|
|
@@ -528,89 +916,188 @@ declare function shuffle<Item>(array: Item[]): Item[];
|
|
|
528
916
|
//#region src/array/difference.d.ts
|
|
529
917
|
/**
|
|
530
918
|
* Get the items from the first array that are not in the second array
|
|
919
|
+
*
|
|
531
920
|
* @param first First array
|
|
532
921
|
* @param second Second array
|
|
533
922
|
* @param callback Callback to get an item's value for comparison
|
|
534
923
|
* @returns Unique values from the first array
|
|
924
|
+
*
|
|
925
|
+
* @example
|
|
926
|
+
* ```typescript
|
|
927
|
+
* difference(
|
|
928
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
929
|
+
* [{id: 2}, {id: 4}],
|
|
930
|
+
* item => item.id,
|
|
931
|
+
* ); // => [{id: 1}, {id: 3}]
|
|
932
|
+
* ```
|
|
535
933
|
*/
|
|
536
934
|
declare function difference<First, Second>(first: First[], second: Second[], callback: (item: First | Second) => unknown): First[];
|
|
537
935
|
/**
|
|
538
936
|
* Get the items from the first array that are not in the second array
|
|
937
|
+
*
|
|
539
938
|
* @param first First array
|
|
540
939
|
* @param second Second array
|
|
541
940
|
* @param key Key to get an item's value for comparison
|
|
542
941
|
* @returns Unique values from the first array
|
|
942
|
+
*
|
|
943
|
+
* @example
|
|
944
|
+
* ```typescript
|
|
945
|
+
* difference(
|
|
946
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
947
|
+
* [{id: 2}, {id: 4}],
|
|
948
|
+
* 'id',
|
|
949
|
+
* ); // => [{id: 1}, {id: 3}]
|
|
950
|
+
* ```
|
|
543
951
|
*/
|
|
544
952
|
declare function difference<First extends PlainObject, Second extends PlainObject, SharedKey extends keyof First & keyof Second>(first: First[], second: Second[], key: SharedKey): First[];
|
|
545
953
|
/**
|
|
546
954
|
* Get the items from the first array that are not in the second array
|
|
955
|
+
*
|
|
547
956
|
* @param first First array
|
|
548
957
|
* @param second Second array
|
|
549
958
|
* @returns Unique values from the first array
|
|
959
|
+
*
|
|
960
|
+
* @example
|
|
961
|
+
* ```typescript
|
|
962
|
+
* difference(
|
|
963
|
+
* [1, 2, 3],
|
|
964
|
+
* [2, 4],
|
|
965
|
+
* ); // => [1, 3]
|
|
966
|
+
* ```
|
|
550
967
|
*/
|
|
551
968
|
declare function difference<First, Second>(first: First[], second: Second[]): First[];
|
|
552
969
|
//#endregion
|
|
553
970
|
//#region src/array/exists.d.ts
|
|
554
971
|
/**
|
|
555
972
|
* Does an item with a specific value exist in the array?
|
|
973
|
+
*
|
|
556
974
|
* @param array Array to search in
|
|
557
975
|
* @param callback Callback to get an item's value for matching
|
|
558
976
|
* @param value Value to match against
|
|
559
977
|
* @returns `true` if the item exists in the array, otherwise `false`
|
|
978
|
+
*
|
|
979
|
+
* @example
|
|
980
|
+
* ```typescript
|
|
981
|
+
* exists(
|
|
982
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
983
|
+
* item => item.id,
|
|
984
|
+
* 2,
|
|
985
|
+
* ); // => true
|
|
986
|
+
* ```
|
|
560
987
|
*/
|
|
561
988
|
declare function exists<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): boolean;
|
|
562
989
|
/**
|
|
563
990
|
* Does an item with a specific value exist in the array?
|
|
991
|
+
*
|
|
564
992
|
* @param array Array to search in
|
|
565
993
|
* @param key Key to get an item's value for matching
|
|
566
994
|
* @param value Value to match against
|
|
567
995
|
* @returns `true` if the item exists in the array, otherwise `false`
|
|
996
|
+
*
|
|
997
|
+
* @example
|
|
998
|
+
* ```typescript
|
|
999
|
+
* exists(
|
|
1000
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
1001
|
+
* 'id',
|
|
1002
|
+
* 2,
|
|
1003
|
+
* ); // => true
|
|
1004
|
+
* ```
|
|
568
1005
|
*/
|
|
569
1006
|
declare function exists<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): boolean;
|
|
570
1007
|
/**
|
|
571
1008
|
* Does an item in the array match the filter?
|
|
1009
|
+
*
|
|
572
1010
|
* @param array Array to search in
|
|
573
1011
|
* @param filter Filter callback to match items
|
|
574
1012
|
* @returns `true` if a matching item exists, otherwise `false`
|
|
1013
|
+
*
|
|
1014
|
+
* @example
|
|
1015
|
+
* ```typescript
|
|
1016
|
+
* exists(
|
|
1017
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
1018
|
+
* item => item.id === 2,
|
|
1019
|
+
* ); // => true
|
|
1020
|
+
* ```
|
|
575
1021
|
*/
|
|
576
1022
|
declare function exists<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): boolean;
|
|
577
1023
|
/**
|
|
578
1024
|
* Does the item exist in the array?
|
|
1025
|
+
*
|
|
579
1026
|
* @param array Array to search in
|
|
580
1027
|
* @param item Item to search for
|
|
581
1028
|
* @returns `true` if the item exists in the array, otherwise `false`
|
|
1029
|
+
*
|
|
1030
|
+
* @example
|
|
1031
|
+
* ```typescript
|
|
1032
|
+
* exists([1, 2, 3], 2); // => true
|
|
1033
|
+
* ```
|
|
582
1034
|
*/
|
|
583
1035
|
declare function exists<Item>(array: Item[], item: Item): boolean;
|
|
584
1036
|
//#endregion
|
|
585
1037
|
//#region src/array/find.d.ts
|
|
586
1038
|
/**
|
|
587
1039
|
* Get the first item matching the given value
|
|
1040
|
+
*
|
|
588
1041
|
* @param array Array to search in
|
|
589
1042
|
* @param callback Callback to get an item's value for matching
|
|
590
1043
|
* @param value Value to match against
|
|
591
1044
|
* @returns First item that matches the value, or `undefined` if no match is found
|
|
1045
|
+
*
|
|
1046
|
+
* @example
|
|
1047
|
+
* ```typescript
|
|
1048
|
+
* find(
|
|
1049
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
1050
|
+
* item => item.value,
|
|
1051
|
+
* 10,
|
|
1052
|
+
* ); // => {id: 1, value: 10}
|
|
1053
|
+
* ```
|
|
592
1054
|
*/
|
|
593
1055
|
declare function find<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item | undefined;
|
|
594
1056
|
/**
|
|
595
1057
|
* Get the first item matching the given value by key
|
|
1058
|
+
*
|
|
596
1059
|
* @param array Array to search in
|
|
597
1060
|
* @param key Key to get an item's value for matching
|
|
598
1061
|
* @param value Value to match against
|
|
599
1062
|
* @returns First item that matches the value, or `undefined` if no match is found
|
|
1063
|
+
*
|
|
1064
|
+
* @example
|
|
1065
|
+
* ```typescript
|
|
1066
|
+
* find(
|
|
1067
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
1068
|
+
* 'value',
|
|
1069
|
+
* 10,
|
|
1070
|
+
* ); // => {id: 1, value: 10}
|
|
1071
|
+
* ```
|
|
600
1072
|
*/
|
|
601
1073
|
declare function find<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
|
|
602
1074
|
/**
|
|
603
1075
|
* Get the first item matching the filter
|
|
1076
|
+
*
|
|
604
1077
|
* @param array Array to search in
|
|
605
1078
|
* @param filter Filter callback to match items
|
|
606
1079
|
* @returns First item that matches the filter, or `undefined` if no match is found
|
|
1080
|
+
*
|
|
1081
|
+
* @example
|
|
1082
|
+
* ```typescript
|
|
1083
|
+
* find(
|
|
1084
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
1085
|
+
* item => item.value === 10,
|
|
1086
|
+
* ); // => {id: 1, value: 10}
|
|
1087
|
+
* ```
|
|
607
1088
|
*/
|
|
608
1089
|
declare function find<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item | undefined;
|
|
609
1090
|
/**
|
|
610
1091
|
* Get the first item matching the given value
|
|
1092
|
+
*
|
|
611
1093
|
* @param array Array to search in
|
|
612
1094
|
* @param value Value to match against
|
|
613
1095
|
* @returns First item that matches the value, or `undefined` if no match is found
|
|
1096
|
+
*
|
|
1097
|
+
* @example
|
|
1098
|
+
* ```typescript
|
|
1099
|
+
* find([1, 2, 3, 2, 1], 1); // => 1
|
|
1100
|
+
* ```
|
|
614
1101
|
*/
|
|
615
1102
|
declare function find<Item>(array: Item[], value: Item): Item | undefined;
|
|
616
1103
|
declare namespace find {
|
|
@@ -620,195 +1107,360 @@ declare namespace find {
|
|
|
620
1107
|
* Get the last item matching the given value
|
|
621
1108
|
*
|
|
622
1109
|
* Available as `findLast` and `find.last`
|
|
1110
|
+
*
|
|
623
1111
|
* @param array Array to search in
|
|
624
1112
|
* @param callback Callback to get an item's value for matching
|
|
625
1113
|
* @param value Value to match against
|
|
626
1114
|
* @returns Last item that matches the value, or `undefined` if no match is found
|
|
1115
|
+
*
|
|
1116
|
+
* @example
|
|
1117
|
+
* ```typescript
|
|
1118
|
+
* findLast(
|
|
1119
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
1120
|
+
* item => item.value,
|
|
1121
|
+
* 10,
|
|
1122
|
+
* ); // => {id: 3, value: 10}
|
|
1123
|
+
* ```
|
|
627
1124
|
*/
|
|
628
1125
|
declare function findLast<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item | undefined;
|
|
629
1126
|
/**
|
|
630
1127
|
* Get the last item matching the given value by key
|
|
631
1128
|
*
|
|
632
1129
|
* Available as `findLast` and `find.last`
|
|
1130
|
+
*
|
|
633
1131
|
* @param array Array to search in
|
|
634
1132
|
* @param key Key to get an item's value for matching
|
|
635
1133
|
* @param value Value to match against
|
|
636
1134
|
* @returns Last item that matches the value, or `undefined` if no match is found
|
|
1135
|
+
*
|
|
1136
|
+
* @example
|
|
1137
|
+
* ```typescript
|
|
1138
|
+
* findLast(
|
|
1139
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
1140
|
+
* 'value',
|
|
1141
|
+
* 10,
|
|
1142
|
+
* ); // => {id: 3, value: 10}
|
|
1143
|
+
* ```
|
|
637
1144
|
*/
|
|
638
1145
|
declare function findLast<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
|
|
639
1146
|
/**
|
|
640
1147
|
* Get the last item matching the filter
|
|
641
1148
|
*
|
|
642
1149
|
* Available as `findLast` and `find.last`
|
|
1150
|
+
*
|
|
643
1151
|
* @param array Array to search in
|
|
644
1152
|
* @param filter Filter callback to match items
|
|
645
1153
|
* @returns Last item that matches the filter, or `undefined` if no match is found
|
|
1154
|
+
*
|
|
1155
|
+
* @example
|
|
1156
|
+
* ```typescript
|
|
1157
|
+
* findLast(
|
|
1158
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
1159
|
+
* item => item.value === 10,
|
|
1160
|
+
* ); // => {id: 3, value: 10}
|
|
1161
|
+
* ```
|
|
646
1162
|
*/
|
|
647
1163
|
declare function findLast<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item | undefined;
|
|
648
1164
|
/**
|
|
649
1165
|
* Get the last item matching the given value
|
|
650
1166
|
*
|
|
651
1167
|
* Available as `findLast` and `find.last`
|
|
1168
|
+
*
|
|
652
1169
|
* @param array Array to search in
|
|
653
1170
|
* @param value Value to match against
|
|
654
1171
|
* @returns Last item that matches the value, or `undefined` if no match is found
|
|
1172
|
+
*
|
|
1173
|
+
* @example
|
|
1174
|
+
* ```typescript
|
|
1175
|
+
* findLast([1, 2, 3, 2, 1], 1); // => 1
|
|
1176
|
+
* ```
|
|
655
1177
|
*/
|
|
656
1178
|
declare function findLast<Item>(array: Item[], value: Item): Item | undefined;
|
|
657
1179
|
//#endregion
|
|
658
1180
|
//#region src/array/flatten.d.ts
|
|
659
1181
|
/**
|
|
660
1182
|
* Flatten an array _(using native `flat` and maximum depth)_
|
|
1183
|
+
*
|
|
661
1184
|
* @param array Array to flatten
|
|
662
1185
|
* @returns Flattened array
|
|
1186
|
+
*
|
|
1187
|
+
* @example
|
|
1188
|
+
* ```typescript
|
|
1189
|
+
* flatten([1, [2, [3, 4], 5], 6]); // => [1, 2, 3, 4, 5, 6]
|
|
1190
|
+
* ```
|
|
663
1191
|
*/
|
|
664
1192
|
declare function flatten<Item>(array: Item[]): NestedArray<Item>[];
|
|
665
1193
|
//#endregion
|
|
666
1194
|
//#region src/array/from.d.ts
|
|
667
1195
|
/**
|
|
668
1196
|
* Get an array with a specified length, filled with indices
|
|
1197
|
+
*
|
|
669
1198
|
* @param length Length of the array
|
|
670
1199
|
* @returns Array of indices
|
|
1200
|
+
*
|
|
1201
|
+
* @example
|
|
1202
|
+
* ```typescript
|
|
1203
|
+
* range(5); // => [0, 1, 2, 3, 4]
|
|
1204
|
+
* ```
|
|
671
1205
|
*/
|
|
672
1206
|
declare function range(length: number): number[];
|
|
673
1207
|
/**
|
|
674
1208
|
* Get an array of numbers in a specified range
|
|
1209
|
+
*
|
|
675
1210
|
* @param start Starting number _(inclusive)_
|
|
676
1211
|
* @param end Ending number _(exclusive)_
|
|
677
1212
|
* @returns Array of numbers in range
|
|
1213
|
+
*
|
|
1214
|
+
* @example
|
|
1215
|
+
* ```typescript
|
|
1216
|
+
* range(2, 5); // => [2, 3, 4]
|
|
1217
|
+
* ```
|
|
678
1218
|
*/
|
|
679
1219
|
declare function range(start: number, end: number): number[];
|
|
680
1220
|
/**
|
|
681
1221
|
* Get an array of numbers in a specified range with a specified step
|
|
1222
|
+
*
|
|
682
1223
|
* @param start Starting number _(inclusive)_
|
|
683
1224
|
* @param end Ending number _(exclusive)_
|
|
684
1225
|
* @param step Step between numbers
|
|
685
1226
|
* @returns Array of numbers in range
|
|
1227
|
+
*
|
|
1228
|
+
* @example
|
|
1229
|
+
* ```typescript
|
|
1230
|
+
* range(0, 10, 2); // => [0, 2, 4, 6, 8]
|
|
1231
|
+
* ```
|
|
686
1232
|
*/
|
|
687
1233
|
declare function range(start: number, end: number, step: number): number[];
|
|
688
1234
|
/**
|
|
689
1235
|
* Get an array with a specified length, filled with indices
|
|
1236
|
+
*
|
|
690
1237
|
* @param length Length of the array
|
|
691
1238
|
* @returns Array of indices
|
|
1239
|
+
*
|
|
1240
|
+
* @example
|
|
1241
|
+
* ```typescript
|
|
1242
|
+
* times(5); // => [0, 1, 2, 3, 4]
|
|
1243
|
+
* ```
|
|
692
1244
|
*/
|
|
693
1245
|
declare function times(length: number): number[];
|
|
694
1246
|
/**
|
|
695
1247
|
* Get an array with a specified length, filled by values from a callback
|
|
1248
|
+
*
|
|
696
1249
|
* @param length Length of the array
|
|
697
1250
|
* @param callback Callback function to generate values
|
|
698
1251
|
* @returns Array of values generated by the callback
|
|
1252
|
+
*
|
|
1253
|
+
* @example
|
|
1254
|
+
* ```typescript
|
|
1255
|
+
* times(5, index => index * 2); // => [0, 2, 4, 6, 8]
|
|
1256
|
+
* ```
|
|
699
1257
|
*/
|
|
700
1258
|
declare function times<Callback extends (index: number) => unknown>(length: number, callback: Callback): ReturnType<Callback>[];
|
|
701
1259
|
/**
|
|
702
1260
|
* Get an array with a specified length, filled with a specified value
|
|
1261
|
+
*
|
|
703
1262
|
* @param length Length of the array
|
|
704
1263
|
* @param value Value to fill the array with
|
|
705
1264
|
* @returns Array filled with the specified value
|
|
1265
|
+
*
|
|
1266
|
+
* @example
|
|
1267
|
+
* ```typescript
|
|
1268
|
+
* times(5, 'a'); // => ['a', 'a', 'a', 'a', 'a']
|
|
1269
|
+
* ```
|
|
706
1270
|
*/
|
|
707
1271
|
declare function times<Value>(length: number, value: Value): Value[];
|
|
708
1272
|
//#endregion
|
|
709
1273
|
//#region src/array/get.d.ts
|
|
710
1274
|
/**
|
|
711
1275
|
* Get an array from an object, where only values with numerical keys will be included
|
|
1276
|
+
*
|
|
712
1277
|
* @param value Object to convert to an array
|
|
713
1278
|
* @returns Array holding the values of the object's numerical keys
|
|
1279
|
+
*
|
|
1280
|
+
* @example
|
|
1281
|
+
* ```typescript
|
|
1282
|
+
* getArray({0: 'a', 1: 'b', 2: 'c', d: 'd'}, true); // => ['a', 'b', 'c']
|
|
1283
|
+
* getArray({a: 'a', b: 'b', c: 'c', d: 'd'}, true); // => []
|
|
1284
|
+
* ```
|
|
714
1285
|
*/
|
|
715
1286
|
declare function getArray<Value extends PlainObject>(value: Value, indiced: true): Value[NumericalKeys<Value>][];
|
|
716
1287
|
/**
|
|
717
1288
|
* Get an array from an object
|
|
1289
|
+
*
|
|
718
1290
|
* @param value Object to convert to an array
|
|
719
1291
|
* @returns Array holding the values of the object
|
|
1292
|
+
*
|
|
1293
|
+
* @example
|
|
1294
|
+
* ```typescript
|
|
1295
|
+
* getArray({0: 'a', 1: 'b', 2: 'c', d: 'd'}); // => ['a', 'b', 'c', 'd']
|
|
1296
|
+
* getArray({a: 'a', b: 'b', c: 'c', d: 'd'}); // => ['a', 'b', 'c', 'd']
|
|
1297
|
+
* ```
|
|
720
1298
|
*/
|
|
721
1299
|
declare function getArray<Value extends PlainObject>(value: Value): Value[keyof Value][];
|
|
722
1300
|
/**
|
|
723
|
-
* Get an array
|
|
1301
|
+
* Get an array from a value
|
|
1302
|
+
*
|
|
724
1303
|
* @param value Original array
|
|
725
1304
|
* @returns Original array
|
|
1305
|
+
*
|
|
1306
|
+
* @example
|
|
1307
|
+
* ```typescript
|
|
1308
|
+
* getArray(123); // => [123]
|
|
1309
|
+
* ```
|
|
726
1310
|
*/
|
|
727
1311
|
declare function getArray<Item>(value: Item[]): Item[];
|
|
728
|
-
/**
|
|
729
|
-
* Get an array from a value
|
|
730
|
-
* @param value Value to convert to an array
|
|
731
|
-
* @returns Array holding the value
|
|
732
|
-
*/
|
|
733
|
-
declare function getArray<Item>(value: Item): Item[];
|
|
734
|
-
/**
|
|
735
|
-
* Get an array from an unknown value
|
|
736
|
-
* @param value Value to convert to an array
|
|
737
|
-
* @returns Array of value
|
|
738
|
-
*/
|
|
739
|
-
declare function getArray(value: unknown): unknown[];
|
|
740
1312
|
//#endregion
|
|
741
1313
|
//#region src/array/insert.d.ts
|
|
742
1314
|
/**
|
|
743
1315
|
* Insert items into an array at a specified index
|
|
1316
|
+
*
|
|
1317
|
+
* _(Uses chunking to avoid call stack size being exceeded)_
|
|
1318
|
+
*
|
|
744
1319
|
* @param array Original array
|
|
745
1320
|
* @param index Index to insert at
|
|
746
1321
|
* @param items Inserted items
|
|
747
1322
|
* @returns Updated array
|
|
1323
|
+
*
|
|
1324
|
+
* @example
|
|
1325
|
+
* ```typescript
|
|
1326
|
+
* insert([1, 2, 3], 1, [4, 5]); // => [1, 4, 5, 2, 3]
|
|
1327
|
+
* ```
|
|
748
1328
|
*/
|
|
749
1329
|
declare function insert<Item>(array: Item[], index: number, items: Item[]): Item[];
|
|
750
1330
|
/**
|
|
751
1331
|
* Insert items into an array _(at the end)_
|
|
1332
|
+
*
|
|
1333
|
+
* _(Uses chunking to avoid call stack size being exceeded)_
|
|
1334
|
+
*
|
|
752
1335
|
* @param array Original array
|
|
753
1336
|
* @param items Inserted items
|
|
754
1337
|
* @returns Updated array
|
|
1338
|
+
*
|
|
1339
|
+
* @example
|
|
1340
|
+
* ```typescript
|
|
1341
|
+
* insert([1, 2, 3], [4, 5]); // => [1, 2, 3, 4, 5]
|
|
1342
|
+
* ```
|
|
755
1343
|
*/
|
|
756
1344
|
declare function insert<Item>(array: Item[], items: Item[]): Item[];
|
|
757
1345
|
//#endregion
|
|
758
1346
|
//#region src/array/intersection.d.ts
|
|
759
1347
|
/**
|
|
760
1348
|
* Get the common values between two arrays
|
|
1349
|
+
*
|
|
761
1350
|
* @param first First array
|
|
762
1351
|
* @param second Second array
|
|
763
1352
|
* @param callback Callback to get an item's value for comparison
|
|
764
1353
|
* @returns Common values from both arrays
|
|
1354
|
+
*
|
|
1355
|
+
* @example
|
|
1356
|
+
* ```typescript
|
|
1357
|
+
* intersection(
|
|
1358
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
1359
|
+
* [{id: 2}, {id: 3}, {id: 4}],
|
|
1360
|
+
* item => item.id,
|
|
1361
|
+
* ); // => [{id: 2}, {id: 3}]
|
|
1362
|
+
* ```
|
|
765
1363
|
*/
|
|
766
1364
|
declare function intersection<First, Second>(first: First[], second: Second[], callback: (item: First | Second) => unknown): First[];
|
|
767
1365
|
/**
|
|
768
1366
|
* Get the common values between two arrays
|
|
1367
|
+
*
|
|
769
1368
|
* @param first First array
|
|
770
1369
|
* @param second Second array
|
|
771
1370
|
* @param key Key to get an item's value for comparison
|
|
772
1371
|
* @returns Common values from both arrays
|
|
1372
|
+
*
|
|
1373
|
+
* @example
|
|
1374
|
+
* ```typescript
|
|
1375
|
+
* intersection(
|
|
1376
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
1377
|
+
* [{id: 2}, {id: 3}, {id: 4}],
|
|
1378
|
+
* 'id',
|
|
1379
|
+
* ); // => [{id: 2}, {id: 3}]
|
|
1380
|
+
* ```
|
|
773
1381
|
*/
|
|
774
1382
|
declare function intersection<First extends Record<string, unknown>, Second extends Record<string, unknown>, SharedKey extends keyof First & keyof Second>(first: First[], second: Second[], key: SharedKey): First[];
|
|
775
1383
|
/**
|
|
776
1384
|
* Get the common values between two arrays
|
|
1385
|
+
*
|
|
777
1386
|
* @param first First array
|
|
778
1387
|
* @param second Second array
|
|
779
1388
|
* @returns Common values from both arrays
|
|
1389
|
+
*
|
|
1390
|
+
* @example
|
|
1391
|
+
* ```typescript
|
|
1392
|
+
* intersection(
|
|
1393
|
+
* [1, 2, 3],
|
|
1394
|
+
* [2, 3, 4],
|
|
1395
|
+
* ); // => [2, 3]
|
|
1396
|
+
* ```
|
|
780
1397
|
*/
|
|
781
1398
|
declare function intersection<First, Second>(first: First[], second: Second[]): First[];
|
|
782
1399
|
//#endregion
|
|
783
1400
|
//#region src/array/partition.d.ts
|
|
784
1401
|
/**
|
|
785
1402
|
* Get a partitioned array of items
|
|
1403
|
+
*
|
|
786
1404
|
* @param array Array to search in
|
|
787
1405
|
* @param callback Callback to get an item's value for matching
|
|
788
1406
|
* @param value Value to match against
|
|
789
1407
|
* @returns Partitioned array of items
|
|
1408
|
+
*
|
|
1409
|
+
* @example
|
|
1410
|
+
* ```typescript
|
|
1411
|
+
* partition(
|
|
1412
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
1413
|
+
* item => item.id,
|
|
1414
|
+
* 2,
|
|
1415
|
+
* ); // => [[{id: 2}], [{id: 1}, {id: 3}]]
|
|
1416
|
+
* ```
|
|
790
1417
|
*/
|
|
791
1418
|
declare function partition<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[][];
|
|
792
1419
|
/**
|
|
793
1420
|
* Get a partitioned array of items
|
|
1421
|
+
*
|
|
794
1422
|
* @param array Array to search in
|
|
795
1423
|
* @param key Key to get an item's value for matching
|
|
796
1424
|
* @param value Value to match against
|
|
797
1425
|
* @returns Partitioned array of items
|
|
1426
|
+
*
|
|
1427
|
+
* @example
|
|
1428
|
+
* ```typescript
|
|
1429
|
+
* partition(
|
|
1430
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
1431
|
+
* 'id',
|
|
1432
|
+
* 2,
|
|
1433
|
+
* ); // => [[{id: 2}], [{id: 1}, {id: 3}]]
|
|
1434
|
+
* ```
|
|
798
1435
|
*/
|
|
799
1436
|
declare function partition<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[][];
|
|
800
1437
|
/**
|
|
801
1438
|
* Get a partitioned array of items
|
|
1439
|
+
*
|
|
802
1440
|
* @param array Array to search in
|
|
803
1441
|
* @param filter Filter callback to match items
|
|
804
1442
|
* @returns Partitioned array of items
|
|
1443
|
+
*
|
|
1444
|
+
* @example
|
|
1445
|
+
* ```typescript
|
|
1446
|
+
* partition(
|
|
1447
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
1448
|
+
* item => item.id === 2,
|
|
1449
|
+
* ); // => [[{id: 2}], [{id: 1}, {id: 3}]]
|
|
1450
|
+
* ```
|
|
805
1451
|
*/
|
|
806
1452
|
declare function partition<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item[][];
|
|
807
1453
|
/**
|
|
808
1454
|
* Get a partitioned array of items matching the given item
|
|
1455
|
+
*
|
|
809
1456
|
* @param array Array to search in
|
|
810
1457
|
* @param item Item to match against
|
|
811
1458
|
* @returns Partitioned array of items
|
|
1459
|
+
*
|
|
1460
|
+
* @example
|
|
1461
|
+
* ```typescript
|
|
1462
|
+
* partition([1, 2, 3, 4, 5], 3); // => [[3], [1, 2, 4, 5]]
|
|
1463
|
+
* ```
|
|
812
1464
|
*/
|
|
813
1465
|
declare function partition<Item>(array: Item[], item: Item): Item[][];
|
|
814
1466
|
//#endregion
|
|
@@ -821,130 +1473,268 @@ type ArrayComparison = 'end' | 'inside' | 'invalid' | 'outside' | 'same' | 'star
|
|
|
821
1473
|
* Does the needle array end the haystack array?
|
|
822
1474
|
* @param haystack Haystack array
|
|
823
1475
|
* @param needle Needle array
|
|
824
|
-
* @param
|
|
825
|
-
* @
|
|
1476
|
+
* @param callback Callback to get an item's value for matching
|
|
1477
|
+
* @returns `true` if the haystack ends with the needle, otherwise `false`
|
|
1478
|
+
*
|
|
1479
|
+
* @example
|
|
1480
|
+
* ```typescript
|
|
1481
|
+
* endsWithArray(
|
|
1482
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
1483
|
+
* [{id: 2}, {id: 3}],
|
|
1484
|
+
* item => item.id,
|
|
1485
|
+
* ); // => true
|
|
1486
|
+
* ```
|
|
826
1487
|
*/
|
|
827
|
-
declare function endsWithArray<Item
|
|
1488
|
+
declare function endsWithArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean;
|
|
828
1489
|
/**
|
|
829
1490
|
* Does the needle array end the haystack array?
|
|
1491
|
+
*
|
|
830
1492
|
* @param haystack Haystack array
|
|
831
1493
|
* @param needle Needle array
|
|
832
|
-
* @param
|
|
833
|
-
* @
|
|
1494
|
+
* @param key Key to get an item's value for matching
|
|
1495
|
+
* @returns `true` if the haystack ends with the needle, otherwise `false`
|
|
1496
|
+
*
|
|
1497
|
+
* @example
|
|
1498
|
+
* ```typescript
|
|
1499
|
+
* endsWithArray(
|
|
1500
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
1501
|
+
* [{id: 2}, {id: 3}],
|
|
1502
|
+
* 'id',
|
|
1503
|
+
* ); // => true
|
|
1504
|
+
* ```
|
|
834
1505
|
*/
|
|
835
|
-
declare function endsWithArray<Item>(haystack: Item[], needle: Item[],
|
|
1506
|
+
declare function endsWithArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): boolean;
|
|
836
1507
|
/**
|
|
837
1508
|
* Does the needle array end the haystack array?
|
|
1509
|
+
*
|
|
838
1510
|
* @param haystack Haystack array
|
|
839
1511
|
* @param needle Needle array
|
|
840
|
-
* @
|
|
1512
|
+
* @returns `true` if the haystack ends with the needle, otherwise `false`
|
|
1513
|
+
*
|
|
1514
|
+
* @example
|
|
1515
|
+
* ```typescript
|
|
1516
|
+
* endsWithArray([1, 2, 3], [2, 3]); // => true
|
|
1517
|
+
* ```
|
|
841
1518
|
*/
|
|
842
1519
|
declare function endsWithArray<Item>(haystack: Item[], needle: Item[]): boolean;
|
|
843
1520
|
/**
|
|
844
1521
|
* Get the position of an array within another array
|
|
1522
|
+
*
|
|
845
1523
|
* @param haystack Haystack array
|
|
846
1524
|
* @param needle Needle array
|
|
847
|
-
* @param
|
|
1525
|
+
* @param callback Callback to get an item's value for matching
|
|
848
1526
|
* @returns Position of the needle within the haystack
|
|
1527
|
+
*
|
|
1528
|
+
* @example
|
|
1529
|
+
* ```typescript
|
|
1530
|
+
* getArrayComparison(
|
|
1531
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
1532
|
+
* [{id: 2}, {id: 3}],
|
|
1533
|
+
* item => item.id,
|
|
1534
|
+
* ); // => 'end'
|
|
1535
|
+
* ```
|
|
849
1536
|
*/
|
|
850
|
-
declare function getArrayComparison<Item
|
|
1537
|
+
declare function getArrayComparison<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): ArrayComparison;
|
|
851
1538
|
/**
|
|
852
1539
|
* Get the position of an array within another array
|
|
1540
|
+
*
|
|
853
1541
|
* @param haystack Haystack array
|
|
854
1542
|
* @param needle Needle array
|
|
855
|
-
* @param
|
|
1543
|
+
* @param key Key to get an item's value for matching
|
|
856
1544
|
* @returns Position of the needle within the haystack
|
|
1545
|
+
*
|
|
1546
|
+
* @example
|
|
1547
|
+
* ```typescript
|
|
1548
|
+
* getArrayComparison(
|
|
1549
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
1550
|
+
* [{id: 2}, {id: 3}],
|
|
1551
|
+
* 'id',
|
|
1552
|
+
* ); // => 'end'
|
|
1553
|
+
* ```
|
|
857
1554
|
*/
|
|
858
|
-
declare function getArrayComparison<Item>(haystack: Item[], needle: Item[],
|
|
1555
|
+
declare function getArrayComparison<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): ArrayComparison;
|
|
859
1556
|
/**
|
|
860
1557
|
* Get the position of an array within another array
|
|
1558
|
+
*
|
|
861
1559
|
* @param haystack Haystack array
|
|
862
1560
|
* @param needle Needle array
|
|
863
1561
|
* @returns Position of the needle within the haystack
|
|
1562
|
+
*
|
|
1563
|
+
* @example
|
|
1564
|
+
* ```typescript
|
|
1565
|
+
* getArrayComparison([1, 2, 3], [2, 3]); // => 'end'
|
|
1566
|
+
* ```
|
|
864
1567
|
*/
|
|
865
1568
|
declare function getArrayComparison<Item>(haystack: Item[], needle: Item[]): ArrayComparison;
|
|
866
1569
|
/**
|
|
867
1570
|
* Does the needle array exist within the haystack array?
|
|
1571
|
+
*
|
|
868
1572
|
* @param haystack Haystack array
|
|
869
1573
|
* @param needle Needle array
|
|
870
|
-
* @param
|
|
871
|
-
* @
|
|
1574
|
+
* @param callback Callback to get an item's value for matching
|
|
1575
|
+
* @returns `true` if the haystack includes the needle, otherwise `false`
|
|
1576
|
+
*
|
|
1577
|
+
* @example
|
|
1578
|
+
* ```typescript
|
|
1579
|
+
* includesArray(
|
|
1580
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
1581
|
+
* [{id: 2}, {id: 3}],
|
|
1582
|
+
* item => item.id,
|
|
1583
|
+
* ); // => true
|
|
1584
|
+
* ```
|
|
872
1585
|
*/
|
|
873
|
-
declare function includesArray<Item
|
|
1586
|
+
declare function includesArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean;
|
|
874
1587
|
/**
|
|
875
1588
|
* Does the needle array exist within the haystack array?
|
|
1589
|
+
*
|
|
876
1590
|
* @param haystack Haystack array
|
|
877
1591
|
* @param needle Needle array
|
|
878
|
-
* @param
|
|
879
|
-
* @
|
|
1592
|
+
* @param key Key to get an item's value for matching
|
|
1593
|
+
* @returns `true` if the haystack includes the needle, otherwise `false`
|
|
1594
|
+
*
|
|
1595
|
+
* @example
|
|
1596
|
+
* ```typescript
|
|
1597
|
+
* includesArray(
|
|
1598
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
1599
|
+
* [{id: 2}, {id: 3}],
|
|
1600
|
+
* 'id',
|
|
1601
|
+
* ); // => true
|
|
1602
|
+
* ```
|
|
880
1603
|
*/
|
|
881
|
-
declare function includesArray<Item>(haystack: Item[], needle: Item[],
|
|
1604
|
+
declare function includesArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): boolean;
|
|
882
1605
|
/**
|
|
883
1606
|
* Does the needle array exist within the haystack array?
|
|
1607
|
+
*
|
|
884
1608
|
* @param haystack Haystack array
|
|
885
1609
|
* @param needle Needle array
|
|
886
|
-
* @
|
|
1610
|
+
* @returns `true` if the haystack includes the needle, otherwise `false`
|
|
1611
|
+
*
|
|
1612
|
+
* @example
|
|
1613
|
+
* ```typescript
|
|
1614
|
+
* includesArray([1, 2, 3], [2, 3]); // => true
|
|
1615
|
+
* ```
|
|
887
1616
|
*/
|
|
888
1617
|
declare function includesArray<Item>(haystack: Item[], needle: Item[]): boolean;
|
|
889
1618
|
/**
|
|
890
1619
|
* Get the index of an array within another array
|
|
1620
|
+
*
|
|
891
1621
|
* @param haystack Haystack array
|
|
892
1622
|
* @param needle Needle array
|
|
893
|
-
* @param
|
|
894
|
-
* @
|
|
1623
|
+
* @param callback Callback to get an item's value for matching
|
|
1624
|
+
* @returns Index of the needle's start within the haystack, or `-1` if it is not found
|
|
1625
|
+
*
|
|
1626
|
+
* @example
|
|
1627
|
+
* ```typescript
|
|
1628
|
+
* indexOfArray(
|
|
1629
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
1630
|
+
* [{id: 2}, {id: 3}],
|
|
1631
|
+
* item => item.id,
|
|
1632
|
+
* ); // => 1
|
|
1633
|
+
* ```
|
|
895
1634
|
*/
|
|
896
|
-
declare function indexOfArray<Item
|
|
1635
|
+
declare function indexOfArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): number;
|
|
897
1636
|
/**
|
|
898
1637
|
* Get the index of an array within another array
|
|
1638
|
+
*
|
|
899
1639
|
* @param haystack Haystack array
|
|
900
1640
|
* @param needle Needle array
|
|
901
|
-
* @param
|
|
902
|
-
* @
|
|
1641
|
+
* @param key Key to get an item's value for matching
|
|
1642
|
+
* @returns Index of the needle's start within the haystack, or `-1` if it is not found
|
|
1643
|
+
*
|
|
1644
|
+
* @example
|
|
1645
|
+
* ```typescript
|
|
1646
|
+
* indexOfArray(
|
|
1647
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
1648
|
+
* [{id: 2}, {id: 3}],
|
|
1649
|
+
* 'id',
|
|
1650
|
+
* ); // => 1
|
|
1651
|
+
* ```
|
|
903
1652
|
*/
|
|
904
|
-
declare function indexOfArray<Item>(haystack: Item[], needle: Item[],
|
|
1653
|
+
declare function indexOfArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): number;
|
|
905
1654
|
/**
|
|
906
1655
|
* Get the index of an array within another array
|
|
1656
|
+
*
|
|
907
1657
|
* @param haystack Haystack array
|
|
908
1658
|
* @param needle Needle array
|
|
909
|
-
* @
|
|
1659
|
+
* @returns Index of the needle's start within the haystack, or `-1` if it is not found
|
|
1660
|
+
*
|
|
1661
|
+
* @example
|
|
1662
|
+
* ```typescript
|
|
1663
|
+
* indexOfArray([1, 2, 3], [2, 3]); // => 1
|
|
1664
|
+
* ```
|
|
910
1665
|
*/
|
|
911
1666
|
declare function indexOfArray<Item>(haystack: Item[], needle: Item[]): number;
|
|
912
1667
|
/**
|
|
913
1668
|
* Does the needle array start the haystack array?
|
|
1669
|
+
*
|
|
914
1670
|
* @param haystack Haystack array
|
|
915
1671
|
* @param needle Needle array
|
|
916
|
-
* @param
|
|
917
|
-
* @
|
|
1672
|
+
* @param callback Callback to get an item's value for matching
|
|
1673
|
+
* @returns `true` if the haystack starts with the needle, otherwise `false`
|
|
1674
|
+
*
|
|
1675
|
+
* @example
|
|
1676
|
+
* ```typescript
|
|
1677
|
+
* startsWithArray(
|
|
1678
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
1679
|
+
* [{id: 1}, {id: 2}],
|
|
1680
|
+
* item => item.id,
|
|
1681
|
+
* ); // => true
|
|
1682
|
+
* ```
|
|
918
1683
|
*/
|
|
919
|
-
declare function startsWithArray<Item
|
|
1684
|
+
declare function startsWithArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean;
|
|
920
1685
|
/**
|
|
921
1686
|
* Does the needle array start the haystack array?
|
|
1687
|
+
*
|
|
922
1688
|
* @param haystack Haystack array
|
|
923
1689
|
* @param needle Needle array
|
|
924
|
-
* @param
|
|
925
|
-
* @
|
|
1690
|
+
* @param key Key to get an item's value for matching
|
|
1691
|
+
* @returns `true` if the haystack starts with the needle, otherwise `false`
|
|
1692
|
+
*
|
|
1693
|
+
* @example
|
|
1694
|
+
* ```typescript
|
|
1695
|
+
* startsWithArray(
|
|
1696
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
1697
|
+
* [{id: 1}, {id: 2}],
|
|
1698
|
+
* 'id',
|
|
1699
|
+
* ); // => true
|
|
1700
|
+
* ```
|
|
926
1701
|
*/
|
|
927
|
-
declare function startsWithArray<Item>(haystack: Item[], needle: Item[],
|
|
1702
|
+
declare function startsWithArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): boolean;
|
|
928
1703
|
/**
|
|
929
1704
|
* Does the needle array start the haystack array?
|
|
1705
|
+
*
|
|
930
1706
|
* @param haystack Haystack array
|
|
931
1707
|
* @param needle Needle array
|
|
932
|
-
* @
|
|
1708
|
+
* @returns `true` if the haystack starts with the needle, otherwise `false`
|
|
1709
|
+
*
|
|
1710
|
+
* @example
|
|
1711
|
+
* ```typescript
|
|
1712
|
+
* startsWithArray([1, 2, 3], [1, 2]); // => true
|
|
1713
|
+
* ```
|
|
933
1714
|
*/
|
|
934
1715
|
declare function startsWithArray<Item>(haystack: Item[], needle: Item[]): boolean;
|
|
935
1716
|
//#endregion
|
|
936
1717
|
//#region src/array/push.d.ts
|
|
937
1718
|
/**
|
|
938
1719
|
* Push items into an array _(at the end)_
|
|
1720
|
+
*
|
|
1721
|
+
* _(Uses chunking to avoid call stack size being exceeded)_
|
|
1722
|
+
*
|
|
939
1723
|
* @param array Original array
|
|
940
1724
|
* @param pushed Pushed items
|
|
941
1725
|
* @returns New length of the array
|
|
1726
|
+
*
|
|
1727
|
+
* @example
|
|
1728
|
+
* ```typescript
|
|
1729
|
+
* push([1, 2, 3], [4, 5]); // => 5 (new length); array becomes [1, 2, 3, 4, 5]
|
|
1730
|
+
* ```
|
|
942
1731
|
*/
|
|
943
1732
|
declare function push<Item>(array: Item[], pushed: Item[]): number;
|
|
944
1733
|
//#endregion
|
|
945
1734
|
//#region src/array/reverse.d.ts
|
|
946
1735
|
/**
|
|
947
1736
|
* Reverse the order of items in an array
|
|
1737
|
+
*
|
|
948
1738
|
* @param array Array to reverse
|
|
949
1739
|
* @returns Reversed array
|
|
950
1740
|
*/
|
|
@@ -953,46 +1743,100 @@ declare function reverse<Item>(array: Item[]): Item[];
|
|
|
953
1743
|
//#region src/array/select.d.ts
|
|
954
1744
|
/**
|
|
955
1745
|
* Get a filtered and mapped array of items
|
|
1746
|
+
*
|
|
956
1747
|
* @param array Array to search in
|
|
957
1748
|
* @param filterCallback Callback to get an item's value for matching
|
|
958
1749
|
* @param filterValue Value to match against
|
|
959
1750
|
* @param mapCallback Callback to map the matched items
|
|
960
1751
|
* @returns Filtered and mapped array of items
|
|
1752
|
+
*
|
|
1753
|
+
* @example
|
|
1754
|
+
* ```typescript
|
|
1755
|
+
* select(
|
|
1756
|
+
* [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
|
|
1757
|
+
* item => item.id,
|
|
1758
|
+
* 2,
|
|
1759
|
+
* item => item.name,
|
|
1760
|
+
* ); // => ['Bob']
|
|
1761
|
+
* ```
|
|
961
1762
|
*/
|
|
962
1763
|
declare function select<Item, FilterCallback extends (item: Item, index: number, array: Item[]) => unknown, MapCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], filterCallback: FilterCallback, filterValue: ReturnType<FilterCallback>, mapCallback: MapCallback): Array<ReturnType<MapCallback>>;
|
|
963
1764
|
/**
|
|
964
1765
|
* Get a filtered and mapped array of items
|
|
1766
|
+
*
|
|
965
1767
|
* @param array Array to search in
|
|
966
1768
|
* @param filterCallback Callback to get an item's value for matching
|
|
967
1769
|
* @param filterValue Value to match against
|
|
968
1770
|
* @param mapKey Key to get an item's value for mapping
|
|
969
1771
|
* @returns Filtered and mapped array of items
|
|
1772
|
+
*
|
|
1773
|
+
* @example
|
|
1774
|
+
* ```typescript
|
|
1775
|
+
* select(
|
|
1776
|
+
* [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
|
|
1777
|
+
* item => item.id,
|
|
1778
|
+
* 2,
|
|
1779
|
+
* 'name',
|
|
1780
|
+
* ); // => ['Bob']
|
|
1781
|
+
* ```
|
|
970
1782
|
*/
|
|
971
1783
|
declare function select<Item extends PlainObject, FilterCallback extends (item: Item, index: number, array: Item[]) => unknown, MapKey extends keyof Item>(array: Item[], filterCallback: FilterCallback, filterValue: ReturnType<FilterCallback>, mapKey: MapKey): Array<Item[MapKey]>;
|
|
972
1784
|
/**
|
|
973
1785
|
* Get a filtered and mapped array of items
|
|
1786
|
+
*
|
|
974
1787
|
* @param array Array to search in
|
|
975
1788
|
* @param filterKey Key to get an item's value for matching
|
|
976
1789
|
* @param filterValue Value to match against
|
|
977
1790
|
* @param mapCallback Callback to map the matched items
|
|
978
1791
|
* @returns Filtered and mapped array of items
|
|
1792
|
+
*
|
|
1793
|
+
* @example
|
|
1794
|
+
* ```typescript
|
|
1795
|
+
* select(
|
|
1796
|
+
* [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
|
|
1797
|
+
* 'id',
|
|
1798
|
+
* 2,
|
|
1799
|
+
* item => item.name,
|
|
1800
|
+
* ); // => ['Bob']
|
|
1801
|
+
* ```
|
|
979
1802
|
*/
|
|
980
1803
|
declare function select<Item extends PlainObject, ItemKey extends keyof Item, MapCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], filterKey: ItemKey, filterValue: Item[ItemKey], mapCallback: MapCallback): Array<ReturnType<MapCallback>>;
|
|
981
1804
|
/**
|
|
982
1805
|
* Get a filtered and mapped array of items
|
|
1806
|
+
*
|
|
983
1807
|
* @param array Array to search in
|
|
984
1808
|
* @param filterKey Key to get an item's value for matching
|
|
985
1809
|
* @param filterValue Value to match against
|
|
986
1810
|
* @param mapKey Key to get an item's value for mapping
|
|
987
1811
|
* @returns Filtered and mapped array of items
|
|
1812
|
+
*
|
|
1813
|
+
* @example
|
|
1814
|
+
* ```typescript
|
|
1815
|
+
* select(
|
|
1816
|
+
* [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
|
|
1817
|
+
* 'id',
|
|
1818
|
+
* 2,
|
|
1819
|
+
* 'name',
|
|
1820
|
+
* ); // => ['Bob']
|
|
1821
|
+
* ```
|
|
988
1822
|
*/
|
|
989
1823
|
declare function select<Item extends PlainObject, ItemKey extends keyof Item, MapKey extends keyof Item>(array: Item[], filterKey: ItemKey, filterValue: Item[ItemKey], mapKey: MapKey): Array<Item[MapKey]>;
|
|
990
1824
|
/**
|
|
991
1825
|
* Get a filtered and mapped array of items
|
|
1826
|
+
*
|
|
992
1827
|
* @param array Array to search in
|
|
993
1828
|
* @param filterCallback Filter callback to match items
|
|
994
1829
|
* @param mapCallback Callback to map the matched items
|
|
995
1830
|
* @returns Filtered and mapped array of items
|
|
1831
|
+
*
|
|
1832
|
+
* @example
|
|
1833
|
+
* ```typescript
|
|
1834
|
+
* select(
|
|
1835
|
+
* [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
|
|
1836
|
+
* item => item.id === 2,
|
|
1837
|
+
* item => item.name,
|
|
1838
|
+
* ); // => ['Bob']
|
|
1839
|
+
* ```
|
|
996
1840
|
*/
|
|
997
1841
|
declare function select<Item, FilterCallback extends (item: Item, index: number, array: Item[]) => unknown, MapCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], filterCallback: FilterCallback, filterValue: ReturnType<FilterCallback>, mapCallback: MapCallback): Array<ReturnType<MapCallback>>;
|
|
998
1842
|
/**
|
|
@@ -1001,336 +1845,717 @@ declare function select<Item, FilterCallback extends (item: Item, index: number,
|
|
|
1001
1845
|
* @param filterCallback Filter callback to match items
|
|
1002
1846
|
* @param mapKey Key to get an item's value for mapping
|
|
1003
1847
|
* @returns Filtered and mapped array of items
|
|
1848
|
+
*
|
|
1849
|
+
* @example
|
|
1850
|
+
* ```typescript
|
|
1851
|
+
* select(
|
|
1852
|
+
* [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
|
|
1853
|
+
* item => item.id,
|
|
1854
|
+
* 2,
|
|
1855
|
+
* 'name'
|
|
1856
|
+
* ); // => ['Bob']
|
|
1857
|
+
* ```
|
|
1004
1858
|
*/
|
|
1005
1859
|
declare function select<Item extends PlainObject, FilterCallback extends (item: Item, index: number, array: Item[]) => unknown, MapKey extends keyof Item>(array: Item[], filterCallback: FilterCallback, filterValue: ReturnType<FilterCallback>, mapKey: MapKey): Array<Item[MapKey]>;
|
|
1006
1860
|
/**
|
|
1007
1861
|
* Get a filtered and mapped array of items
|
|
1862
|
+
*
|
|
1008
1863
|
* @param array Array to search in
|
|
1009
1864
|
* @param filter Filter callback to match items
|
|
1010
1865
|
* @param map Callback to map the matched items
|
|
1011
1866
|
* @returns Filtered and mapped array of items
|
|
1867
|
+
*
|
|
1868
|
+
* @example
|
|
1869
|
+
* ```typescript
|
|
1870
|
+
* select(
|
|
1871
|
+
* [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
|
|
1872
|
+
* item => item.id === 2,
|
|
1873
|
+
* item => item.name,
|
|
1874
|
+
* ); // => ['Bob']
|
|
1875
|
+
* ```
|
|
1012
1876
|
*/
|
|
1013
1877
|
declare function select<Item, MapCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean, map: MapCallback): Array<ReturnType<MapCallback>>;
|
|
1014
1878
|
/**
|
|
1015
1879
|
* Get a filtered and mapped array of items
|
|
1880
|
+
*
|
|
1016
1881
|
* @param array Array to search in
|
|
1017
1882
|
* @param filter Filter callback to match items
|
|
1018
1883
|
* @param map Key to get an item's value for mapping
|
|
1019
1884
|
* @returns Filtered and mapped array of items
|
|
1885
|
+
*
|
|
1886
|
+
* @example
|
|
1887
|
+
* ```typescript
|
|
1888
|
+
* select(
|
|
1889
|
+
* [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
|
|
1890
|
+
* item => item.id === 2,
|
|
1891
|
+
* 'name'
|
|
1892
|
+
* ); // => ['Bob']
|
|
1893
|
+
* ```
|
|
1020
1894
|
*/
|
|
1021
1895
|
declare function select<Item extends PlainObject, MapKey extends keyof Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean, map: MapKey): Array<Item[MapKey]>;
|
|
1022
1896
|
/**
|
|
1023
1897
|
* Get a filtered and mapped array of items
|
|
1898
|
+
*
|
|
1024
1899
|
* @param array Array to search in
|
|
1025
1900
|
* @param item Item to match against
|
|
1026
1901
|
* @param map Callback to map the matched items
|
|
1027
1902
|
* @returns Filtered and mapped array of items
|
|
1903
|
+
*
|
|
1904
|
+
* @example
|
|
1905
|
+
* ```typescript
|
|
1906
|
+
* select(
|
|
1907
|
+
* [1, 2, 3, 2, 1],
|
|
1908
|
+
* 3,
|
|
1909
|
+
* value => value ** 2,
|
|
1910
|
+
* ); // => [9]
|
|
1911
|
+
* ```
|
|
1028
1912
|
*/
|
|
1029
1913
|
declare function select<Item, MapCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], item: Item, map: MapCallback): Array<ReturnType<MapCallback>>;
|
|
1030
|
-
/**
|
|
1031
|
-
* Get a filtered and mapped array of items
|
|
1032
|
-
* @param array Array to search in
|
|
1033
|
-
* @param item Item to match against
|
|
1034
|
-
* @param map Key to get an item's value for mapping
|
|
1035
|
-
* @returns Filtered and mapped array of items
|
|
1036
|
-
*/
|
|
1037
|
-
declare function select<Item extends PlainObject, MapKey extends keyof Item>(array: Item[], item: Item, map: MapKey): Array<Item[MapKey]>;
|
|
1038
1914
|
//#endregion
|
|
1039
1915
|
//#region src/array/single.d.ts
|
|
1040
1916
|
/**
|
|
1041
1917
|
* Get the _only_ item matching the given value
|
|
1042
1918
|
*
|
|
1043
1919
|
* Throws an error if multiple items match the value
|
|
1920
|
+
*
|
|
1044
1921
|
* @param array Array to search in
|
|
1045
1922
|
* @param callback Callback to get an item's value for matching
|
|
1046
1923
|
* @param value Value to match against
|
|
1047
1924
|
* @returns Only item that matches the value, or `undefined` if no match is found
|
|
1925
|
+
*
|
|
1926
|
+
* @example
|
|
1927
|
+
* ```typescript
|
|
1928
|
+
* single(
|
|
1929
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
1930
|
+
* item => item.id,
|
|
1931
|
+
* 2
|
|
1932
|
+
* ); // => {id: 2}
|
|
1933
|
+
* ```
|
|
1048
1934
|
*/
|
|
1049
1935
|
declare function single<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item | undefined;
|
|
1050
1936
|
/**
|
|
1051
1937
|
* Get the _only_ item matching the given value by key
|
|
1052
1938
|
*
|
|
1053
1939
|
* Throws an error if multiple items match the value
|
|
1940
|
+
*
|
|
1054
1941
|
* @param array Array to search in
|
|
1055
1942
|
* @param key Key to get an item's value for matching
|
|
1056
1943
|
* @param value Value to match against
|
|
1057
1944
|
* @returns Only item that matches the value, or `undefined` if no match is found
|
|
1945
|
+
*
|
|
1946
|
+
* @example
|
|
1947
|
+
* ```typescript
|
|
1948
|
+
* single(
|
|
1949
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
1950
|
+
* 'id',
|
|
1951
|
+
* 2
|
|
1952
|
+
* ); // => {id: 2}
|
|
1953
|
+
* ```
|
|
1058
1954
|
*/
|
|
1059
1955
|
declare function single<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
|
|
1060
1956
|
/**
|
|
1061
1957
|
* Get the _only_ item matching the filter
|
|
1062
1958
|
*
|
|
1063
1959
|
* Throws an error if multiple items match the filter
|
|
1960
|
+
*
|
|
1064
1961
|
* @param array Array to search in
|
|
1065
1962
|
* @param filter Filter callback to match items
|
|
1066
1963
|
* @returns Only item that matches the filter, or `undefined` if no match is found
|
|
1964
|
+
*
|
|
1965
|
+
* @example
|
|
1966
|
+
* ```typescript
|
|
1967
|
+
* single(
|
|
1968
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
1969
|
+
* item => item.id === 2
|
|
1970
|
+
* ); // => {id: 2}
|
|
1971
|
+
* ```
|
|
1067
1972
|
*/
|
|
1068
1973
|
declare function single<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item | undefined;
|
|
1069
1974
|
//#endregion
|
|
1070
1975
|
//#region src/array/slice.d.ts
|
|
1071
1976
|
/**
|
|
1072
1977
|
* Drop items from the start of an array until they match a value
|
|
1978
|
+
*
|
|
1073
1979
|
* @param array Original array
|
|
1074
|
-
* @param
|
|
1980
|
+
* @param callback Callback to get an item's value for matching
|
|
1075
1981
|
* @param value Value to match against
|
|
1076
1982
|
* @returns New array with items dropped
|
|
1983
|
+
*
|
|
1984
|
+
* @example
|
|
1985
|
+
* ```typescript
|
|
1986
|
+
* drop(
|
|
1987
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
1988
|
+
* item => item.id,
|
|
1989
|
+
* 2,
|
|
1990
|
+
* ); // => [{id: 2}, {id: 3}]
|
|
1991
|
+
* ```
|
|
1077
1992
|
*/
|
|
1078
|
-
declare function drop<Item extends
|
|
1993
|
+
declare function drop<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[];
|
|
1079
1994
|
/**
|
|
1080
1995
|
* Drop items from the start of an array until they match a value
|
|
1996
|
+
*
|
|
1081
1997
|
* @param array Original array
|
|
1082
|
-
* @param
|
|
1998
|
+
* @param key Key to get an item's value for matching
|
|
1083
1999
|
* @param value Value to match against
|
|
1084
|
-
* @
|
|
2000
|
+
* @returns New array with items dropped
|
|
2001
|
+
*
|
|
2002
|
+
* @example
|
|
2003
|
+
* ```typescript
|
|
2004
|
+
* drop(
|
|
2005
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
2006
|
+
* 'id',
|
|
2007
|
+
* 2,
|
|
2008
|
+
* ); // => [{id: 2}, {id: 3}]
|
|
2009
|
+
* ```
|
|
1085
2010
|
*/
|
|
1086
|
-
declare function drop<Item
|
|
2011
|
+
declare function drop<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[];
|
|
1087
2012
|
/**
|
|
1088
2013
|
* Drop items from the start of an array while they match a filter
|
|
2014
|
+
*
|
|
1089
2015
|
* @param array Original array
|
|
1090
2016
|
* @param callback Filter callback to match items
|
|
1091
|
-
* @
|
|
2017
|
+
* @returns New array with items dropped
|
|
2018
|
+
*
|
|
2019
|
+
* @example
|
|
2020
|
+
* ```typescript
|
|
2021
|
+
* drop(
|
|
2022
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
2023
|
+
* item => item.id === 2,
|
|
2024
|
+
* ); // => [{id: 2}, {id: 3}]
|
|
2025
|
+
* ```
|
|
1092
2026
|
*/
|
|
1093
2027
|
declare function drop<Item extends PlainObject>(array: Item[], callback: (item: Item, index: number, array: Item[]) => boolean): Item[];
|
|
1094
2028
|
/**
|
|
1095
2029
|
* Drop a specified number of items, from the start if `>= 0`, or from the end if `< 0`
|
|
2030
|
+
*
|
|
1096
2031
|
* @param array Original array
|
|
1097
2032
|
* @param count Number of items to drop
|
|
1098
2033
|
* @returns New array with items dropped
|
|
2034
|
+
*
|
|
2035
|
+
* @example
|
|
2036
|
+
* ```typescript
|
|
2037
|
+
* drop([1, 2, 3, 4, 5], 2); // => [3, 4, 5]
|
|
2038
|
+
* drop([1, 2, 3, 4, 5], -2); // => [1, 2, 3]
|
|
2039
|
+
* ```
|
|
1099
2040
|
*/
|
|
1100
2041
|
declare function drop(array: unknown[], count: number): unknown[];
|
|
1101
2042
|
/**
|
|
1102
2043
|
* Slice an array, returning a new array with a specified range of items
|
|
2044
|
+
*
|
|
1103
2045
|
* @param array Original array
|
|
1104
2046
|
* @param start Start index _(inclusive)_
|
|
1105
2047
|
* @param end End index _(exclusive)_
|
|
1106
|
-
* @
|
|
2048
|
+
* @returns New array with sliced items
|
|
2049
|
+
*
|
|
2050
|
+
* @example
|
|
2051
|
+
* ```typescript
|
|
2052
|
+
* slice([1, 2, 3, 4, 5], 1, 4); // => [2, 3, 4]
|
|
2053
|
+
* ```
|
|
1107
2054
|
*/
|
|
1108
2055
|
declare function slice<Item>(array: Item[], start: number, end: number): Item[];
|
|
1109
2056
|
/**
|
|
1110
|
-
* Slice an array, returning a new array with a specified number of items
|
|
2057
|
+
* Slice an array, returning a new array with a specified number of items _(from the start)_
|
|
2058
|
+
*
|
|
1111
2059
|
* @param array Original array
|
|
1112
|
-
* @param count Maximum
|
|
1113
|
-
* @
|
|
2060
|
+
* @param count Maximum size of the new array
|
|
2061
|
+
* @returns New array with sliced items
|
|
2062
|
+
*
|
|
2063
|
+
* @example
|
|
2064
|
+
* ```typescript
|
|
2065
|
+
* slice([1, 2, 3, 4, 5], 3); // => [1, 2, 3]
|
|
2066
|
+
* ```
|
|
1114
2067
|
*/
|
|
1115
2068
|
declare function slice<Item>(array: Item[], count: number): Item[];
|
|
1116
2069
|
/**
|
|
1117
2070
|
* Slice an array
|
|
2071
|
+
*
|
|
1118
2072
|
* @param array Array to slice
|
|
1119
2073
|
* @returns Sliced array
|
|
2074
|
+
*
|
|
2075
|
+
* @example
|
|
2076
|
+
* ```typescript
|
|
2077
|
+
* slice([1, 2, 3]); // => [1, 2, 3]
|
|
2078
|
+
* ```
|
|
1120
2079
|
*/
|
|
1121
2080
|
declare function slice<Item>(array: Item[]): Item[];
|
|
1122
2081
|
/**
|
|
1123
2082
|
* Take items from the start of an array until they match a value
|
|
2083
|
+
*
|
|
1124
2084
|
* @param array Original array
|
|
1125
|
-
* @param
|
|
2085
|
+
* @param callback Callback to get an item's value for matching
|
|
1126
2086
|
* @param value Value to match against
|
|
1127
2087
|
* @returns New array with taken items
|
|
2088
|
+
*
|
|
2089
|
+
* @example
|
|
2090
|
+
* ```typescript
|
|
2091
|
+
* take(
|
|
2092
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
2093
|
+
* item => item.id,
|
|
2094
|
+
* 2,
|
|
2095
|
+
* ); // => [{id: 1}]
|
|
2096
|
+
* ```
|
|
1128
2097
|
*/
|
|
1129
|
-
declare function take<Item extends
|
|
2098
|
+
declare function take<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[];
|
|
1130
2099
|
/**
|
|
1131
2100
|
* Take items from the start of an array until they match a value
|
|
2101
|
+
*
|
|
1132
2102
|
* @param array Original array
|
|
1133
|
-
* @param
|
|
2103
|
+
* @param key Key to get an item's value for matching
|
|
1134
2104
|
* @param value Value to match against
|
|
1135
|
-
* @
|
|
2105
|
+
* @returns New array with taken items
|
|
2106
|
+
*
|
|
2107
|
+
* @example
|
|
2108
|
+
* ```typescript
|
|
2109
|
+
* take(
|
|
2110
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
2111
|
+
* 'id',
|
|
2112
|
+
* 2,
|
|
2113
|
+
* ); // => [{id: 1}]
|
|
2114
|
+
* ```
|
|
1136
2115
|
*/
|
|
1137
|
-
declare function take<Item
|
|
2116
|
+
declare function take<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[];
|
|
1138
2117
|
/**
|
|
1139
2118
|
* Take items from the start of an array while they match a filter
|
|
2119
|
+
*
|
|
1140
2120
|
* @param array Original array
|
|
1141
2121
|
* @param callback Filter callback to match items
|
|
1142
|
-
* @
|
|
2122
|
+
* @returns New array with taken items
|
|
2123
|
+
*
|
|
2124
|
+
* @example
|
|
2125
|
+
* ```typescript
|
|
2126
|
+
* take(
|
|
2127
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
2128
|
+
* item => item.id === 2,
|
|
2129
|
+
* ); // => [{id: 1}]
|
|
2130
|
+
* ```
|
|
1143
2131
|
*/
|
|
1144
2132
|
declare function take<Item extends PlainObject>(array: Item[], callback: (item: Item, index: number, array: Item[]) => boolean): Item[];
|
|
1145
2133
|
/**
|
|
1146
2134
|
* Take a specified number of items, from the start if `>= 0`, or from the end if `< 0`
|
|
2135
|
+
*
|
|
1147
2136
|
* @param array Original array
|
|
1148
2137
|
* @param count Number of items to take
|
|
1149
2138
|
* @returns New array with taken items
|
|
2139
|
+
*
|
|
2140
|
+
* @example
|
|
2141
|
+
* ```typescript
|
|
2142
|
+
* take([1, 2, 3, 4, 5], 2); // => [1, 2]
|
|
2143
|
+
* take([1, 2, 3, 4, 5], -2); // => [4, 5]
|
|
2144
|
+
* ```
|
|
1150
2145
|
*/
|
|
1151
2146
|
declare function take(array: unknown[], count: number): unknown[];
|
|
1152
2147
|
//#endregion
|
|
1153
2148
|
//#region src/array/splice.d.ts
|
|
1154
2149
|
/**
|
|
1155
2150
|
* Adds items into an array at a specific index and removes a specific amount of items
|
|
2151
|
+
*
|
|
2152
|
+
* _(Uses chunking to avoid call stack size being exceeded)_
|
|
2153
|
+
*
|
|
1156
2154
|
* @param array Original array
|
|
1157
2155
|
* @param start Index to start splicing from
|
|
1158
2156
|
* @param amount Number of items to remove
|
|
1159
2157
|
* @param added Added items
|
|
1160
2158
|
* @returns Removed items
|
|
2159
|
+
*
|
|
2160
|
+
* @example
|
|
2161
|
+
* ```typescript
|
|
2162
|
+
* splice(
|
|
2163
|
+
* [1, 2, 3, 4, 5],
|
|
2164
|
+
* 2,
|
|
2165
|
+
* 2,
|
|
2166
|
+
* [6, 7]
|
|
2167
|
+
* ); // => [3, 4], array becomes [1, 2, 6, 7, 5]
|
|
2168
|
+
* ```
|
|
1161
2169
|
*/
|
|
1162
2170
|
declare function splice<Item>(array: Item[], start: number, amount: number, added: Item[]): Item[];
|
|
1163
2171
|
/**
|
|
1164
2172
|
* Adds items into an array at a specific index
|
|
2173
|
+
*
|
|
2174
|
+
* _(Uses chunking to avoid call stack size being exceeded)_
|
|
2175
|
+
*
|
|
1165
2176
|
* @param array Original array
|
|
1166
2177
|
* @param start Index to start splicing from
|
|
1167
2178
|
* @param added Added items
|
|
1168
2179
|
* @returns Removed items
|
|
2180
|
+
*
|
|
2181
|
+
* @example
|
|
2182
|
+
* ```typescript
|
|
2183
|
+
* splice(
|
|
2184
|
+
* [1, 2, 3, 4, 5],
|
|
2185
|
+
* 2,
|
|
2186
|
+
* [6, 7]
|
|
2187
|
+
* ); // => [], array becomes [1, 2, 6, 7, 3, 4, 5]
|
|
2188
|
+
* ```
|
|
1169
2189
|
*/
|
|
1170
2190
|
declare function splice<Item>(array: Item[], start: number, added: Item[]): Item[];
|
|
1171
2191
|
/**
|
|
1172
2192
|
* Removes and returns _(up to)_ a specific amount of items from an array, starting from a specific index
|
|
2193
|
+
*
|
|
2194
|
+
* _(Uses chunking to avoid call stack size being exceeded)_
|
|
2195
|
+
*
|
|
1173
2196
|
* @param array Original array
|
|
1174
2197
|
* @param start Index to start splicing from
|
|
1175
2198
|
* @param amount Number of items to remove
|
|
1176
2199
|
* @returns Removed items
|
|
2200
|
+
*
|
|
2201
|
+
* @example
|
|
2202
|
+
* ```typescript
|
|
2203
|
+
* splice(
|
|
2204
|
+
* [1, 2, 3, 4, 5],
|
|
2205
|
+
* 2,
|
|
2206
|
+
* 2,
|
|
2207
|
+
* ); // => [3, 4], array becomes [1, 2, 5]
|
|
2208
|
+
* ```
|
|
1177
2209
|
*/
|
|
1178
2210
|
declare function splice<Item>(array: Item[], start: number, amount: number): Item[];
|
|
1179
2211
|
/**
|
|
1180
2212
|
* Removes and returns all items from an array starting from a specific index
|
|
2213
|
+
*
|
|
2214
|
+
* _(Uses chunking to avoid call stack size being exceeded)_
|
|
2215
|
+
*
|
|
1181
2216
|
* @param array Original array
|
|
1182
2217
|
* @param start Index to start splicing from
|
|
1183
2218
|
* @returns Removed items
|
|
2219
|
+
*
|
|
2220
|
+
* @example
|
|
2221
|
+
* ```typescript
|
|
2222
|
+
* splice(
|
|
2223
|
+
* [1, 2, 3, 4, 5],
|
|
2224
|
+
* 2,
|
|
2225
|
+
* ); // => [3, 4, 5], array becomes [1, 2]
|
|
2226
|
+
* ```
|
|
1184
2227
|
*/
|
|
1185
2228
|
declare function splice<Item>(array: Item[], start: number): Item[];
|
|
1186
2229
|
//#endregion
|
|
1187
2230
|
//#region src/array/to-set.d.ts
|
|
1188
2231
|
/**
|
|
1189
2232
|
* Create a Set from an array of items using a callback
|
|
2233
|
+
*
|
|
1190
2234
|
* @param array Array to convert
|
|
1191
2235
|
* @param callback Callback to get an item's value
|
|
1192
2236
|
* @returns Set of values
|
|
2237
|
+
*
|
|
2238
|
+
* @example
|
|
2239
|
+
* ```typescript
|
|
2240
|
+
* toSet(
|
|
2241
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
2242
|
+
* item => item.id,
|
|
2243
|
+
* ); // => Set { 1, 2, 3 }
|
|
2244
|
+
* ```
|
|
1193
2245
|
*/
|
|
1194
2246
|
declare function toSet<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback): Set<ReturnType<Callback>>;
|
|
1195
2247
|
/**
|
|
1196
2248
|
* Create a Set from an array of items using a key
|
|
2249
|
+
*
|
|
1197
2250
|
* @param array Array to convert
|
|
1198
2251
|
* @param key Key to use for value
|
|
1199
2252
|
* @returns Set of values
|
|
2253
|
+
*
|
|
2254
|
+
* @example
|
|
2255
|
+
* ```typescript
|
|
2256
|
+
* toSet(
|
|
2257
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
2258
|
+
* 'id',
|
|
2259
|
+
* ); // => Set { 1, 2, 3 }
|
|
2260
|
+
* ```
|
|
1200
2261
|
*/
|
|
1201
2262
|
declare function toSet<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Set<Item[ItemKey]>;
|
|
1202
2263
|
/**
|
|
1203
2264
|
* Create a Set from an array of items
|
|
2265
|
+
*
|
|
1204
2266
|
* @param array Array to convert
|
|
1205
2267
|
* @returns Set of items
|
|
2268
|
+
*
|
|
2269
|
+
* @example
|
|
2270
|
+
* ```typescript
|
|
2271
|
+
* toSet([1, 2, 3]); // => Set { 1, 2, 3 }
|
|
2272
|
+
* ```
|
|
1206
2273
|
*/
|
|
1207
2274
|
declare function toSet<Item>(array: Item[]): Set<Item>;
|
|
1208
2275
|
//#endregion
|
|
1209
2276
|
//#region src/array/toggle.d.ts
|
|
1210
2277
|
/**
|
|
1211
|
-
* Toggle an item in an array
|
|
2278
|
+
* Toggle an item in an array
|
|
2279
|
+
*
|
|
2280
|
+
* If the item exists, it will be removed; if it doesn't, it will be added
|
|
2281
|
+
*
|
|
1212
2282
|
* @param destination Array to toggle within
|
|
1213
2283
|
* @param toggled Toggled items
|
|
1214
2284
|
* @param callback Callback to find existing item
|
|
1215
2285
|
* @returns Original array
|
|
2286
|
+
*
|
|
2287
|
+
* @example
|
|
2288
|
+
* ```typescript
|
|
2289
|
+
* toggle(
|
|
2290
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
2291
|
+
* [{id: 2}, {id: 4}],
|
|
2292
|
+
* item => item.id,
|
|
2293
|
+
* ); // => [{id: 1}, {id: 3}, {id: 4}]
|
|
2294
|
+
* ```
|
|
1216
2295
|
*/
|
|
1217
2296
|
declare function toggle<Item>(destination: Item[], toggled: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
|
|
1218
2297
|
/**
|
|
1219
|
-
* Toggle an item in an array
|
|
2298
|
+
* Toggle an item in an array
|
|
2299
|
+
*
|
|
2300
|
+
* If the item exists, it will be removed; if it doesn't, it will be added
|
|
2301
|
+
*
|
|
1220
2302
|
* @param destination Array to toggle within
|
|
1221
2303
|
* @param toggled Toggled items
|
|
1222
2304
|
* @param key Key to find existing item
|
|
1223
2305
|
* @returns Original array
|
|
2306
|
+
*
|
|
2307
|
+
* @example
|
|
2308
|
+
* ```typescript
|
|
2309
|
+
* toggle(
|
|
2310
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
2311
|
+
* [{id: 2}, {id: 4}],
|
|
2312
|
+
* 'id',
|
|
2313
|
+
* ); // => [{id: 1}, {id: 3}, {id: 4}]
|
|
2314
|
+
* ```
|
|
1224
2315
|
*/
|
|
1225
2316
|
declare function toggle<Item extends PlainObject, ItemKey extends keyof Item>(destination: Item[], toggled: Item[], key: ItemKey): Item[];
|
|
1226
2317
|
/**
|
|
1227
|
-
* Toggle an item in an array
|
|
2318
|
+
* Toggle an item in an array
|
|
2319
|
+
*
|
|
2320
|
+
* If the item exists, it will be removed; if it doesn't, it will be added
|
|
2321
|
+
*
|
|
1228
2322
|
* @param destination Array to toggle within
|
|
1229
2323
|
* @param toggled Toggled items
|
|
1230
2324
|
* @returns Original array
|
|
2325
|
+
*
|
|
2326
|
+
* @example
|
|
2327
|
+
* ```typescript
|
|
2328
|
+
* toggle(
|
|
2329
|
+
* [1, 2, 3],
|
|
2330
|
+
* [2, 4],
|
|
2331
|
+
* ); // => [1, 3, 4]
|
|
2332
|
+
* ```
|
|
1231
2333
|
*/
|
|
1232
2334
|
declare function toggle<Item>(destination: Item[], toggled: Item[]): Item[];
|
|
1233
2335
|
//#endregion
|
|
1234
2336
|
//#region src/array/union.d.ts
|
|
1235
2337
|
/**
|
|
1236
2338
|
* Get the combined, unique values from two arrays
|
|
2339
|
+
*
|
|
1237
2340
|
* @param first First array
|
|
1238
2341
|
* @param second Second array
|
|
1239
2342
|
* @param callback Callback to get an item's value for comparison
|
|
1240
2343
|
* @returns Combined, unique values from both arrays
|
|
2344
|
+
*
|
|
2345
|
+
* @example
|
|
2346
|
+
* ```typescript
|
|
2347
|
+
* union(
|
|
2348
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
2349
|
+
* [{id: 2}, {id: 4}],
|
|
2350
|
+
* item => item.id,
|
|
2351
|
+
* ); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}]
|
|
2352
|
+
* ```
|
|
1241
2353
|
*/
|
|
1242
2354
|
declare function union<First, Second>(first: First[], second: Second[], callback: (item: First | Second) => unknown): (First | Second)[];
|
|
1243
2355
|
/**
|
|
1244
2356
|
* Get the combined, unique values from two arrays
|
|
2357
|
+
*
|
|
1245
2358
|
* @param first First array
|
|
1246
2359
|
* @param second Second array
|
|
1247
2360
|
* @param key Key to get an item's value for comparison
|
|
1248
2361
|
* @returns Combined, unique values from both arrays
|
|
2362
|
+
*
|
|
2363
|
+
* @example
|
|
2364
|
+
* ```typescript
|
|
2365
|
+
* union(
|
|
2366
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
2367
|
+
* [{id: 2}, {id: 4}],
|
|
2368
|
+
* 'id',
|
|
2369
|
+
* ); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}]
|
|
2370
|
+
* ```
|
|
1249
2371
|
*/
|
|
1250
2372
|
declare function union<First extends Record<string, unknown>, Second extends Record<string, unknown>, SharedKey extends keyof First & keyof Second>(first: First[], second: Second[], key: SharedKey): (First | Second)[];
|
|
1251
2373
|
/**
|
|
1252
2374
|
* Get the combined, unique values from two arrays
|
|
2375
|
+
*
|
|
1253
2376
|
* @param first First array
|
|
1254
2377
|
* @param second Second array
|
|
1255
2378
|
* @returns Combined, unique values from both arrays
|
|
2379
|
+
*
|
|
2380
|
+
* @example
|
|
2381
|
+
* ```typescript
|
|
2382
|
+
* union(
|
|
2383
|
+
* [1, 2, 3],
|
|
2384
|
+
* [2, 4],
|
|
2385
|
+
* ); // => [1, 2, 3, 4]
|
|
2386
|
+
* ```
|
|
1256
2387
|
*/
|
|
1257
2388
|
declare function union<First, Second>(first: First[], second: Second[]): (First | Second)[];
|
|
1258
2389
|
//#endregion
|
|
1259
2390
|
//#region src/array/unique.d.ts
|
|
1260
2391
|
/**
|
|
1261
2392
|
* Get an array of unique items
|
|
2393
|
+
*
|
|
1262
2394
|
* @param array Original array
|
|
1263
2395
|
* @param callback Callback to get an item's value
|
|
1264
2396
|
* @returns Array of unique items
|
|
2397
|
+
*
|
|
2398
|
+
* @example
|
|
2399
|
+
* ```typescript
|
|
2400
|
+
* unique(
|
|
2401
|
+
* [{id: 1}, {id: 2}, {id: 3}, {id: 2}],
|
|
2402
|
+
* item => item.id,
|
|
2403
|
+
* ); // => [{id: 1}, {id: 2}, {id: 3}]
|
|
2404
|
+
* ```
|
|
1265
2405
|
*/
|
|
1266
2406
|
declare function unique<Item>(array: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
|
|
1267
2407
|
/**
|
|
1268
2408
|
* Get an array of unique items
|
|
2409
|
+
*
|
|
1269
2410
|
* @param array Original array
|
|
1270
2411
|
* @param key Key to use for unique value
|
|
1271
2412
|
* @returns Array of unique items
|
|
2413
|
+
*
|
|
2414
|
+
* @example
|
|
2415
|
+
* ```typescript
|
|
2416
|
+
* unique(
|
|
2417
|
+
* [{id: 1}, {id: 2}, {id: 3}, {id: 2}],
|
|
2418
|
+
* 'id',
|
|
2419
|
+
* ); // => [{id: 1}, {id: 2}, {id: 3}]
|
|
2420
|
+
* ```
|
|
1272
2421
|
*/
|
|
1273
2422
|
declare function unique<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Item[];
|
|
1274
2423
|
/**
|
|
1275
2424
|
* Get an array of unique items
|
|
2425
|
+
*
|
|
1276
2426
|
* @param array Original array
|
|
1277
2427
|
* @returns Array of unique items
|
|
2428
|
+
*
|
|
2429
|
+
* @example
|
|
2430
|
+
* ```typescript
|
|
2431
|
+
* unique([1, 2, 3, 2]); // => [1, 2, 3]
|
|
2432
|
+
* ```
|
|
1278
2433
|
*/
|
|
1279
2434
|
declare function unique<Item>(array: Item[]): Item[];
|
|
1280
2435
|
//#endregion
|
|
1281
2436
|
//#region src/array/update.d.ts
|
|
1282
2437
|
/**
|
|
1283
|
-
* Update an item in an array
|
|
2438
|
+
* Update an item in an array
|
|
2439
|
+
*
|
|
2440
|
+
* If the item exists, it will be updated; if it doesn't, it will be added
|
|
2441
|
+
*
|
|
1284
2442
|
* @param destination Array to update within
|
|
1285
2443
|
* @param updated Updated items
|
|
1286
2444
|
* @param callback Callback to find existing item
|
|
1287
2445
|
* @returns Original array
|
|
2446
|
+
*
|
|
2447
|
+
* @example
|
|
2448
|
+
* ```typescript
|
|
2449
|
+
* update(
|
|
2450
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
2451
|
+
* [{id: 2, name: 'Updated'}, {id: 4, name: 'New'}],
|
|
2452
|
+
* item => item.id,
|
|
2453
|
+
* ); // => [{id: 1}, {id: 2, name: 'Updated'}, {id: 3}, {id: 4, name: 'New'}]
|
|
2454
|
+
* ```
|
|
1288
2455
|
*/
|
|
1289
2456
|
declare function update<Item>(destination: Item[], updated: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
|
|
1290
2457
|
/**
|
|
1291
|
-
* Update an item in an array
|
|
2458
|
+
* Update an item in an array
|
|
2459
|
+
*
|
|
2460
|
+
* If the item exists, it will be updated; if it doesn't, it will be added
|
|
2461
|
+
*
|
|
1292
2462
|
* @param destination Array to update within
|
|
1293
2463
|
* @param updated Updated items
|
|
1294
2464
|
* @param key Key to find existing item
|
|
1295
2465
|
* @returns Original array
|
|
2466
|
+
*
|
|
2467
|
+
* @example
|
|
2468
|
+
* ```typescript
|
|
2469
|
+
* update(
|
|
2470
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
2471
|
+
* [{id: 2, name: 'Updated'}, {id: 4, name: 'New'}],
|
|
2472
|
+
* 'id',
|
|
2473
|
+
* ); // => [{id: 1}, {id: 2, name: 'Updated'}, {id: 3}, {id: 4, name: 'New'}]
|
|
2474
|
+
* ```
|
|
1296
2475
|
*/
|
|
1297
2476
|
declare function update<Item extends PlainObject, ItemKey extends keyof Item>(destination: Item[], updated: Item[], key: ItemKey): Item[];
|
|
1298
2477
|
/**
|
|
1299
|
-
* Update an item in an array
|
|
2478
|
+
* Update an item in an array
|
|
2479
|
+
*
|
|
2480
|
+
* If the item exists, it will be updated; if it doesn't, it will be added
|
|
2481
|
+
*
|
|
1300
2482
|
* @param destination Array to update within
|
|
1301
2483
|
* @param updated Updated items
|
|
1302
2484
|
* @returns Original array
|
|
2485
|
+
*
|
|
2486
|
+
* @example
|
|
2487
|
+
* ```typescript
|
|
2488
|
+
* update(
|
|
2489
|
+
* [1, 2, 3],
|
|
2490
|
+
* [2, 4],
|
|
2491
|
+
* ); // => [1, 2, 3, 4]
|
|
2492
|
+
* ```
|
|
1303
2493
|
*/
|
|
1304
2494
|
declare function update<Item>(destination: Item[], updated: Item[]): Item[];
|
|
1305
2495
|
//#endregion
|
|
1306
2496
|
//#region src/array/last.d.ts
|
|
1307
2497
|
/**
|
|
1308
2498
|
* Get the last items matching the given value
|
|
2499
|
+
*
|
|
1309
2500
|
* @param array Array to search in
|
|
1310
2501
|
* @param callback Callback to get an item's value for matching
|
|
1311
2502
|
* @param value Value to match against
|
|
1312
2503
|
* @returns Last item that matches the value, or `undefined` if no match is found
|
|
2504
|
+
*
|
|
2505
|
+
* @example
|
|
2506
|
+
* ```typescript
|
|
2507
|
+
* last(
|
|
2508
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
2509
|
+
* item => item.value,
|
|
2510
|
+
* 10,
|
|
2511
|
+
* ); // => {id: 3, value: 10}
|
|
2512
|
+
* ```
|
|
1313
2513
|
*/
|
|
1314
2514
|
declare function last<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item | undefined;
|
|
1315
2515
|
/**
|
|
1316
2516
|
* Get the first item matching the given value by key
|
|
2517
|
+
*
|
|
1317
2518
|
* @param array Array to search in
|
|
1318
2519
|
* @param key Key to get an item's value for matching
|
|
1319
2520
|
* @param value Value to match against
|
|
1320
2521
|
* @returns Last item that matches the value, or `undefined` if no match is found
|
|
2522
|
+
*
|
|
2523
|
+
* @example
|
|
2524
|
+
* ```typescript
|
|
2525
|
+
* last(
|
|
2526
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
2527
|
+
* 'value',
|
|
2528
|
+
* 10,
|
|
2529
|
+
* ); // => {id: 3, value: 10}
|
|
2530
|
+
* ```
|
|
1321
2531
|
*/
|
|
1322
2532
|
declare function last<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
|
|
1323
2533
|
/**
|
|
1324
2534
|
* Get the last item matching the filter
|
|
2535
|
+
*
|
|
1325
2536
|
* @param array Array to search in
|
|
1326
2537
|
* @param filter Filter callback to match items
|
|
1327
2538
|
* @returns Last item that matches the filter, or `undefined` if no match is found
|
|
2539
|
+
*
|
|
2540
|
+
* @example
|
|
2541
|
+
* ```typescript
|
|
2542
|
+
* last(
|
|
2543
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
2544
|
+
* item => item.value === 10,
|
|
2545
|
+
* ); // => {id: 3, value: 10}
|
|
2546
|
+
* ```
|
|
1328
2547
|
*/
|
|
1329
2548
|
declare function last<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item | undefined;
|
|
1330
2549
|
/**
|
|
1331
2550
|
* Get the last item from an array
|
|
2551
|
+
*
|
|
1332
2552
|
* @param array Array to get from
|
|
1333
|
-
* @
|
|
2553
|
+
* @returns Last item from the array, or `undefined` if the array is empty
|
|
2554
|
+
*
|
|
2555
|
+
* @example
|
|
2556
|
+
* ```typescript
|
|
2557
|
+
* last([1, 2, 3]); // => 3
|
|
2558
|
+
* ```
|
|
1334
2559
|
*/
|
|
1335
2560
|
declare function last<Item>(array: Item[]): Item | undefined;
|
|
1336
2561
|
declare namespace last {
|
|
@@ -1341,41 +2566,79 @@ declare namespace last {
|
|
|
1341
2566
|
* Get the last item matching the given value
|
|
1342
2567
|
*
|
|
1343
2568
|
* Available as `lastOrDefault` and `last.default`
|
|
2569
|
+
*
|
|
1344
2570
|
* @param array Array to search in
|
|
1345
2571
|
* @param defaultValue Default value to return if no match is found
|
|
1346
2572
|
* @param callback Callback to get an item's value for matching
|
|
1347
2573
|
* @param value Value to match against
|
|
1348
2574
|
* @returns Last item that matches the value, or the default value if no match is found
|
|
2575
|
+
*
|
|
2576
|
+
* @example
|
|
2577
|
+
* ```typescript
|
|
2578
|
+
* lastOrDefault(
|
|
2579
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
2580
|
+
* {id: -1, value: 30},
|
|
2581
|
+
* item => item.value,
|
|
2582
|
+
* 30,
|
|
2583
|
+
* ); // => {id: -1, value: 30}
|
|
2584
|
+
* ```
|
|
1349
2585
|
*/
|
|
1350
2586
|
declare function lastOrDefault<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], defaultValue: Item, callback: Callback, value: ReturnType<Callback>): Item;
|
|
1351
2587
|
/**
|
|
1352
2588
|
* Get the last item matching the given value by key
|
|
1353
2589
|
*
|
|
1354
2590
|
* Available as `lastOrDefault` and `last.default`
|
|
2591
|
+
*
|
|
1355
2592
|
* @param array Array to search in
|
|
1356
2593
|
* @param defaultValue Default value to return if no match is found
|
|
1357
2594
|
* @param key Key to get an item's value for matching
|
|
1358
2595
|
* @param value Value to match against
|
|
1359
2596
|
* @returns Last item that matches the value, or the default value if no match is found
|
|
2597
|
+
*
|
|
2598
|
+
* @example
|
|
2599
|
+
* ```typescript
|
|
2600
|
+
* lastOrDefault(
|
|
2601
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
2602
|
+
* {id: -1, value: 30},
|
|
2603
|
+
* 'value',
|
|
2604
|
+
* 30,
|
|
2605
|
+
* ); // => {id: -1, value: 30}
|
|
2606
|
+
* ```
|
|
1360
2607
|
*/
|
|
1361
2608
|
declare function lastOrDefault<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], defaultValue: Item, key: ItemKey, value: Item[ItemKey]): Item;
|
|
1362
2609
|
/**
|
|
1363
2610
|
* Get the last item matching the filter
|
|
1364
2611
|
*
|
|
1365
2612
|
* Available as `lastOrDefault` and `last.default`
|
|
2613
|
+
*
|
|
1366
2614
|
* @param array Array to search in
|
|
1367
2615
|
* @param defaultValue Default value to return if no match is found
|
|
1368
2616
|
* @param filter Filter callback to match items
|
|
1369
2617
|
* @returns Last item that matches the filter, or the default value if no match is found
|
|
2618
|
+
*
|
|
2619
|
+
* @example
|
|
2620
|
+
* ```typescript
|
|
2621
|
+
* lastOrDefault(
|
|
2622
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
2623
|
+
* {id: -1, value: 30},
|
|
2624
|
+
* item => item.value === 30,
|
|
2625
|
+
* ); // => {id: -1, value: 30}
|
|
2626
|
+
* ```
|
|
1370
2627
|
*/
|
|
1371
2628
|
declare function lastOrDefault<Item>(array: Item[], defaultValue: Item, filter: (item: Item, index: number, array: Item[]) => boolean): Item;
|
|
1372
2629
|
/**
|
|
1373
2630
|
* Get the last item from an array
|
|
1374
2631
|
*
|
|
1375
2632
|
* Available as `lastOrDefault` and `last.default`
|
|
2633
|
+
*
|
|
1376
2634
|
* @param array Array to get from
|
|
1377
2635
|
* @param defaultValue Default value to return if the array is empty
|
|
1378
|
-
* @
|
|
2636
|
+
* @returns Last item from the array, or the default value if the array is empty
|
|
2637
|
+
*
|
|
2638
|
+
* @example
|
|
2639
|
+
* ```typescript
|
|
2640
|
+
* lastOrDefault([], {id: -1, value: 30}); // => {id: -1, value: 30}
|
|
2641
|
+
* ```
|
|
1379
2642
|
*/
|
|
1380
2643
|
declare function lastOrDefault<Item>(array: Item[], defaultValue: Item): Item;
|
|
1381
2644
|
//#endregion
|
|
@@ -1386,36 +2649,66 @@ declare function lastOrDefault<Item>(array: Item[], defaultValue: Item): Item;
|
|
|
1386
2649
|
* When moving to the front of the array, the moved items will be placed __before__ the target item. When moving to the back of the array, the moved items will be placed __after__ the target item.
|
|
1387
2650
|
*
|
|
1388
2651
|
* If either of values are not present in the array, or if they overlap, the array will be returned unchanged
|
|
2652
|
+
*
|
|
1389
2653
|
* @param array Array to move within
|
|
1390
2654
|
* @param from Item or items to move
|
|
1391
2655
|
* @param to Item or items to move to
|
|
1392
|
-
* @param
|
|
2656
|
+
* @param callback Callback to get an item's value for matching
|
|
1393
2657
|
* @returns Original array with items moved _(or unchanged if unable to move)_
|
|
2658
|
+
*
|
|
2659
|
+
* @example
|
|
2660
|
+
* ```typescript
|
|
2661
|
+
* const array = [{id: 1}, {id: 2}, {id: 3}, {id: 4}];
|
|
2662
|
+
*
|
|
2663
|
+
* move(array, {id: 1}, {id: 3}, item => item.id); // => [{id: 2}, {id: 3}, {id: 1}, {id: 4}]
|
|
2664
|
+
* move(array, [{id: 2}, {id: 3}], {id: 4}, item => item.id); // => [{id: 1}, {id: 4}, {id: 2}, {id: 3}]
|
|
2665
|
+
* move(array, {id: 5}, {id: 1}, item => item.id); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}] (unchanged)
|
|
2666
|
+
* ```
|
|
1394
2667
|
*/
|
|
1395
|
-
declare function move<Item
|
|
2668
|
+
declare function move<Item>(array: Item[], from: Item | Item[], to: Item | Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
|
|
1396
2669
|
/**
|
|
1397
2670
|
* Move an item _(or array of items)_ to the position of another item _(or array of items)_ within an array
|
|
1398
2671
|
*
|
|
1399
2672
|
* When moving to the front of the array, the moved items will be placed __before__ the target item. When moving to the back of the array, the moved items will be placed __after__ the target item.
|
|
1400
2673
|
*
|
|
1401
2674
|
* If either of values are not present in the array, or if they overlap, the array will be returned unchanged
|
|
2675
|
+
*
|
|
1402
2676
|
* @param array Array to move within
|
|
1403
2677
|
* @param from Item or items to move
|
|
1404
2678
|
* @param to Item or items to move to
|
|
1405
|
-
* @param
|
|
2679
|
+
* @param key Key to get an item's value for matching
|
|
1406
2680
|
* @returns Original array with items moved _(or unchanged if unable to move)_
|
|
2681
|
+
*
|
|
2682
|
+
* @example
|
|
2683
|
+
* ```typescript
|
|
2684
|
+
* const array = [{id: 1}, {id: 2}, {id: 3}, {id: 4}];
|
|
2685
|
+
*
|
|
2686
|
+
* move(array, {id: 1}, {id: 3}, 'id'); // => [{id: 2}, {id: 3}, {id: 1}, {id: 4}]
|
|
2687
|
+
* move(array, [{id: 2}, {id: 3}], {id: 4}, 'id'); // => [{id: 1}, {id: 4}, {id: 2}, {id: 3}]
|
|
2688
|
+
* move(array, {id: 5}, {id: 1}, 'id'); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}] (unchanged)
|
|
2689
|
+
* ```
|
|
1407
2690
|
*/
|
|
1408
|
-
declare function move<Item>(array: Item[], from: Item | Item[], to: Item | Item[],
|
|
2691
|
+
declare function move<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], from: Item | Item[], to: Item | Item[], key: ItemKey): Item[];
|
|
1409
2692
|
/**
|
|
1410
2693
|
* Move an item _(or array of items)_ to the position of another item _(or array of items)_ within an array
|
|
1411
2694
|
*
|
|
1412
2695
|
* When moving to the front of the array, the moved items will be placed __before__ the target item. When moving to the back of the array, the moved items will be placed __after__ the target item.
|
|
1413
2696
|
*
|
|
1414
2697
|
* If either of values are not present in the array, or if they overlap, the array will be returned unchanged
|
|
2698
|
+
*
|
|
1415
2699
|
* @param array Array to move within
|
|
1416
2700
|
* @param from Item or items to move
|
|
1417
2701
|
* @param to Item or items to move to
|
|
1418
2702
|
* @returns Original array with items moved _(or unchanged if unable to move)_
|
|
2703
|
+
*
|
|
2704
|
+
* @example
|
|
2705
|
+
* ```typescript
|
|
2706
|
+
* const array = [1, 2, 3, 4];
|
|
2707
|
+
*
|
|
2708
|
+
* move(array, 1, 3); // => [2, 3, 1, 4]
|
|
2709
|
+
* move(array, [2, 3], 4); // => [1, 4, 2, 3]
|
|
2710
|
+
* move(array, 5, 1); // => [1, 2, 3, 4] (unchanged)
|
|
2711
|
+
* ```
|
|
1419
2712
|
*/
|
|
1420
2713
|
declare function move<Item>(array: Item[], from: Item | Item[], to: Item | Item[]): Item[];
|
|
1421
2714
|
declare namespace move {
|
|
@@ -1428,10 +2721,20 @@ declare namespace move {
|
|
|
1428
2721
|
* If the from index is out of bounds, the array will be returned unchanged
|
|
1429
2722
|
*
|
|
1430
2723
|
* Available as `moveIndices` and `move.indices`
|
|
2724
|
+
*
|
|
1431
2725
|
* @param array Array to move within
|
|
1432
2726
|
* @param from Index to move from
|
|
1433
2727
|
* @param to Index to move to
|
|
1434
2728
|
* @returns Original array with item moved _(or unchanged if unable to move)_
|
|
2729
|
+
*
|
|
2730
|
+
* @example
|
|
2731
|
+
* ```typescript
|
|
2732
|
+
* const array = [1, 2, 3, 4];
|
|
2733
|
+
*
|
|
2734
|
+
* moveIndices(array, 0, 2); // => [2, 3, 1, 4]
|
|
2735
|
+
* moveIndices(array, -1, 0); // => [4, 2, 3, 1]
|
|
2736
|
+
* moveIndices(array, 5, 1); // => [4, 2, 3, 1] (unchanged)
|
|
2737
|
+
* ```
|
|
1435
2738
|
*/
|
|
1436
2739
|
declare function moveIndices<Item>(array: Item[], from: number, to: number): Item[];
|
|
1437
2740
|
/**
|
|
@@ -1440,36 +2743,66 @@ declare function moveIndices<Item>(array: Item[], from: number, to: number): Ite
|
|
|
1440
2743
|
* If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged
|
|
1441
2744
|
*
|
|
1442
2745
|
* Available as `moveToIndex` and `move.toIndex`
|
|
2746
|
+
*
|
|
2747
|
+
* @example
|
|
2748
|
+
* ```typescript
|
|
2749
|
+
* const array = [{id: 1}, {id: 2}, {id: 3}, {id: 4}];
|
|
2750
|
+
*
|
|
2751
|
+
* moveToIndex(array, {id: 1}, 2, item => item.id); // => [{id: 2}, {id: 3}, {id: 1}, {id: 4}]
|
|
2752
|
+
* moveToIndex(array, [{id: 2}, {id: 3}], 3, item => item.id); // => [{id: 1}, {id: 4}, {id: 2}, {id: 3}]
|
|
2753
|
+
* moveToIndex(array, {id: 5}, 1, item => item.id); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}] (unchanged)
|
|
2754
|
+
* ```
|
|
2755
|
+
*
|
|
1443
2756
|
* @param array Array to move within
|
|
1444
2757
|
* @param value Item or items to move
|
|
1445
2758
|
* @param index Index to move to
|
|
1446
|
-
* @param
|
|
2759
|
+
* @param callback Callback to get an item's value for matching
|
|
1447
2760
|
* @returns Original array with items moved _(or unchanged if unable to move)_
|
|
1448
2761
|
*/
|
|
1449
|
-
declare function moveToIndex<Item
|
|
2762
|
+
declare function moveToIndex<Item>(array: Item[], value: Item | Item[], index: number, callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
|
|
1450
2763
|
/**
|
|
1451
2764
|
* Move an item _(or array of items)_ to an index within an array
|
|
1452
2765
|
*
|
|
1453
2766
|
* If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged
|
|
1454
2767
|
*
|
|
1455
2768
|
* Available as `moveToIndex` and `move.toIndex`
|
|
2769
|
+
*
|
|
1456
2770
|
* @param array Array to move within
|
|
1457
2771
|
* @param value Item or items to move
|
|
1458
2772
|
* @param index Index to move to
|
|
1459
|
-
* @param
|
|
2773
|
+
* @param key Key to get an item's value for matching
|
|
1460
2774
|
* @returns Original array with items moved _(or unchanged if unable to move)_
|
|
2775
|
+
*
|
|
2776
|
+
* @example
|
|
2777
|
+
* ```typescript
|
|
2778
|
+
* const array = [{id: 1}, {id: 2}, {id: 3}, {id: 4}];
|
|
2779
|
+
*
|
|
2780
|
+
* moveToIndex(array, {id: 1}, 2, 'id'); // => [{id: 2}, {id: 3}, {id: 1}, {id: 4}]
|
|
2781
|
+
* moveToIndex(array, [{id: 2}, {id: 3}], 3, 'id'); // => [{id: 1}, {id: 4}, {id: 2}, {id: 3}]
|
|
2782
|
+
* moveToIndex(array, {id: 5}, 1, 'id'); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}] (unchanged)
|
|
2783
|
+
* ```
|
|
1461
2784
|
*/
|
|
1462
|
-
declare function moveToIndex<Item>(array: Item[], value: Item | Item[], index: number,
|
|
2785
|
+
declare function moveToIndex<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], value: Item | Item[], index: number, key: ItemKey): Item[];
|
|
1463
2786
|
/**
|
|
1464
2787
|
* Move an item _(or array of items)_ to an index within an array
|
|
1465
2788
|
*
|
|
1466
2789
|
* If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged
|
|
1467
2790
|
*
|
|
1468
2791
|
* Available as `moveToIndex` and `move.toIndex`
|
|
2792
|
+
*
|
|
1469
2793
|
* @param array Array to move within
|
|
1470
2794
|
* @param value Item or items to move
|
|
1471
2795
|
* @param index Index to move to
|
|
1472
2796
|
* @returns Original array with items moved _(or unchanged if unable to move)_
|
|
2797
|
+
*
|
|
2798
|
+
* @example
|
|
2799
|
+
* ```typescript
|
|
2800
|
+
* const array = [1, 2, 3, 4];
|
|
2801
|
+
*
|
|
2802
|
+
* moveToIndex(array, 1, 2); // => [2, 3, 1, 4]
|
|
2803
|
+
* moveToIndex(array, [2, 3], 3); // => [1, 4, 2, 3]
|
|
2804
|
+
* moveToIndex(array, 5, 1); // => [1, 2, 3, 4] (unchanged)
|
|
2805
|
+
* ```
|
|
1473
2806
|
*/
|
|
1474
2807
|
declare function moveToIndex<Item>(array: Item[], value: Item | Item[], index: number): Item[];
|
|
1475
2808
|
//#endregion
|
|
@@ -1546,6 +2879,7 @@ type SortDirection = 'ascending' | 'descending';
|
|
|
1546
2879
|
type Sorter<Item> = {
|
|
1547
2880
|
/**
|
|
1548
2881
|
* Sort an array of items
|
|
2882
|
+
*
|
|
1549
2883
|
* @param array Array to sort
|
|
1550
2884
|
* @returns Sorted array
|
|
1551
2885
|
*/
|
|
@@ -1554,6 +2888,7 @@ type Sorter<Item> = {
|
|
|
1554
2888
|
* Get the index for an item _(to be inserted into an array of items)_
|
|
1555
2889
|
*
|
|
1556
2890
|
* _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
|
|
2891
|
+
*
|
|
1557
2892
|
* @param array Array to get the index from
|
|
1558
2893
|
* @param item Item to get the index for
|
|
1559
2894
|
* @returns Index for item
|
|
@@ -1561,6 +2896,7 @@ type Sorter<Item> = {
|
|
|
1561
2896
|
index(array: Item[], item: Item): number;
|
|
1562
2897
|
/**
|
|
1563
2898
|
* Is the array sorted?
|
|
2899
|
+
*
|
|
1564
2900
|
* @param array Array to check
|
|
1565
2901
|
* @returns `true` if sorted, otherwise `false`
|
|
1566
2902
|
*/
|
|
@@ -1572,6 +2908,7 @@ type Sorter<Item> = {
|
|
|
1572
2908
|
* _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
|
|
1573
2909
|
*
|
|
1574
2910
|
* Available as `getSortedIndex` and `sort.getIndex`
|
|
2911
|
+
*
|
|
1575
2912
|
* @param array Array to get the index from
|
|
1576
2913
|
* @param item Item to get the index for
|
|
1577
2914
|
* @param sorters Sorters to use to determine sorting
|
|
@@ -1585,6 +2922,7 @@ declare function getSortedIndex<Item>(array: Item[], item: Item, sorters: Array<
|
|
|
1585
2922
|
* _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
|
|
1586
2923
|
*
|
|
1587
2924
|
* Available as `getSortedIndex` and `sort.getIndex`
|
|
2925
|
+
*
|
|
1588
2926
|
* @param array Array to get the index from
|
|
1589
2927
|
* @param item Item to get the index for
|
|
1590
2928
|
* @param sorter Sorter to use to determine sorting
|
|
@@ -1598,6 +2936,7 @@ declare function getSortedIndex<Item>(array: Item[], item: Item, sorter: ArraySo
|
|
|
1598
2936
|
* _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
|
|
1599
2937
|
*
|
|
1600
2938
|
* Available as `getSortedIndex` and `sort.getIndex`
|
|
2939
|
+
*
|
|
1601
2940
|
* @param array Array to get the index from
|
|
1602
2941
|
* @param item Item to get the index for
|
|
1603
2942
|
* @param descending Sorted in descending order? _(defaults to `false`)_
|
|
@@ -1608,6 +2947,7 @@ declare function getSortedIndex<Item>(array: Item[], item: Item, descending?: bo
|
|
|
1608
2947
|
* Initialize a sort handler with sorters _(and an optional default direction)_
|
|
1609
2948
|
*
|
|
1610
2949
|
* Available as `initializeSorter` and `sort.initialize`
|
|
2950
|
+
*
|
|
1611
2951
|
* @param sorters Sorters to use for sorting
|
|
1612
2952
|
* @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
1613
2953
|
* @returns Sort handler
|
|
@@ -1617,6 +2957,7 @@ declare function initializeSorter<Item>(sorters: Array<ArraySorter<Item>>, desce
|
|
|
1617
2957
|
* Initialize a sort handler with a sorter _(and an optional default direction)_
|
|
1618
2958
|
*
|
|
1619
2959
|
* Available as `initializeSorter` and `sort.initialize`
|
|
2960
|
+
*
|
|
1620
2961
|
* @param sorter Sorter to use for sorting
|
|
1621
2962
|
* @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
1622
2963
|
* @returns Sort handler
|
|
@@ -1626,12 +2967,14 @@ declare function initializeSorter<Item>(sorter: ArraySorter<Item>, descending?:
|
|
|
1626
2967
|
* Initialize a sort handler _(with an optional default direction)_
|
|
1627
2968
|
*
|
|
1628
2969
|
* Available as `initializeSorter` and `sort.initialize`
|
|
2970
|
+
*
|
|
1629
2971
|
* @param descending Sort in descending order? _(defaults to `false`)_
|
|
1630
2972
|
* @returns Sort handler
|
|
1631
2973
|
*/
|
|
1632
2974
|
declare function initializeSorter<Item>(descending?: boolean): Sorter<Item>;
|
|
1633
2975
|
/**
|
|
1634
2976
|
* Is the array sorted according to the sorters _(and the optional default direction)_?
|
|
2977
|
+
*
|
|
1635
2978
|
* @param array Array to check
|
|
1636
2979
|
* @param sorters Sorters to determine sorting
|
|
1637
2980
|
* @param descending Sorted in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
@@ -1640,6 +2983,7 @@ declare function initializeSorter<Item>(descending?: boolean): Sorter<Item>;
|
|
|
1640
2983
|
declare function isSorted<Item>(array: Item[], sorters: Array<ArraySorter<Item>>, descending?: boolean): boolean;
|
|
1641
2984
|
/**
|
|
1642
2985
|
* Is the array sorted according to the sorter _(and the optional default direction)_?
|
|
2986
|
+
*
|
|
1643
2987
|
* @param array Array to check
|
|
1644
2988
|
* @param sorter Sorter to determine sorting
|
|
1645
2989
|
* @param descending Sorted in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
@@ -1650,6 +2994,7 @@ declare function isSorted<Item>(array: Item[], sorter: ArraySorter<Item>, descen
|
|
|
1650
2994
|
* Is the array sorted?
|
|
1651
2995
|
*
|
|
1652
2996
|
* Available as `isSorted` and `sort.is`
|
|
2997
|
+
*
|
|
1653
2998
|
* @param array Array to check
|
|
1654
2999
|
* @param descending Sorted in descending order? _(defaults to `false`)_
|
|
1655
3000
|
* @returns `true` if sorted, otherwise `false`
|
|
@@ -1657,10 +3002,19 @@ declare function isSorted<Item>(array: Item[], sorter: ArraySorter<Item>, descen
|
|
|
1657
3002
|
declare function isSorted<Item>(array: Item[], descending?: boolean): boolean;
|
|
1658
3003
|
/**
|
|
1659
3004
|
* Sort an array of items using a comparison callback
|
|
3005
|
+
*
|
|
1660
3006
|
* @param array Array to sort
|
|
1661
3007
|
* @param comparator Comparator to use for sorting
|
|
1662
3008
|
* @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
1663
3009
|
* @returns Sorted array
|
|
3010
|
+
*
|
|
3011
|
+
* @example
|
|
3012
|
+
* ```typescript
|
|
3013
|
+
* sort(
|
|
3014
|
+
* [{id: 3}, {id: 1}, {id: 2}],
|
|
3015
|
+
* (first, second) => first.id - second.id,
|
|
3016
|
+
* ); // => [{id: 1}, {id: 2}, {id: 3}]
|
|
3017
|
+
* ```
|
|
1664
3018
|
*/
|
|
1665
3019
|
declare function sort<Item>(array: Item[], comparator: (first: Item, second: Item) => number, descending?: boolean): Item[];
|
|
1666
3020
|
/**
|
|
@@ -1699,62 +3053,166 @@ declare const SORT_DIRECTION_DESCENDING: SortDirection;
|
|
|
1699
3053
|
* Swap two smaller arrays within a larger array
|
|
1700
3054
|
*
|
|
1701
3055
|
* If either of the smaller arrays are not present in the larger array, or if they overlap, the larger array will be returned unchanged
|
|
3056
|
+
*
|
|
1702
3057
|
* @param array Array of items to swap
|
|
1703
3058
|
* @param first First array
|
|
1704
3059
|
* @param second Second array
|
|
1705
|
-
* @param
|
|
3060
|
+
* @param callback Callback to get an item's value for matching
|
|
1706
3061
|
* @returns Original array with items swapped _(or unchanged if unable to swap)_
|
|
3062
|
+
*
|
|
3063
|
+
* @example
|
|
3064
|
+
* ```typescript
|
|
3065
|
+
* swap(
|
|
3066
|
+
* [
|
|
3067
|
+
* {id: 1, name: 'Alice'},
|
|
3068
|
+
* {id: 2, name: 'Bob'},
|
|
3069
|
+
* {id: 3, name: 'Charlie'},
|
|
3070
|
+
* ],
|
|
3071
|
+
* [
|
|
3072
|
+
* {id: 2, name: 'Bob'},
|
|
3073
|
+
* ],
|
|
3074
|
+
* [
|
|
3075
|
+
* {id: 3, name: 'Charlie'},
|
|
3076
|
+
* ],
|
|
3077
|
+
* item => item.id,
|
|
3078
|
+
* ); // => [
|
|
3079
|
+
* // {id: 1, name: 'Alice'},
|
|
3080
|
+
* // {id: 3, name: 'Charlie'},
|
|
3081
|
+
* // {id: 2, name: 'Bob'},
|
|
3082
|
+
* // ]
|
|
3083
|
+
* ```
|
|
1707
3084
|
*/
|
|
1708
|
-
declare function swap<Item
|
|
3085
|
+
declare function swap<Item>(array: Item[], first: Item[], second: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
|
|
1709
3086
|
/**
|
|
1710
3087
|
* Swap two smaller arrays within a larger array
|
|
1711
3088
|
*
|
|
1712
3089
|
* If either of the smaller arrays are not present in the larger array, or if they overlap, the larger array will be returned unchanged
|
|
3090
|
+
*
|
|
1713
3091
|
* @param array Array of items to swap
|
|
1714
3092
|
* @param first First array
|
|
1715
3093
|
* @param second Second array
|
|
1716
|
-
* @param
|
|
3094
|
+
* @param key Key to get an item's value for matching
|
|
1717
3095
|
* @returns Original array with items swapped _(or unchanged if unable to swap)_
|
|
3096
|
+
*
|
|
3097
|
+
* @example
|
|
3098
|
+
* ```typescript
|
|
3099
|
+
* swap(
|
|
3100
|
+
* [
|
|
3101
|
+
* {id: 1, name: 'Alice'},
|
|
3102
|
+
* {id: 2, name: 'Bob'},
|
|
3103
|
+
* {id: 3, name: 'Charlie'},
|
|
3104
|
+
* ],
|
|
3105
|
+
* [
|
|
3106
|
+
* {id: 2, name: 'Bob'},
|
|
3107
|
+
* ],
|
|
3108
|
+
* [
|
|
3109
|
+
* {id: 3, name: 'Charlie'},
|
|
3110
|
+
* ],
|
|
3111
|
+
* 'id',
|
|
3112
|
+
* ); // => [
|
|
3113
|
+
* // {id: 1, name: 'Alice'},
|
|
3114
|
+
* // {id: 3, name: 'Charlie'},
|
|
3115
|
+
* // {id: 2, name: 'Bob'},
|
|
3116
|
+
* // ]
|
|
3117
|
+
* ```
|
|
1718
3118
|
*/
|
|
1719
|
-
declare function swap<Item>(array: Item[], first: Item[], second: Item[],
|
|
3119
|
+
declare function swap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], first: Item[], second: Item[], key: ItemKey): Item[];
|
|
1720
3120
|
/**
|
|
1721
3121
|
* Swap two smaller arrays within a larger array
|
|
1722
3122
|
*
|
|
1723
3123
|
* If either of the smaller arrays are not present in the larger array, or if they overlap, the larger array will be returned unchanged
|
|
3124
|
+
*
|
|
1724
3125
|
* @param array Array of items to swap
|
|
1725
3126
|
* @param first First array
|
|
1726
3127
|
* @param second Second array
|
|
1727
3128
|
* @returns Original array with items swapped _(or unchanged if unable to swap)_
|
|
3129
|
+
*
|
|
3130
|
+
* @example
|
|
3131
|
+
* ```typescript
|
|
3132
|
+
* swap(
|
|
3133
|
+
* [1, 2, 3, 4, 5, 6],
|
|
3134
|
+
* [1, 2],
|
|
3135
|
+
* [5, 6],
|
|
3136
|
+
* ); // => [5, 6, 3, 4, 1, 2]
|
|
3137
|
+
* ```
|
|
1728
3138
|
*/
|
|
1729
3139
|
declare function swap<Item>(array: Item[], first: Item[], second: Item[]): Item[];
|
|
1730
3140
|
/**
|
|
1731
3141
|
* Swap two indiced items in an array
|
|
1732
3142
|
*
|
|
1733
3143
|
* If either of the items are not present in the array, the array will be returned unchanged
|
|
3144
|
+
*
|
|
1734
3145
|
* @param array Array of items to swap
|
|
1735
3146
|
* @param first First item
|
|
1736
3147
|
* @param second Second item
|
|
1737
|
-
* @param
|
|
3148
|
+
* @param callback Callback to get an item's value for matching
|
|
1738
3149
|
* @returns Original array with items swapped _(or unchanged if unable to swap)_
|
|
3150
|
+
*
|
|
3151
|
+
* @example
|
|
3152
|
+
* ```typescript
|
|
3153
|
+
* swap(
|
|
3154
|
+
* [
|
|
3155
|
+
* {id: 1, name: 'Alice'},
|
|
3156
|
+
* {id: 2, name: 'Bob'},
|
|
3157
|
+
* {id: 3, name: 'Charlie'},
|
|
3158
|
+
* ],
|
|
3159
|
+
* {id: 2, name: 'Bob'},
|
|
3160
|
+
* {id: 3, name: 'Charlie'},
|
|
3161
|
+
* item => item.id,
|
|
3162
|
+
* ); // => [
|
|
3163
|
+
* // {id: 1, name: 'Alice'},
|
|
3164
|
+
* // {id: 3, name: 'Charlie'},
|
|
3165
|
+
* // {id: 2, name: 'Bob'},
|
|
3166
|
+
* // ]
|
|
3167
|
+
* ```
|
|
1739
3168
|
*/
|
|
1740
|
-
declare function swap<Item
|
|
3169
|
+
declare function swap<Item>(array: Item[], first: Item, second: Item, callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
|
|
1741
3170
|
/**
|
|
1742
3171
|
* Swap two indiced items in an array
|
|
1743
3172
|
*
|
|
1744
3173
|
* If either of the items are not present in the array, the array will be returned unchanged
|
|
3174
|
+
*
|
|
1745
3175
|
* @param array Array of items to swap
|
|
1746
3176
|
* @param first First item
|
|
1747
3177
|
* @param second Second item
|
|
1748
|
-
* @param
|
|
3178
|
+
* @param key Key to get an item's value for matching
|
|
1749
3179
|
* @returns Original array with items swapped _(or unchanged if unable to swap)_
|
|
3180
|
+
*
|
|
3181
|
+
* @example
|
|
3182
|
+
* ```typescript
|
|
3183
|
+
* swap(
|
|
3184
|
+
* [
|
|
3185
|
+
* {id: 1, name: 'Alice'},
|
|
3186
|
+
* {id: 2, name: 'Bob'},
|
|
3187
|
+
* {id: 3, name: 'Charlie'},
|
|
3188
|
+
* ],
|
|
3189
|
+
* {id: 2, name: 'Bob'},
|
|
3190
|
+
* {id: 3, name: 'Charlie'},
|
|
3191
|
+
* 'id',
|
|
3192
|
+
* ); // => [
|
|
3193
|
+
* // {id: 1, name: 'Alice'},
|
|
3194
|
+
* // {id: 3, name: 'Charlie'},
|
|
3195
|
+
* // {id: 2, name: 'Bob'},
|
|
3196
|
+
* // ]
|
|
3197
|
+
* ```
|
|
1750
3198
|
*/
|
|
1751
|
-
declare function swap<Item>(array: Item[], first: Item, second: Item,
|
|
3199
|
+
declare function swap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], first: Item, second: Item, key: ItemKey): Item[];
|
|
1752
3200
|
/**
|
|
1753
3201
|
* Swap two indiced items in an array
|
|
3202
|
+
*
|
|
1754
3203
|
* @param array Array of items to swap
|
|
1755
3204
|
* @param first First item
|
|
1756
3205
|
* @param second Second item
|
|
1757
3206
|
* @returns Original array with items swapped _(or unchanged if unable to swap)_
|
|
3207
|
+
*
|
|
3208
|
+
* @example
|
|
3209
|
+
* ```typescript
|
|
3210
|
+
* swap(
|
|
3211
|
+
* [1, 2, 3, 4, 5, 6],
|
|
3212
|
+
* 2,
|
|
3213
|
+
* 5,
|
|
3214
|
+
* ); // => [1, 5, 3, 4, 2, 6]
|
|
3215
|
+
* ```
|
|
1758
3216
|
*/
|
|
1759
3217
|
declare function swap<Item>(array: Item[], first: Item, second: Item): Item[];
|
|
1760
3218
|
declare namespace swap {
|
|
@@ -1766,6 +3224,7 @@ declare namespace swap {
|
|
|
1766
3224
|
* If either index is out of bounds, the array will be returned unchanged
|
|
1767
3225
|
*
|
|
1768
3226
|
* Available as `swapIndices` and `swap.indices`
|
|
3227
|
+
*
|
|
1769
3228
|
* @param array Array of items to swap
|
|
1770
3229
|
* @param first First index _(can be negative to count from the end)_
|
|
1771
3230
|
* @param second Second index _(can be negative to count from the end)_
|
|
@@ -1778,64 +3237,130 @@ declare function swapIndices<Item>(array: Item[], first: number, second: number)
|
|
|
1778
3237
|
* Create a Map from an array of items using callbacks
|
|
1779
3238
|
*
|
|
1780
3239
|
* If multiple items have the same key, the latest item's value will be used
|
|
3240
|
+
*
|
|
1781
3241
|
* @param array Array to convert
|
|
1782
3242
|
* @param key Callback to get an item's grouping key
|
|
1783
3243
|
* @param value Callback to get an item's value
|
|
1784
3244
|
* @returns Map of keyed values
|
|
3245
|
+
*
|
|
3246
|
+
* @example
|
|
3247
|
+
* ```typescript
|
|
3248
|
+
* toMap(
|
|
3249
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3250
|
+
* item => item.value,
|
|
3251
|
+
* item => item.id,
|
|
3252
|
+
* ); // => Map { 10 => 3, 20 => 2 }
|
|
3253
|
+
* ```
|
|
1785
3254
|
*/
|
|
1786
3255
|
declare function toMap<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key$1, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Map<ReturnType<KeyCallback>, ReturnType<ValueCallback>>;
|
|
1787
3256
|
/**
|
|
1788
3257
|
* Create a Map from an array of items using a callback and value
|
|
1789
3258
|
*
|
|
1790
3259
|
* If multiple items have the same key, the latest item's value will be used
|
|
3260
|
+
*
|
|
1791
3261
|
* @param array Array to convert
|
|
1792
3262
|
* @param key Callback to get an item's grouping key
|
|
1793
3263
|
* @param value Key to use for value
|
|
1794
3264
|
* @returns Map of keyed values
|
|
3265
|
+
*
|
|
3266
|
+
* @example
|
|
3267
|
+
* ```typescript
|
|
3268
|
+
* toMap(
|
|
3269
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3270
|
+
* item => item.value,
|
|
3271
|
+
* 'id',
|
|
3272
|
+
* ); // => Map { 10 => 3, 20 => 2 }
|
|
3273
|
+
* ```
|
|
1795
3274
|
*/
|
|
1796
3275
|
declare function toMap<Item extends PlainObject, KeyCallback extends (item: Item, index: number, array: Item[]) => Key$1, ItemValue extends keyof Item>(array: Item[], key: KeyCallback, value: ItemValue): Map<ReturnType<KeyCallback>, Item[ItemValue]>;
|
|
1797
3276
|
/**
|
|
1798
3277
|
* Create a Map from an array of items using a key and callback
|
|
1799
3278
|
*
|
|
1800
3279
|
* If multiple items have the same key, the latest item's value will be used
|
|
3280
|
+
*
|
|
1801
3281
|
* @param array Array to convert
|
|
1802
3282
|
* @param key Key to use for grouping
|
|
1803
3283
|
* @param value Callback to get an item's value
|
|
1804
3284
|
* @returns Map of keyed values
|
|
3285
|
+
*
|
|
3286
|
+
* @example
|
|
3287
|
+
* ```typescript
|
|
3288
|
+
* toMap(
|
|
3289
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3290
|
+
* 'value',
|
|
3291
|
+
* item => item.id,
|
|
3292
|
+
* ); // => Map { 10 => 3, 20 => 2 }
|
|
3293
|
+
* ```
|
|
1805
3294
|
*/
|
|
1806
3295
|
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>>;
|
|
1807
3296
|
/**
|
|
1808
3297
|
* Create a Map from an array of items using a key and value
|
|
1809
3298
|
*
|
|
1810
3299
|
* If multiple items have the same key, the latest item's value will be used
|
|
3300
|
+
*
|
|
1811
3301
|
* @param array Array to convert
|
|
1812
3302
|
* @param key Key to use for grouping
|
|
1813
3303
|
* @param value Key to use for value
|
|
1814
3304
|
* @returns Map of keyed values
|
|
3305
|
+
*
|
|
3306
|
+
* @example
|
|
3307
|
+
* ```typescript
|
|
3308
|
+
* toMap(
|
|
3309
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3310
|
+
* 'value',
|
|
3311
|
+
* 'id',
|
|
3312
|
+
* ); // => Map { 10 => 3, 20 => 2 }
|
|
3313
|
+
* ```
|
|
1815
3314
|
*/
|
|
1816
3315
|
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]>;
|
|
1817
3316
|
/**
|
|
1818
3317
|
* Create a Map from an array of items using a callback
|
|
1819
3318
|
*
|
|
1820
3319
|
* If multiple items have the same key, the latest item will be used
|
|
3320
|
+
*
|
|
1821
3321
|
* @param array Array to convert
|
|
1822
3322
|
* @param callback Callback to get an item's grouping key
|
|
1823
3323
|
* @returns Map of keyed items
|
|
3324
|
+
*
|
|
3325
|
+
* @example
|
|
3326
|
+
* ```typescript
|
|
3327
|
+
* toMap(
|
|
3328
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3329
|
+
* item => item.value,
|
|
3330
|
+
* ); // => Map { 10 => {id: 3, value: 10}, 20 => {id: 2, value: 20} }
|
|
3331
|
+
* ```
|
|
1824
3332
|
*/
|
|
1825
3333
|
declare function toMap<Item, Callback extends (item: Item, index: number, array: Item[]) => Key$1>(array: Item[], callback: Callback): Map<ReturnType<Callback>, Item>;
|
|
1826
3334
|
/**
|
|
1827
3335
|
* Create a Map from an array of items using a key
|
|
1828
3336
|
*
|
|
1829
3337
|
* If multiple items have the same key, the latest item will be used
|
|
3338
|
+
*
|
|
1830
3339
|
* @param array Array to convert
|
|
1831
3340
|
* @param key Key to use for grouping
|
|
1832
3341
|
* @returns Map of keyed items
|
|
3342
|
+
*
|
|
3343
|
+
* @example
|
|
3344
|
+
* ```typescript
|
|
3345
|
+
* toMap(
|
|
3346
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3347
|
+
* 'value',
|
|
3348
|
+
* ); // => Map { 10 => {id: 3, value: 10}, 20 => {id: 2, value: 20} }
|
|
3349
|
+
* ```
|
|
1833
3350
|
*/
|
|
1834
3351
|
declare function toMap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Map<Item[ItemKey], Item>;
|
|
1835
3352
|
/**
|
|
1836
3353
|
* Create a Map from an array of items _(using indices as keys)_
|
|
3354
|
+
*
|
|
1837
3355
|
* @param array Array to convert
|
|
1838
3356
|
* @returns Map of indiced items
|
|
3357
|
+
*
|
|
3358
|
+
* @example
|
|
3359
|
+
* ```typescript
|
|
3360
|
+
* toMap(
|
|
3361
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3362
|
+
* ); // => Map { 0 => {id: 1, value: 10}, 1 => {id: 2, value: 20}, 2 => {id: 3, value: 10} }
|
|
3363
|
+
* ```
|
|
1839
3364
|
*/
|
|
1840
3365
|
declare function toMap<Item>(array: Item[]): Map<number, Item>;
|
|
1841
3366
|
declare namespace toMap {
|
|
@@ -1845,58 +3370,116 @@ declare namespace toMap {
|
|
|
1845
3370
|
* Create a Map from an array of items using callbacks, grouping values into arrays
|
|
1846
3371
|
*
|
|
1847
3372
|
* Available as `toMapArrays` and `toMap.arrays`
|
|
3373
|
+
*
|
|
1848
3374
|
* @param array Array to convert
|
|
1849
3375
|
* @param key Callback to get an item's grouping key
|
|
1850
3376
|
* @param value Callback to get an item's value
|
|
1851
3377
|
* @returns Map of keyed arrays of values
|
|
3378
|
+
*
|
|
3379
|
+
* @example
|
|
3380
|
+
* ```typescript
|
|
3381
|
+
* toMapArrays(
|
|
3382
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3383
|
+
* item => item.value,
|
|
3384
|
+
* item => item.id,
|
|
3385
|
+
* ); // => Map { 10 => [1, 3], 20 => [2] }
|
|
3386
|
+
* ```
|
|
1852
3387
|
*/
|
|
1853
3388
|
declare function toMapArrays<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key$1, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Map<ReturnType<KeyCallback>, ReturnType<ValueCallback>[]>;
|
|
1854
3389
|
/**
|
|
1855
3390
|
* Create a Map from an array of items using a callback and value, grouping values into arrays
|
|
1856
3391
|
*
|
|
1857
3392
|
* Available as `toMapArrays` and `toMap.arrays`
|
|
3393
|
+
*
|
|
1858
3394
|
* @param array Array to convert
|
|
1859
3395
|
* @param key Callback to get an item's grouping key
|
|
1860
3396
|
* @param value Key to use for value
|
|
1861
3397
|
* @returns Map of keyed arrays of values
|
|
3398
|
+
*
|
|
3399
|
+
* @example
|
|
3400
|
+
* ```typescript
|
|
3401
|
+
* toMapArrays(
|
|
3402
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3403
|
+
* item => item.value,
|
|
3404
|
+
* 'id',
|
|
3405
|
+
* ); // => Map { 10 => [1, 3], 20 => [2] }
|
|
3406
|
+
* ```
|
|
1862
3407
|
*/
|
|
1863
3408
|
declare function toMapArrays<Item extends PlainObject, KeyCallback extends (item: Item, index: number, array: Item[]) => Key$1, ItemValue extends keyof Item>(array: Item[], key: KeyCallback, value: ItemValue): Map<ReturnType<KeyCallback>, Item[ItemValue][]>;
|
|
1864
3409
|
/**
|
|
1865
3410
|
* Create a Map from an array of items using a key and callback, grouping values into arrays
|
|
1866
3411
|
*
|
|
1867
3412
|
* Available as `toMapArrays` and `toMap.arrays`
|
|
3413
|
+
*
|
|
1868
3414
|
* @param array Array to convert
|
|
1869
3415
|
* @param key Key to use for grouping
|
|
1870
3416
|
* @param value Callback to get an item's value
|
|
1871
3417
|
* @returns Map of keyed arrays of values
|
|
3418
|
+
*
|
|
3419
|
+
* @example
|
|
3420
|
+
* ```typescript
|
|
3421
|
+
* toMapArrays(
|
|
3422
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3423
|
+
* 'value',
|
|
3424
|
+
* item => item.id,
|
|
3425
|
+
* ); // => Map { 10 => [1, 3], 20 => [2] }
|
|
3426
|
+
* ```
|
|
1872
3427
|
*/
|
|
1873
3428
|
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], ReturnType<ValueCallback>[]>;
|
|
1874
3429
|
/**
|
|
1875
3430
|
* Create a Map from an array of items using a key and value, grouping values into arrays
|
|
1876
3431
|
*
|
|
1877
3432
|
* Available as `toMapArrays` and `toMap.arrays`
|
|
3433
|
+
*
|
|
1878
3434
|
* @param array Array to convert
|
|
1879
3435
|
* @param key Key to use for grouping
|
|
1880
3436
|
* @param value Key to use for value
|
|
1881
3437
|
* @returns Map of keyed arrays of values
|
|
3438
|
+
*
|
|
3439
|
+
* @example
|
|
3440
|
+
* ```typescript
|
|
3441
|
+
* toMapArrays(
|
|
3442
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3443
|
+
* 'value',
|
|
3444
|
+
* 'id',
|
|
3445
|
+
* ); // => Map { 10 => [1, 3], 20 => [2] }
|
|
3446
|
+
* ```
|
|
1882
3447
|
*/
|
|
1883
3448
|
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][]>;
|
|
1884
3449
|
/**
|
|
1885
3450
|
* Create a Map from an array of items using a callback, grouping items into arrays
|
|
1886
3451
|
*
|
|
1887
3452
|
* Available as `toMapArrays` and `toMap.arrays`
|
|
3453
|
+
*
|
|
1888
3454
|
* @param array Array to convert
|
|
1889
3455
|
* @param callback Callback to get an item's grouping key
|
|
1890
3456
|
* @returns Map of keyed arrays of items
|
|
3457
|
+
*
|
|
3458
|
+
* @example
|
|
3459
|
+
* ```typescript
|
|
3460
|
+
* toMapArrays(
|
|
3461
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3462
|
+
* item => item.value,
|
|
3463
|
+
* ); // => Map { 10 => [{id: 1, value: 10}, {id: 3, value: 10}], 20 => [{id: 2, value: 20}] }
|
|
3464
|
+
* ```
|
|
1891
3465
|
*/
|
|
1892
3466
|
declare function toMapArrays<Item, Callback extends (item: Item, index: number, array: Item[]) => Key$1>(array: Item[], callback: Callback): Map<ReturnType<Callback>, Item[]>;
|
|
1893
3467
|
/**
|
|
1894
3468
|
* Create a Map from an array of items using a key, grouping items into arrays
|
|
1895
3469
|
*
|
|
1896
3470
|
* Available as `toMapArrays` and `toMap.arrays`
|
|
3471
|
+
*
|
|
1897
3472
|
* @param array Array to convert
|
|
1898
3473
|
* @param key Key to use for grouping
|
|
1899
3474
|
* @returns Map of keyed arrays of items
|
|
3475
|
+
*
|
|
3476
|
+
* @example
|
|
3477
|
+
* ```typescript
|
|
3478
|
+
* toMapArrays(
|
|
3479
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3480
|
+
* 'value',
|
|
3481
|
+
* ); // => Map { 10 => [{id: 1, value: 10}, {id: 3, value: 10}], 20 => [{id: 2, value: 20}] }
|
|
3482
|
+
* ```
|
|
1900
3483
|
*/
|
|
1901
3484
|
declare function toMapArrays<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Map<Item[ItemKey], Item[]>;
|
|
1902
3485
|
//#endregion
|
|
@@ -1905,64 +3488,130 @@ declare function toMapArrays<Item extends PlainObject, ItemKey extends keyof Ite
|
|
|
1905
3488
|
* Create a record from an array of items using callbacks
|
|
1906
3489
|
*
|
|
1907
3490
|
* If multiple items have the same key, the latest item will be used
|
|
3491
|
+
*
|
|
1908
3492
|
* @param array Array to convert
|
|
1909
3493
|
* @param key Callback to get an item's grouping key
|
|
1910
3494
|
* @param value Callback to get an item's value
|
|
1911
3495
|
* @returns Record of keyed values
|
|
3496
|
+
*
|
|
3497
|
+
* @example
|
|
3498
|
+
* ```typescript
|
|
3499
|
+
* toRecord(
|
|
3500
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3501
|
+
* item => item.value,
|
|
3502
|
+
* item => item.id,
|
|
3503
|
+
* ); // => { 10: 3, 20: 2 }
|
|
3504
|
+
* ```
|
|
1912
3505
|
*/
|
|
1913
3506
|
declare function toRecord<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key$1, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Record<ReturnType<KeyCallback>, ReturnType<ValueCallback>>;
|
|
1914
3507
|
/**
|
|
1915
3508
|
* Create a record from an array of items using a callback and value
|
|
1916
3509
|
*
|
|
1917
3510
|
* If multiple items have the same key, the latest item will be used
|
|
3511
|
+
*
|
|
1918
3512
|
* @param array Array to convert
|
|
1919
3513
|
* @param callback Callback to get an item's grouping key
|
|
1920
3514
|
* @param value Key to use for value
|
|
1921
3515
|
* @returns Record with keys
|
|
3516
|
+
*
|
|
3517
|
+
* @example
|
|
3518
|
+
* ```typescript
|
|
3519
|
+
* toRecord(
|
|
3520
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3521
|
+
* item => item.value,
|
|
3522
|
+
* 'id',
|
|
3523
|
+
* ); // => { 10: 3, 20: 2 }
|
|
3524
|
+
* ```
|
|
1922
3525
|
*/
|
|
1923
3526
|
declare function toRecord<Item extends PlainObject, Callback extends (item: Item, index: number, array: Item[]) => Key$1, ItemValue extends keyof Item>(array: Item[], callback: Callback, value: ItemValue): Record<ReturnType<Callback>, Item[ItemValue]>;
|
|
1924
3527
|
/**
|
|
1925
3528
|
* Create a record from an array of items using a key and callback
|
|
1926
3529
|
*
|
|
1927
3530
|
* If multiple items have the same key, the latest item will be used
|
|
3531
|
+
*
|
|
1928
3532
|
* @param array Array to convert
|
|
1929
3533
|
* @param key Key to use for grouping
|
|
1930
3534
|
* @param callback Callback to get an item's value
|
|
1931
3535
|
* @returns Record with keys
|
|
3536
|
+
*
|
|
3537
|
+
* @example
|
|
3538
|
+
* ```typescript
|
|
3539
|
+
* toRecord(
|
|
3540
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3541
|
+
* 'value',
|
|
3542
|
+
* item => item.id,
|
|
3543
|
+
* ); // => { 10: 3, 20: 2 }
|
|
3544
|
+
* ```
|
|
1932
3545
|
*/
|
|
1933
3546
|
declare function toRecord<Item extends PlainObject, ItemKey extends keyof Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, callback: Callback): Simplify<Record<KeyedValue<Item, ItemKey>, ReturnType<Callback>>>;
|
|
1934
3547
|
/**
|
|
1935
3548
|
* Create a record from an array of items using a key and value
|
|
1936
3549
|
*
|
|
1937
3550
|
* If multiple items have the same key, the latest item will be used
|
|
3551
|
+
*
|
|
1938
3552
|
* @param array Array to convert
|
|
1939
3553
|
* @param key Key to use for grouping
|
|
1940
3554
|
* @param value Key to use for value
|
|
1941
3555
|
* @returns Record of keyed values
|
|
3556
|
+
*
|
|
3557
|
+
* @example
|
|
3558
|
+
* ```typescript
|
|
3559
|
+
* toRecord(
|
|
3560
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3561
|
+
* 'value',
|
|
3562
|
+
* 'id',
|
|
3563
|
+
* ); // => { 10: 3, 20: 2 }
|
|
3564
|
+
* ```
|
|
1942
3565
|
*/
|
|
1943
3566
|
declare function toRecord<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Simplify<Record<KeyedValue<Item, ItemKey>, Item[ItemValue]>>;
|
|
1944
3567
|
/**
|
|
1945
3568
|
* Create a record from an array of items using a callback
|
|
1946
3569
|
*
|
|
1947
3570
|
* If multiple items have the same key, the latest item will be used
|
|
3571
|
+
*
|
|
1948
3572
|
* @param array Array to convert
|
|
1949
3573
|
* @param callback Callback to get an item's grouping key
|
|
1950
3574
|
* @returns Record of keyed values
|
|
3575
|
+
*
|
|
3576
|
+
* @example
|
|
3577
|
+
* ```typescript
|
|
3578
|
+
* toRecord(
|
|
3579
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3580
|
+
* item => item.value,
|
|
3581
|
+
* ); // => { 10: {id: 3, value: 10}, 20: {id: 2, value: 20} }
|
|
3582
|
+
* ```
|
|
1951
3583
|
*/
|
|
1952
3584
|
declare function toRecord<Item, Callback extends (item: Item, index: number, array: Item[]) => Key$1>(array: Item[], callback: Callback): Record<ReturnType<Callback>, Item>;
|
|
1953
3585
|
/**
|
|
1954
3586
|
* Create a record from an array of items using a key
|
|
1955
3587
|
*
|
|
1956
3588
|
* If multiple items have the same key, the latest item will be used
|
|
3589
|
+
*
|
|
1957
3590
|
* @param array Array to convert
|
|
1958
3591
|
* @param key Key to use for grouping
|
|
1959
3592
|
* @returns Record of keyed values
|
|
3593
|
+
*
|
|
3594
|
+
* @example
|
|
3595
|
+
* ```typescript
|
|
3596
|
+
* toRecord(
|
|
3597
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3598
|
+
* 'value',
|
|
3599
|
+
* ); // => { 10: {id: 3, value: 10}, 20: {id: 2, value: 20} }
|
|
3600
|
+
* ```
|
|
1960
3601
|
*/
|
|
1961
3602
|
declare function toRecord<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Simplify<Record<KeyedValue<Item, ItemKey>, Item>>;
|
|
1962
3603
|
/**
|
|
1963
3604
|
* Create a record from an array of items _(using indices as keys)_
|
|
3605
|
+
*
|
|
1964
3606
|
* @param array Array to convert
|
|
1965
3607
|
* @returns Record of indiced values
|
|
3608
|
+
*
|
|
3609
|
+
* @example
|
|
3610
|
+
* ```typescript
|
|
3611
|
+
* toRecord(
|
|
3612
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3613
|
+
* ); // => { 0: {id: 1, value: 10}, 1: {id: 2, value: 20}, 2: {id: 3, value: 10} }
|
|
3614
|
+
* ```
|
|
1966
3615
|
*/
|
|
1967
3616
|
declare function toRecord<Item>(array: Item[]): Record<number, Item>;
|
|
1968
3617
|
declare namespace toRecord {
|
|
@@ -1972,58 +3621,116 @@ declare namespace toRecord {
|
|
|
1972
3621
|
* Create a record from an array of items using callbacks, grouping values into arrays
|
|
1973
3622
|
*
|
|
1974
3623
|
* Available as `toRecordArrays` and `toRecord.arrays`
|
|
3624
|
+
*
|
|
1975
3625
|
* @param array Array to convert
|
|
1976
3626
|
* @param key Callback to get an item's grouping key
|
|
1977
3627
|
* @param value Callback to get an item's value
|
|
1978
3628
|
* @returns Record of keyed arrays of values
|
|
3629
|
+
*
|
|
3630
|
+
* @example
|
|
3631
|
+
* ```typescript
|
|
3632
|
+
* toRecordArrays(
|
|
3633
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3634
|
+
* item => item.value,
|
|
3635
|
+
* item => item.id,
|
|
3636
|
+
* ); // => { 10: [1, 3], 20: [2] }
|
|
3637
|
+
* ```
|
|
1979
3638
|
*/
|
|
1980
3639
|
declare function toRecordArrays<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key$1, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Record<ReturnType<KeyCallback>, ReturnType<ValueCallback>[]>;
|
|
1981
3640
|
/**
|
|
1982
3641
|
* Create a record from an array of items using a callback and value, grouping values into arrays
|
|
1983
3642
|
*
|
|
1984
3643
|
* Available as `toRecordArrays` and `toRecord.arrays`
|
|
3644
|
+
*
|
|
1985
3645
|
* @param array Array to convert
|
|
1986
3646
|
* @param callback Callback to get an item's grouping key
|
|
1987
3647
|
* @param value Key to use for value
|
|
1988
3648
|
* @returns Record of keyed arrays of values
|
|
3649
|
+
*
|
|
3650
|
+
* @example
|
|
3651
|
+
* ```typescript
|
|
3652
|
+
* toRecordArrays(
|
|
3653
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3654
|
+
* item => item.value,
|
|
3655
|
+
* 'id',
|
|
3656
|
+
* ); // => { 10: [1, 3], 20: [2] }
|
|
3657
|
+
* ```
|
|
1989
3658
|
*/
|
|
1990
3659
|
declare function toRecordArrays<Item extends PlainObject, Callback extends (item: Item, index: number, array: Item[]) => Key$1, ItemValue extends keyof Item>(array: Item[], callback: Callback, value: ItemValue): Record<ReturnType<Callback>, Item[ItemValue][]>;
|
|
1991
3660
|
/**
|
|
1992
3661
|
* Create a record from an array of items using a key and callback, grouping values into arrays
|
|
1993
3662
|
*
|
|
1994
3663
|
* Available as `toRecordArrays` and `toRecord.arrays`
|
|
3664
|
+
*
|
|
1995
3665
|
* @param array Array to convert
|
|
1996
3666
|
* @param key Key to use for grouping
|
|
1997
3667
|
* @param callback Callback to get an item's value
|
|
1998
3668
|
* @returns Record of keyed arrays of values
|
|
3669
|
+
*
|
|
3670
|
+
* @example
|
|
3671
|
+
* ```typescript
|
|
3672
|
+
* toRecordArrays(
|
|
3673
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3674
|
+
* 'value',
|
|
3675
|
+
* item => item.id,
|
|
3676
|
+
* ); // => { 10: [1, 3], 20: [2] }
|
|
3677
|
+
* ```
|
|
1999
3678
|
*/
|
|
2000
3679
|
declare function toRecordArrays<Item extends PlainObject, ItemKey extends keyof Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, callback: Callback): Simplify<Record<KeyedValue<Item, ItemKey>, ReturnType<Callback>[]>>;
|
|
2001
3680
|
/**
|
|
2002
3681
|
* Create a record from an array of items using a key and value, grouping values into arrays
|
|
2003
3682
|
*
|
|
2004
3683
|
* Available as `toRecordArrays` and `toRecord.arrays`
|
|
3684
|
+
*
|
|
2005
3685
|
* @param array Array to convert
|
|
2006
3686
|
* @param key Key to use for grouping
|
|
2007
3687
|
* @param value Key to use for value
|
|
2008
3688
|
* @returns Record of keyed arrays of values
|
|
3689
|
+
*
|
|
3690
|
+
* @example
|
|
3691
|
+
* ```typescript
|
|
3692
|
+
* toRecordArrays(
|
|
3693
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3694
|
+
* 'value',
|
|
3695
|
+
* 'id',
|
|
3696
|
+
* ); // => { 10: [1, 3], 20: [2] }
|
|
3697
|
+
* ```
|
|
2009
3698
|
*/
|
|
2010
3699
|
declare function toRecordArrays<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Simplify<Record<KeyedValue<Item, ItemKey>, Item[ItemValue][]>>;
|
|
2011
3700
|
/**
|
|
2012
3701
|
* Create a record from an array of items using a callback, grouping items into arrays
|
|
2013
3702
|
*
|
|
2014
3703
|
* Available as `toRecordArrays` and `toRecord.arrays`
|
|
3704
|
+
*
|
|
2015
3705
|
* @param array Array to convert
|
|
2016
3706
|
* @param callback Callback to get an item's grouping key
|
|
2017
3707
|
* @returns Record of keyed arrays of items
|
|
3708
|
+
*
|
|
3709
|
+
* @example
|
|
3710
|
+
* ```typescript
|
|
3711
|
+
* toRecordArrays(
|
|
3712
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3713
|
+
* item => item.value,
|
|
3714
|
+
* ); // => { 10: [{id: 1, value: 10}, {id: 3, value: 10}], 20: [{id: 2, value: 20}] }
|
|
3715
|
+
* ```
|
|
2018
3716
|
*/
|
|
2019
3717
|
declare function toRecordArrays<Item, Callback extends (item: Item, index: number, array: Item[]) => Key$1>(array: Item[], callback: Callback): Record<ReturnType<Callback>, Item[]>;
|
|
2020
3718
|
/**
|
|
2021
3719
|
* Create a record from an array of items using a key, grouping items into arrays
|
|
2022
3720
|
*
|
|
2023
3721
|
* Available as `toRecordArrays` and `toRecord.arrays`
|
|
3722
|
+
*
|
|
2024
3723
|
* @param array Array to convert
|
|
2025
3724
|
* @param key Key to use for grouping
|
|
2026
3725
|
* @returns Record of keyed arrays of items
|
|
3726
|
+
*
|
|
3727
|
+
* @example
|
|
3728
|
+
* ```typescript
|
|
3729
|
+
* toRecordArrays(
|
|
3730
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
3731
|
+
* 'value',
|
|
3732
|
+
* ); // => { 10: [{id: 1, value: 10}, {id: 3, value: 10}], 20: [{id: 2, value: 20}] }
|
|
3733
|
+
* ```
|
|
2027
3734
|
*/
|
|
2028
3735
|
declare function toRecordArrays<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Simplify<Record<KeyedValue<Item, ItemKey>, Item[]>>;
|
|
2029
3736
|
//#endregion
|
|
@@ -2844,16 +4551,38 @@ declare function registerEqualizer<Instance>(constructor: Constructor<Instance>,
|
|
|
2844
4551
|
//#region src/internal/value/get.d.ts
|
|
2845
4552
|
/**
|
|
2846
4553
|
* Get the value from an object using a known path
|
|
4554
|
+
*
|
|
4555
|
+
* @example
|
|
4556
|
+
* ```typescript
|
|
4557
|
+
* const data = {foo: {bar: {baz: 42}}};
|
|
4558
|
+
*
|
|
4559
|
+
* getValue(data, 'foo'); // {bar: {baz: 42}}
|
|
4560
|
+
* getValue(data, 'foo.bar'); // {baz: 42}
|
|
4561
|
+
* getValue(data, 'foo.bar.baz'); // 42
|
|
4562
|
+
* getValue(data, 'foo.nope'); // undefined
|
|
4563
|
+
* ```
|
|
4564
|
+
*
|
|
2847
4565
|
* @param data Object to get value from
|
|
2848
|
-
* @param path Path for value
|
|
4566
|
+
* @param path Path for value
|
|
2849
4567
|
* @returns Found value, or `undefined`
|
|
2850
4568
|
*/
|
|
2851
4569
|
declare function getValue<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path): NestedValue<Data, Path>;
|
|
2852
4570
|
/**
|
|
2853
4571
|
* Get the value from an object using an unknown path
|
|
4572
|
+
*
|
|
4573
|
+
* @example
|
|
4574
|
+
* ```typescript
|
|
4575
|
+
* const data = {foo: {bar: {baz: 42}}};
|
|
4576
|
+
*
|
|
4577
|
+
* getValue(data, 'foo'); // {bar: {baz: 42}}
|
|
4578
|
+
* getValue(data, 'foo.bar'); // {baz: 42}
|
|
4579
|
+
* getValue(data, 'Foo.Bar.Baz', true); // 42
|
|
4580
|
+
* getValue(data, 'foo.nope'); // undefined
|
|
4581
|
+
* ```
|
|
4582
|
+
*
|
|
2854
4583
|
* @param data Object to get value from
|
|
2855
|
-
* @param path Path for value
|
|
2856
|
-
* @param ignoreCase If `true`,
|
|
4584
|
+
* @param path Path for value
|
|
4585
|
+
* @param ignoreCase If `true`, path matching is case-insensitive
|
|
2857
4586
|
* @returns Found value, or `undefined`
|
|
2858
4587
|
*/
|
|
2859
4588
|
declare function getValue<Data extends PlainObject>(data: Data, path: string, ignoreCase?: boolean): unknown;
|
|
@@ -2863,7 +4592,7 @@ declare function getValue<Data extends PlainObject>(data: Data, path: string, ig
|
|
|
2863
4592
|
* Check if a nested property is defined in an object
|
|
2864
4593
|
* @param data Object to check in
|
|
2865
4594
|
* @param path Path for property
|
|
2866
|
-
* @
|
|
4595
|
+
* @returns `true` if the property exists, `false` otherwise
|
|
2867
4596
|
*/
|
|
2868
4597
|
declare function hasValue<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path): boolean;
|
|
2869
4598
|
/**
|
|
@@ -2871,7 +4600,7 @@ declare function hasValue<Data extends PlainObject, Path extends NestedKeys<Data
|
|
|
2871
4600
|
* @param data Object to check in
|
|
2872
4601
|
* @param path Path for property
|
|
2873
4602
|
* @param ignoreCase If `true`, the path matching is case-insensitive
|
|
2874
|
-
* @
|
|
4603
|
+
* @returns `true` if the property exists, `false` otherwise
|
|
2875
4604
|
*/
|
|
2876
4605
|
declare function hasValue<Data extends PlainObject>(data: Data, path: string, ignoreCase?: boolean): boolean;
|
|
2877
4606
|
declare namespace hasValue {
|
|
@@ -2884,7 +4613,7 @@ declare namespace hasValue {
|
|
|
2884
4613
|
* @param data Object to check in
|
|
2885
4614
|
* @param path Path for property
|
|
2886
4615
|
* @param ignoreCase If `true`, the path matching is case-insensitive
|
|
2887
|
-
* @
|
|
4616
|
+
* @returns Result object
|
|
2888
4617
|
*/
|
|
2889
4618
|
declare function hasValueResult<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path, ignoreCase?: boolean): Result<NestedValue<Data, ToString<Path>>, string>;
|
|
2890
4619
|
/**
|
|
@@ -2894,7 +4623,7 @@ declare function hasValueResult<Data extends PlainObject, Path extends NestedKey
|
|
|
2894
4623
|
* @param data Object to check in
|
|
2895
4624
|
* @param path Path for property
|
|
2896
4625
|
* @param ignoreCase If `true`, the path matching is case-insensitive
|
|
2897
|
-
* @
|
|
4626
|
+
* @returns Result object
|
|
2898
4627
|
*/
|
|
2899
4628
|
declare function hasValueResult<Data extends PlainObject>(data: Data, path: string, ignoreCase?: boolean): Result<unknown, string>;
|
|
2900
4629
|
//#endregion
|
|
@@ -3358,7 +5087,7 @@ declare function inMap<Value>(map: Map<unknown, Value>, value: Value): boolean;
|
|
|
3358
5087
|
* @param map Map to check in
|
|
3359
5088
|
* @param value Value to check for
|
|
3360
5089
|
* @param key To return the key for the value
|
|
3361
|
-
* @
|
|
5090
|
+
* @returns The key for the value if it exists, otherwise `undefined`
|
|
3362
5091
|
*/
|
|
3363
5092
|
declare function inMap<Key, Value>(map: Map<Key, Value>, value: Value, key: true): Key;
|
|
3364
5093
|
/**
|
|
@@ -3500,10 +5229,6 @@ declare function smush<Value extends PlainObject>(value: Value): Smushed<Value>;
|
|
|
3500
5229
|
* Thanks, type-fest!
|
|
3501
5230
|
*/
|
|
3502
5231
|
type KeysOfUnion<ObjectType> = keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
|
|
3503
|
-
/**
|
|
3504
|
-
* Thanks, type-fest!
|
|
3505
|
-
*/
|
|
3506
|
-
type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Union) => void : never) extends ((mergedIntersection: infer Intersection) => void) ? Intersection & Union : never;
|
|
3507
5232
|
/**
|
|
3508
5233
|
* An unsmushed object, with all dot notation keys turned into nested keys
|
|
3509
5234
|
*/
|
|
@@ -3520,13 +5245,16 @@ declare function unsmush<Value extends PlainObject>(value: Value): Unsmushed<Val
|
|
|
3520
5245
|
* Options for assigning values
|
|
3521
5246
|
*/
|
|
3522
5247
|
type AssignOptions = Omit<MergeOptions, 'assignValues'>;
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
5248
|
+
type Assigner = {
|
|
5249
|
+
/**
|
|
5250
|
+
* Assign values from one or more objects to the first one
|
|
5251
|
+
*
|
|
5252
|
+
* @param to Value to assign to
|
|
5253
|
+
* @param from Values to assign
|
|
5254
|
+
* @returns Assigned value
|
|
5255
|
+
*/
|
|
5256
|
+
<To extends PlainObject, From extends PlainObject[]>(to: To, from: [...From]): To & UnionToIntersection<From[number]>;
|
|
5257
|
+
};
|
|
3530
5258
|
/**
|
|
3531
5259
|
* Options for merging values
|
|
3532
5260
|
*/
|
|
@@ -3560,20 +5288,24 @@ type MergeOptions = {
|
|
|
3560
5288
|
*/
|
|
3561
5289
|
skipNullableInArrays?: boolean;
|
|
3562
5290
|
};
|
|
5291
|
+
type Merger = {
|
|
5292
|
+
/**
|
|
5293
|
+
* Merge multiple arrays or objects into a single one
|
|
5294
|
+
*
|
|
5295
|
+
* @param values Values to merge
|
|
5296
|
+
* @returns Merged value
|
|
5297
|
+
*/
|
|
5298
|
+
<Values extends ArrayOrPlainObject[]>(values: NestedPartial<Values[number]>[]): UnionToIntersection<Values[number]>;
|
|
5299
|
+
};
|
|
3563
5300
|
/**
|
|
3564
|
-
*
|
|
3565
|
-
*
|
|
3566
|
-
* @returns Merged value
|
|
3567
|
-
*/
|
|
3568
|
-
type Merger<Model extends ArrayOrPlainObject = ArrayOrPlainObject> = (values: NestedPartial<Model>[]) => Model;
|
|
3569
|
-
/**
|
|
3570
|
-
* Assign values from multiple arrays or objects to the first one
|
|
5301
|
+
* Assign values from one or more objects to the first one
|
|
5302
|
+
*
|
|
3571
5303
|
* @param to Value to assign to
|
|
3572
5304
|
* @param from Values to assign
|
|
3573
5305
|
* @param options Assigning options
|
|
3574
5306
|
* @returns Assigned value
|
|
3575
5307
|
*/
|
|
3576
|
-
declare function assign<
|
|
5308
|
+
declare function assign<To extends PlainObject, From extends PlainObject[]>(to: To, from: [...From], options?: AssignOptions): To & UnionToIntersection<From[number]>;
|
|
3577
5309
|
declare namespace assign {
|
|
3578
5310
|
var initialize: typeof initializeAssigner;
|
|
3579
5311
|
}
|
|
@@ -3581,32 +5313,28 @@ declare namespace assign {
|
|
|
3581
5313
|
* Create an assigner with predefined options
|
|
3582
5314
|
*
|
|
3583
5315
|
* Available as `initializeAssigner` and `assign.initialize`
|
|
5316
|
+
*
|
|
3584
5317
|
* @param options Assigning options
|
|
3585
5318
|
* @returns Assigner function
|
|
3586
5319
|
*/
|
|
3587
|
-
declare function initializeAssigner
|
|
5320
|
+
declare function initializeAssigner(options?: AssignOptions): Assigner;
|
|
3588
5321
|
/**
|
|
3589
5322
|
* Create a merger with predefined options
|
|
3590
5323
|
*
|
|
3591
5324
|
* Available as `initializeMerger` and `merge.initialize`
|
|
5325
|
+
*
|
|
3592
5326
|
* @param options Merging options
|
|
3593
5327
|
* @returns Merger function
|
|
3594
5328
|
*/
|
|
3595
5329
|
declare function initializeMerger(options?: MergeOptions): Merger;
|
|
3596
5330
|
/**
|
|
3597
5331
|
* Merge multiple arrays or objects into a single one
|
|
5332
|
+
*
|
|
3598
5333
|
* @param values Values to merge
|
|
3599
5334
|
* @param options Merging options
|
|
3600
5335
|
* @returns Merged value
|
|
3601
5336
|
*/
|
|
3602
|
-
declare function merge<
|
|
3603
|
-
/**
|
|
3604
|
-
* Merge multiple arrays or objects into a single one
|
|
3605
|
-
* @param values Values to merge
|
|
3606
|
-
* @param options Merging options
|
|
3607
|
-
* @returns Merged value
|
|
3608
|
-
*/
|
|
3609
|
-
declare function merge(values: NestedPartial<ArrayOrPlainObject>[], options?: MergeOptions): ArrayOrPlainObject;
|
|
5337
|
+
declare function merge<Values extends ArrayOrPlainObject[]>(values: [...Values], options?: MergeOptions): UnionToIntersection<Values[number]>;
|
|
3610
5338
|
declare namespace merge {
|
|
3611
5339
|
var initialize: typeof initializeMerger;
|
|
3612
5340
|
}
|
|
@@ -3639,7 +5367,7 @@ declare function initializeTransformer<Value extends PlainObject>(transform: Tra
|
|
|
3639
5367
|
*
|
|
3640
5368
|
* Available as `initializeTransformer` and `transform.initialize`
|
|
3641
5369
|
* @param transformers Keyed transformer functions
|
|
3642
|
-
* @
|
|
5370
|
+
* @returns Transformer
|
|
3643
5371
|
*/
|
|
3644
5372
|
declare function initializeTransformer<Value extends PlainObject>(transformers: TransformCallbacks<Value>): Transformer<Value>;
|
|
3645
5373
|
/**
|
|
@@ -4323,6 +6051,17 @@ declare const logger: Logger;
|
|
|
4323
6051
|
//#region src/internal/math/aggregate.d.ts
|
|
4324
6052
|
/**
|
|
4325
6053
|
* Get the maximum value from a list of items
|
|
6054
|
+
*
|
|
6055
|
+
* @example
|
|
6056
|
+
* ```typescript
|
|
6057
|
+
* max(
|
|
6058
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}],
|
|
6059
|
+
* item => item.value,
|
|
6060
|
+
* ); // 20
|
|
6061
|
+
*
|
|
6062
|
+
* max([], item => item.value); // Number.NaN
|
|
6063
|
+
* ```
|
|
6064
|
+
*
|
|
4326
6065
|
* @param items List of items
|
|
4327
6066
|
* @param callback Callback to get an item's value
|
|
4328
6067
|
* @returns Maximum value, or `NaN` if no maximum can be found
|
|
@@ -4330,6 +6069,17 @@ declare const logger: Logger;
|
|
|
4330
6069
|
declare function max<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): number;
|
|
4331
6070
|
/**
|
|
4332
6071
|
* Get the maximum value from a list of items
|
|
6072
|
+
*
|
|
6073
|
+
* @example
|
|
6074
|
+
* ```typescript
|
|
6075
|
+
* max(
|
|
6076
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}],
|
|
6077
|
+
* 'value',
|
|
6078
|
+
* ); // 20
|
|
6079
|
+
*
|
|
6080
|
+
* max([], 'value'); // Number.NaN
|
|
6081
|
+
* ```
|
|
6082
|
+
*
|
|
4333
6083
|
* @param items List of items
|
|
4334
6084
|
* @param key Key to use for value
|
|
4335
6085
|
* @returns Maximum value, or `NaN` if no maximum can be found
|
|
@@ -4337,6 +6087,13 @@ declare function max<Item>(items: Item[], callback: (item: Item, index: number,
|
|
|
4337
6087
|
declare function max<Item extends PlainObject, ItemKey extends keyof NumericalValues<Item>>(items: Item[], key: ItemKey): number;
|
|
4338
6088
|
/**
|
|
4339
6089
|
* Get the maximum value from a list of numbers
|
|
6090
|
+
*
|
|
6091
|
+
* @example
|
|
6092
|
+
* ```typescript
|
|
6093
|
+
* max([10, 20]); // 20
|
|
6094
|
+
* max([]); // Number.NaN
|
|
6095
|
+
* ```
|
|
6096
|
+
*
|
|
4340
6097
|
* @param values List of numbers
|
|
4341
6098
|
* @returns Maximum value, or `NaN` if no maximum can be found
|
|
4342
6099
|
*/
|
|
@@ -5654,4 +7411,4 @@ declare class SizedSet<Value = unknown> extends Set<Value> {
|
|
|
5654
7411
|
get(value: Value, update?: boolean): Value | undefined;
|
|
5655
7412
|
}
|
|
5656
7413
|
//#endregion
|
|
5657
|
-
export { AnyResult, ArrayComparison, ArrayComparisonSorter, ArrayKeySorter, ArrayOrPlainObject, ArrayValueSorter, AssertProperty, Asserter, AssignOptions, Assigner, AsyncCancelableCallback, AttemptFlow, AttemptFlowPromise, type Beacon, type BeaconOptions, BuiltIns, CancelableCallback, CancelablePromise, type Color, Constructor, DiffOptions, DiffResult, DiffValue, EqualOptions, Err, EventPosition, type Events, ExtendedErr, ExtendedResult, Flow, FlowPromise, Frozen, FulfilledPromise, FuzzyConfiguration, FuzzyOptions, FuzzyResult, FuzzySearchOptions, GenericAsyncCallback, GenericCallback, type HSLAColor, type HSLColor, type Kalas, Key$1 as Key, type KeyedQueue, KeyedValue, type Logger, type Memoized, type MemoizedOptions, MergeOptions, Merger, NestedArray, NestedKeys, NestedPartial, NestedValue, NestedValues, NormalizeOptions, Normalizer, NumericalKeys, NumericalValues, type Observable, type Observer, Ok, OnceAsyncCallback, OnceCallback, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PlainObject, Primitive, PromiseData, PromiseHandlers, PromiseOptions, PromiseParameters, PromiseStrategy, PromiseTimeoutError, PromisesItems, PromisesOptions, PromisesResult, PromisesUnwrapped, PromisesValue, PromisesValues, type Queue, type QueueError, type QueueOptions, type Queued, type QueuedResult, type RGBAColor, type RGBColor, RejectedPromise, RequiredKeys, Result, ResultMatch, RetryError, RetryOptions, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, Shaken, Simplify, SizedMap, SizedSet, Smushed, SortDirection, Sorter, type Subscription, TemplateOptions, type Time, ToString, Transformer, TypedArray, Unsmushed, Unsubscriber, UnwrapValue, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty, assign, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, findLast, first, firstOrDefault, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayComparison, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isSorted, isTypedArray, join, kalas, kebabCase, keyedQueue, last, lastIndexOf, lastOrDefault, logger, lowerCase, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, normalize, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, transform, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
|
|
7414
|
+
export { AnyResult, ArrayComparison, ArrayComparisonSorter, ArrayKeySorter, ArrayOrPlainObject, ArrayValueSorter, AssertProperty, Asserter, AssignOptions, Assigner, AsyncCancelableCallback, AttemptFlow, AttemptFlowPromise, type Beacon, type BeaconOptions, BuiltIns, CancelableCallback, CancelablePromise, type Color, Constructor, DiffOptions, DiffResult, DiffValue, EqualOptions, Err, EventPosition, type Events, ExtendedErr, ExtendedResult, Flow, FlowPromise, Frozen, FulfilledPromise, FuzzyConfiguration, FuzzyOptions, FuzzyResult, FuzzySearchOptions, GenericAsyncCallback, GenericCallback, type HSLAColor, type HSLColor, type Kalas, Key$1 as Key, type KeyedQueue, KeyedValue, type Logger, type Memoized, type MemoizedOptions, MergeOptions, Merger, NestedArray, NestedKeys, NestedPartial, NestedValue, NestedValues, NormalizeOptions, Normalizer, NumericalKeys, NumericalValues, type Observable, type Observer, Ok, OnceAsyncCallback, OnceCallback, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PlainObject, Primitive, PromiseData, PromiseHandlers, PromiseOptions, PromiseParameters, PromiseStrategy, PromiseTimeoutError, PromisesItems, PromisesOptions, PromisesResult, PromisesUnwrapped, PromisesValue, PromisesValues, type Queue, type QueueError, type QueueOptions, type Queued, type QueuedResult, type RGBAColor, type RGBColor, RejectedPromise, RequiredKeys, Result, ResultMatch, RetryError, RetryOptions, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, Shaken, Simplify, SizedMap, SizedSet, Smushed, SortDirection, Sorter, type Subscription, TemplateOptions, type Time, ToString, Transformer, TypedArray, UnionToIntersection, Unsmushed, Unsubscriber, UnwrapValue, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty, assign, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, findLast, first, firstOrDefault, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayComparison, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isSorted, isTypedArray, join, kalas, kebabCase, keyedQueue, last, lastIndexOf, lastOrDefault, logger, lowerCase, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, normalize, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, transform, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
|