@oscarpalmer/atoms 0.185.0 → 0.186.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/dist/array/difference.d.mts +29 -0
  2. package/dist/array/exists.d.mts +35 -0
  3. package/dist/array/filter.d.mts +72 -2
  4. package/dist/array/find.d.mts +70 -0
  5. package/dist/array/first.d.mts +77 -2
  6. package/dist/array/flatten.d.mts +6 -0
  7. package/dist/array/flatten.mjs +6 -0
  8. package/dist/array/from.d.mts +36 -0
  9. package/dist/array/get.d.mts +27 -7
  10. package/dist/array/group-by.d.mts +142 -0
  11. package/dist/array/insert.d.mts +16 -0
  12. package/dist/array/intersection.d.mts +29 -0
  13. package/dist/array/last.d.mts +75 -2
  14. package/dist/array/match.d.mts +161 -32
  15. package/dist/array/move.d.mts +78 -8
  16. package/dist/array/move.mjs +10 -0
  17. package/dist/array/partition.d.mts +35 -0
  18. package/dist/array/push.d.mts +8 -0
  19. package/dist/array/push.mjs +8 -0
  20. package/dist/array/reverse.d.mts +1 -0
  21. package/dist/array/reverse.mjs +1 -0
  22. package/dist/array/select.d.mts +94 -8
  23. package/dist/array/single.d.mts +29 -0
  24. package/dist/array/slice.d.mts +106 -16
  25. package/dist/array/sort.d.mts +21 -0
  26. package/dist/array/splice.d.mts +48 -0
  27. package/dist/array/splice.mjs +2 -1
  28. package/dist/array/swap.d.mts +113 -8
  29. package/dist/array/swap.mjs +1 -0
  30. package/dist/array/to-map.d.mts +124 -0
  31. package/dist/array/to-record.d.mts +124 -0
  32. package/dist/array/to-set.d.mts +24 -0
  33. package/dist/array/toggle.d.mts +38 -3
  34. package/dist/array/union.d.mts +29 -0
  35. package/dist/array/unique.d.mts +24 -0
  36. package/dist/array/update.d.mts +38 -3
  37. package/dist/index.d.mts +1898 -129
  38. package/dist/index.mjs +64 -18
  39. package/dist/internal/array/chunk.d.mts +6 -0
  40. package/dist/internal/array/chunk.mjs +6 -0
  41. package/dist/internal/array/compact.d.mts +12 -0
  42. package/dist/internal/array/index-of.d.mts +70 -0
  43. package/dist/internal/math/aggregate.d.mts +29 -0
  44. package/dist/internal/value/get.d.mts +25 -3
  45. package/dist/internal/value/has.d.mts +4 -4
  46. package/dist/models.d.mts +14 -1
  47. package/dist/value/collection.d.mts +1 -1
  48. package/dist/value/merge.d.mts +28 -25
  49. package/dist/value/merge.mjs +29 -18
  50. package/dist/value/transform.d.mts +1 -1
  51. package/dist/value/unsmush.d.mts +1 -5
  52. package/package.json +5 -5
  53. package/src/array/difference.ts +29 -0
  54. package/src/array/exists.ts +35 -0
  55. package/src/array/filter.ts +72 -2
  56. package/src/array/find.ts +70 -0
  57. package/src/array/first.ts +77 -3
  58. package/src/array/flatten.ts +6 -0
  59. package/src/array/from.ts +36 -0
  60. package/src/array/get.ts +27 -8
  61. package/src/array/group-by.ts +142 -0
  62. package/src/array/insert.ts +16 -2
  63. package/src/array/intersection.ts +29 -0
  64. package/src/array/last.ts +75 -2
  65. package/src/array/match.ts +171 -42
  66. package/src/array/move.ts +82 -12
  67. package/src/array/partition.ts +35 -0
  68. package/src/array/push.ts +8 -2
  69. package/src/array/reverse.ts +1 -0
  70. package/src/array/select.ts +94 -13
  71. package/src/array/single.ts +29 -0
  72. package/src/array/slice.ts +114 -24
  73. package/src/array/sort.ts +21 -0
  74. package/src/array/splice.ts +52 -4
  75. package/src/array/swap.ts +117 -12
  76. package/src/array/to-map.ts +124 -0
  77. package/src/array/to-record.ts +124 -0
  78. package/src/array/to-set.ts +24 -0
  79. package/src/array/toggle.ts +38 -3
  80. package/src/array/union.ts +29 -0
  81. package/src/array/unique.ts +24 -0
  82. package/src/array/update.ts +38 -3
  83. package/src/internal/array/chunk.ts +6 -0
  84. package/src/internal/array/compact.ts +12 -0
  85. package/src/internal/array/index-of.ts +70 -0
  86. package/src/internal/math/aggregate.ts +29 -0
  87. package/src/internal/string.ts +0 -2
  88. package/src/internal/value/get.ts +25 -3
  89. package/src/internal/value/has.ts +4 -4
  90. package/src/models.ts +18 -0
  91. package/src/value/collection.ts +1 -1
  92. package/src/value/merge.ts +88 -66
  93. package/src/value/transform.ts +1 -1
  94. 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 filter
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 filter
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
- * @return First item from the array, or `undefined` if the array is empty
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
- * @return First item from the array, or the default value if the array is empty
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,372 @@ 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
1312
  /**
735
1313
  * Get an array from an unknown value
1314
+ *
736
1315
  * @param value Value to convert to an array
737
1316
  * @returns Array of value
1317
+ *
1318
+ * @example
1319
+ * ```typescript
1320
+ * getArray(123); // => [123]
1321
+ * ```
738
1322
  */
739
1323
  declare function getArray(value: unknown): unknown[];
740
1324
  //#endregion
741
1325
  //#region src/array/insert.d.ts
742
1326
  /**
743
1327
  * Insert items into an array at a specified index
1328
+ *
1329
+ * _(Uses chunking to avoid call stack size being exceeded)_
1330
+ *
744
1331
  * @param array Original array
745
1332
  * @param index Index to insert at
746
1333
  * @param items Inserted items
747
1334
  * @returns Updated array
1335
+ *
1336
+ * @example
1337
+ * ```typescript
1338
+ * insert([1, 2, 3], 1, [4, 5]); // => [1, 4, 5, 2, 3]
1339
+ * ```
748
1340
  */
749
1341
  declare function insert<Item>(array: Item[], index: number, items: Item[]): Item[];
750
1342
  /**
751
1343
  * Insert items into an array _(at the end)_
1344
+ *
1345
+ * _(Uses chunking to avoid call stack size being exceeded)_
1346
+ *
752
1347
  * @param array Original array
753
1348
  * @param items Inserted items
754
1349
  * @returns Updated array
1350
+ *
1351
+ * @example
1352
+ * ```typescript
1353
+ * insert([1, 2, 3], [4, 5]); // => [1, 2, 3, 4, 5]
1354
+ * ```
755
1355
  */
756
1356
  declare function insert<Item>(array: Item[], items: Item[]): Item[];
757
1357
  //#endregion
758
1358
  //#region src/array/intersection.d.ts
759
1359
  /**
760
1360
  * Get the common values between two arrays
1361
+ *
761
1362
  * @param first First array
762
1363
  * @param second Second array
763
1364
  * @param callback Callback to get an item's value for comparison
764
1365
  * @returns Common values from both arrays
1366
+ *
1367
+ * @example
1368
+ * ```typescript
1369
+ * intersection(
1370
+ * [{id: 1}, {id: 2}, {id: 3}],
1371
+ * [{id: 2}, {id: 3}, {id: 4}],
1372
+ * item => item.id,
1373
+ * ); // => [{id: 2}, {id: 3}]
1374
+ * ```
765
1375
  */
766
1376
  declare function intersection<First, Second>(first: First[], second: Second[], callback: (item: First | Second) => unknown): First[];
767
1377
  /**
768
1378
  * Get the common values between two arrays
1379
+ *
769
1380
  * @param first First array
770
1381
  * @param second Second array
771
1382
  * @param key Key to get an item's value for comparison
772
1383
  * @returns Common values from both arrays
1384
+ *
1385
+ * @example
1386
+ * ```typescript
1387
+ * intersection(
1388
+ * [{id: 1}, {id: 2}, {id: 3}],
1389
+ * [{id: 2}, {id: 3}, {id: 4}],
1390
+ * 'id',
1391
+ * ); // => [{id: 2}, {id: 3}]
1392
+ * ```
773
1393
  */
774
1394
  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
1395
  /**
776
1396
  * Get the common values between two arrays
1397
+ *
777
1398
  * @param first First array
778
1399
  * @param second Second array
779
1400
  * @returns Common values from both arrays
1401
+ *
1402
+ * @example
1403
+ * ```typescript
1404
+ * intersection(
1405
+ * [1, 2, 3],
1406
+ * [2, 3, 4],
1407
+ * ); // => [2, 3]
1408
+ * ```
780
1409
  */
781
1410
  declare function intersection<First, Second>(first: First[], second: Second[]): First[];
782
1411
  //#endregion
783
1412
  //#region src/array/partition.d.ts
784
1413
  /**
785
1414
  * Get a partitioned array of items
1415
+ *
786
1416
  * @param array Array to search in
787
1417
  * @param callback Callback to get an item's value for matching
788
1418
  * @param value Value to match against
789
1419
  * @returns Partitioned array of items
1420
+ *
1421
+ * @example
1422
+ * ```typescript
1423
+ * partition(
1424
+ * [{id: 1}, {id: 2}, {id: 3}],
1425
+ * item => item.id,
1426
+ * 2,
1427
+ * ); // => [[{id: 2}], [{id: 1}, {id: 3}]]
1428
+ * ```
790
1429
  */
791
1430
  declare function partition<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[][];
792
1431
  /**
793
1432
  * Get a partitioned array of items
1433
+ *
794
1434
  * @param array Array to search in
795
1435
  * @param key Key to get an item's value for matching
796
1436
  * @param value Value to match against
797
1437
  * @returns Partitioned array of items
1438
+ *
1439
+ * @example
1440
+ * ```typescript
1441
+ * partition(
1442
+ * [{id: 1}, {id: 2}, {id: 3}],
1443
+ * 'id',
1444
+ * 2,
1445
+ * ); // => [[{id: 2}], [{id: 1}, {id: 3}]]
1446
+ * ```
798
1447
  */
799
1448
  declare function partition<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[][];
800
1449
  /**
801
1450
  * Get a partitioned array of items
1451
+ *
802
1452
  * @param array Array to search in
803
1453
  * @param filter Filter callback to match items
804
1454
  * @returns Partitioned array of items
1455
+ *
1456
+ * @example
1457
+ * ```typescript
1458
+ * partition(
1459
+ * [{id: 1}, {id: 2}, {id: 3}],
1460
+ * item => item.id === 2,
1461
+ * ); // => [[{id: 2}], [{id: 1}, {id: 3}]]
1462
+ * ```
805
1463
  */
806
1464
  declare function partition<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item[][];
807
1465
  /**
808
1466
  * Get a partitioned array of items matching the given item
1467
+ *
809
1468
  * @param array Array to search in
810
1469
  * @param item Item to match against
811
1470
  * @returns Partitioned array of items
1471
+ *
1472
+ * @example
1473
+ * ```typescript
1474
+ * partition([1, 2, 3, 4, 5], 3); // => [[3], [1, 2, 4, 5]]
1475
+ * ```
812
1476
  */
813
1477
  declare function partition<Item>(array: Item[], item: Item): Item[][];
814
1478
  //#endregion
@@ -821,130 +1485,268 @@ type ArrayComparison = 'end' | 'inside' | 'invalid' | 'outside' | 'same' | 'star
821
1485
  * Does the needle array end the haystack array?
822
1486
  * @param haystack Haystack array
823
1487
  * @param needle Needle array
824
- * @param key Key to get an item's value for matching
825
- * @return `true` if the haystack ends with the needle, otherwise `false`
1488
+ * @param callback Callback to get an item's value for matching
1489
+ * @returns `true` if the haystack ends with the needle, otherwise `false`
1490
+ *
1491
+ * @example
1492
+ * ```typescript
1493
+ * endsWithArray(
1494
+ * [{id: 1}, {id: 2}, {id: 3}],
1495
+ * [{id: 2}, {id: 3}],
1496
+ * item => item.id,
1497
+ * ); // => true
1498
+ * ```
826
1499
  */
827
- declare function endsWithArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): boolean;
1500
+ declare function endsWithArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean;
828
1501
  /**
829
1502
  * Does the needle array end the haystack array?
1503
+ *
830
1504
  * @param haystack Haystack array
831
1505
  * @param needle Needle array
832
- * @param callback Callback to get an item's value for matching
833
- * @return `true` if the haystack ends with the needle, otherwise `false`
1506
+ * @param key Key to get an item's value for matching
1507
+ * @returns `true` if the haystack ends with the needle, otherwise `false`
1508
+ *
1509
+ * @example
1510
+ * ```typescript
1511
+ * endsWithArray(
1512
+ * [{id: 1}, {id: 2}, {id: 3}],
1513
+ * [{id: 2}, {id: 3}],
1514
+ * 'id',
1515
+ * ); // => true
1516
+ * ```
834
1517
  */
835
- declare function endsWithArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean;
1518
+ declare function endsWithArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): boolean;
836
1519
  /**
837
1520
  * Does the needle array end the haystack array?
1521
+ *
838
1522
  * @param haystack Haystack array
839
1523
  * @param needle Needle array
840
- * @return `true` if the haystack ends with the needle, otherwise `false`
1524
+ * @returns `true` if the haystack ends with the needle, otherwise `false`
1525
+ *
1526
+ * @example
1527
+ * ```typescript
1528
+ * endsWithArray([1, 2, 3], [2, 3]); // => true
1529
+ * ```
841
1530
  */
842
1531
  declare function endsWithArray<Item>(haystack: Item[], needle: Item[]): boolean;
843
1532
  /**
844
1533
  * Get the position of an array within another array
1534
+ *
845
1535
  * @param haystack Haystack array
846
1536
  * @param needle Needle array
847
- * @param key Key to get an item's value for matching
1537
+ * @param callback Callback to get an item's value for matching
848
1538
  * @returns Position of the needle within the haystack
1539
+ *
1540
+ * @example
1541
+ * ```typescript
1542
+ * getArrayComparison(
1543
+ * [{id: 1}, {id: 2}, {id: 3}],
1544
+ * [{id: 2}, {id: 3}],
1545
+ * item => item.id,
1546
+ * ); // => 'end'
1547
+ * ```
849
1548
  */
850
- declare function getArrayComparison<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): ArrayComparison;
1549
+ declare function getArrayComparison<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): ArrayComparison;
851
1550
  /**
852
1551
  * Get the position of an array within another array
1552
+ *
853
1553
  * @param haystack Haystack array
854
1554
  * @param needle Needle array
855
- * @param callback Callback to get an item's value for matching
1555
+ * @param key Key to get an item's value for matching
856
1556
  * @returns Position of the needle within the haystack
1557
+ *
1558
+ * @example
1559
+ * ```typescript
1560
+ * getArrayComparison(
1561
+ * [{id: 1}, {id: 2}, {id: 3}],
1562
+ * [{id: 2}, {id: 3}],
1563
+ * 'id',
1564
+ * ); // => 'end'
1565
+ * ```
857
1566
  */
858
- declare function getArrayComparison<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): ArrayComparison;
1567
+ declare function getArrayComparison<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): ArrayComparison;
859
1568
  /**
860
1569
  * Get the position of an array within another array
1570
+ *
861
1571
  * @param haystack Haystack array
862
1572
  * @param needle Needle array
863
1573
  * @returns Position of the needle within the haystack
1574
+ *
1575
+ * @example
1576
+ * ```typescript
1577
+ * getArrayComparison([1, 2, 3], [2, 3]); // => 'end'
1578
+ * ```
864
1579
  */
865
1580
  declare function getArrayComparison<Item>(haystack: Item[], needle: Item[]): ArrayComparison;
866
1581
  /**
867
1582
  * Does the needle array exist within the haystack array?
1583
+ *
868
1584
  * @param haystack Haystack array
869
1585
  * @param needle Needle array
870
- * @param key Key to get an item's value for matching
871
- * @return `true` if the haystack includes the needle, otherwise `false`
1586
+ * @param callback Callback to get an item's value for matching
1587
+ * @returns `true` if the haystack includes the needle, otherwise `false`
1588
+ *
1589
+ * @example
1590
+ * ```typescript
1591
+ * includesArray(
1592
+ * [{id: 1}, {id: 2}, {id: 3}],
1593
+ * [{id: 2}, {id: 3}],
1594
+ * item => item.id,
1595
+ * ); // => true
1596
+ * ```
872
1597
  */
873
- declare function includesArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): boolean;
1598
+ declare function includesArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean;
874
1599
  /**
875
1600
  * Does the needle array exist within the haystack array?
1601
+ *
876
1602
  * @param haystack Haystack array
877
1603
  * @param needle Needle array
878
- * @param callback Callback to get an item's value for matching
879
- * @return `true` if the haystack includes the needle, otherwise `false`
1604
+ * @param key Key to get an item's value for matching
1605
+ * @returns `true` if the haystack includes the needle, otherwise `false`
1606
+ *
1607
+ * @example
1608
+ * ```typescript
1609
+ * includesArray(
1610
+ * [{id: 1}, {id: 2}, {id: 3}],
1611
+ * [{id: 2}, {id: 3}],
1612
+ * 'id',
1613
+ * ); // => true
1614
+ * ```
880
1615
  */
881
- declare function includesArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean;
1616
+ declare function includesArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): boolean;
882
1617
  /**
883
1618
  * Does the needle array exist within the haystack array?
1619
+ *
884
1620
  * @param haystack Haystack array
885
1621
  * @param needle Needle array
886
- * @return `true` if the haystack includes the needle, otherwise `false`
1622
+ * @returns `true` if the haystack includes the needle, otherwise `false`
1623
+ *
1624
+ * @example
1625
+ * ```typescript
1626
+ * includesArray([1, 2, 3], [2, 3]); // => true
1627
+ * ```
887
1628
  */
888
1629
  declare function includesArray<Item>(haystack: Item[], needle: Item[]): boolean;
889
1630
  /**
890
1631
  * Get the index of an array within another array
1632
+ *
891
1633
  * @param haystack Haystack array
892
1634
  * @param needle Needle array
893
- * @param key Key to get an item's value for matching
894
- * @return Index of the needle's start within the haystack, or `-1` if it is not found
1635
+ * @param callback Callback to get an item's value for matching
1636
+ * @returns Index of the needle's start within the haystack, or `-1` if it is not found
1637
+ *
1638
+ * @example
1639
+ * ```typescript
1640
+ * indexOfArray(
1641
+ * [{id: 1}, {id: 2}, {id: 3}],
1642
+ * [{id: 2}, {id: 3}],
1643
+ * item => item.id,
1644
+ * ); // => 1
1645
+ * ```
895
1646
  */
896
- declare function indexOfArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): number;
1647
+ declare function indexOfArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): number;
897
1648
  /**
898
1649
  * Get the index of an array within another array
1650
+ *
899
1651
  * @param haystack Haystack array
900
1652
  * @param needle Needle array
901
- * @param callback Callback to get an item's value for matching
902
- * @return Index of the needle's start within the haystack, or `-1` if it is not found
1653
+ * @param key Key to get an item's value for matching
1654
+ * @returns Index of the needle's start within the haystack, or `-1` if it is not found
1655
+ *
1656
+ * @example
1657
+ * ```typescript
1658
+ * indexOfArray(
1659
+ * [{id: 1}, {id: 2}, {id: 3}],
1660
+ * [{id: 2}, {id: 3}],
1661
+ * 'id',
1662
+ * ); // => 1
1663
+ * ```
903
1664
  */
904
- declare function indexOfArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): number;
1665
+ declare function indexOfArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): number;
905
1666
  /**
906
1667
  * Get the index of an array within another array
1668
+ *
907
1669
  * @param haystack Haystack array
908
1670
  * @param needle Needle array
909
- * @return Index of the needle's start within the haystack, or `-1` if it is not found
1671
+ * @returns Index of the needle's start within the haystack, or `-1` if it is not found
1672
+ *
1673
+ * @example
1674
+ * ```typescript
1675
+ * indexOfArray([1, 2, 3], [2, 3]); // => 1
1676
+ * ```
910
1677
  */
911
1678
  declare function indexOfArray<Item>(haystack: Item[], needle: Item[]): number;
912
1679
  /**
913
1680
  * Does the needle array start the haystack array?
1681
+ *
914
1682
  * @param haystack Haystack array
915
1683
  * @param needle Needle array
916
- * @param key Key to get an item's value for matching
917
- * @return `true` if the haystack starts with the needle, otherwise `false`
1684
+ * @param callback Callback to get an item's value for matching
1685
+ * @returns `true` if the haystack starts with the needle, otherwise `false`
1686
+ *
1687
+ * @example
1688
+ * ```typescript
1689
+ * startsWithArray(
1690
+ * [{id: 1}, {id: 2}, {id: 3}],
1691
+ * [{id: 1}, {id: 2}],
1692
+ * item => item.id,
1693
+ * ); // => true
1694
+ * ```
918
1695
  */
919
- declare function startsWithArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): boolean;
1696
+ declare function startsWithArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean;
920
1697
  /**
921
1698
  * Does the needle array start the haystack array?
1699
+ *
922
1700
  * @param haystack Haystack array
923
1701
  * @param needle Needle array
924
- * @param callback Callback to get an item's value for matching
925
- * @return `true` if the haystack starts with the needle, otherwise `false`
1702
+ * @param key Key to get an item's value for matching
1703
+ * @returns `true` if the haystack starts with the needle, otherwise `false`
1704
+ *
1705
+ * @example
1706
+ * ```typescript
1707
+ * startsWithArray(
1708
+ * [{id: 1}, {id: 2}, {id: 3}],
1709
+ * [{id: 1}, {id: 2}],
1710
+ * 'id',
1711
+ * ); // => true
1712
+ * ```
926
1713
  */
927
- declare function startsWithArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean;
1714
+ declare function startsWithArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): boolean;
928
1715
  /**
929
1716
  * Does the needle array start the haystack array?
1717
+ *
930
1718
  * @param haystack Haystack array
931
1719
  * @param needle Needle array
932
- * @return `true` if the haystack starts with the needle, otherwise `false`
1720
+ * @returns `true` if the haystack starts with the needle, otherwise `false`
1721
+ *
1722
+ * @example
1723
+ * ```typescript
1724
+ * startsWithArray([1, 2, 3], [1, 2]); // => true
1725
+ * ```
933
1726
  */
934
1727
  declare function startsWithArray<Item>(haystack: Item[], needle: Item[]): boolean;
935
1728
  //#endregion
936
1729
  //#region src/array/push.d.ts
937
1730
  /**
938
1731
  * Push items into an array _(at the end)_
1732
+ *
1733
+ * _(Uses chunking to avoid call stack size being exceeded)_
1734
+ *
939
1735
  * @param array Original array
940
1736
  * @param pushed Pushed items
941
1737
  * @returns New length of the array
1738
+ *
1739
+ * @example
1740
+ * ```typescript
1741
+ * push([1, 2, 3], [4, 5]); // => 5 (new length); array becomes [1, 2, 3, 4, 5]
1742
+ * ```
942
1743
  */
943
1744
  declare function push<Item>(array: Item[], pushed: Item[]): number;
944
1745
  //#endregion
945
1746
  //#region src/array/reverse.d.ts
946
1747
  /**
947
1748
  * Reverse the order of items in an array
1749
+ *
948
1750
  * @param array Array to reverse
949
1751
  * @returns Reversed array
950
1752
  */
@@ -953,46 +1755,100 @@ declare function reverse<Item>(array: Item[]): Item[];
953
1755
  //#region src/array/select.d.ts
954
1756
  /**
955
1757
  * Get a filtered and mapped array of items
1758
+ *
956
1759
  * @param array Array to search in
957
1760
  * @param filterCallback Callback to get an item's value for matching
958
1761
  * @param filterValue Value to match against
959
1762
  * @param mapCallback Callback to map the matched items
960
1763
  * @returns Filtered and mapped array of items
1764
+ *
1765
+ * @example
1766
+ * ```typescript
1767
+ * select(
1768
+ * [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
1769
+ * item => item.id,
1770
+ * 2,
1771
+ * item => item.name,
1772
+ * ); // => ['Bob']
1773
+ * ```
961
1774
  */
962
1775
  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
1776
  /**
964
1777
  * Get a filtered and mapped array of items
1778
+ *
965
1779
  * @param array Array to search in
966
1780
  * @param filterCallback Callback to get an item's value for matching
967
1781
  * @param filterValue Value to match against
968
1782
  * @param mapKey Key to get an item's value for mapping
969
1783
  * @returns Filtered and mapped array of items
1784
+ *
1785
+ * @example
1786
+ * ```typescript
1787
+ * select(
1788
+ * [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
1789
+ * item => item.id,
1790
+ * 2,
1791
+ * 'name',
1792
+ * ); // => ['Bob']
1793
+ * ```
970
1794
  */
971
1795
  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
1796
  /**
973
1797
  * Get a filtered and mapped array of items
1798
+ *
974
1799
  * @param array Array to search in
975
1800
  * @param filterKey Key to get an item's value for matching
976
1801
  * @param filterValue Value to match against
977
1802
  * @param mapCallback Callback to map the matched items
978
1803
  * @returns Filtered and mapped array of items
1804
+ *
1805
+ * @example
1806
+ * ```typescript
1807
+ * select(
1808
+ * [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
1809
+ * 'id',
1810
+ * 2,
1811
+ * item => item.name,
1812
+ * ); // => ['Bob']
1813
+ * ```
979
1814
  */
980
1815
  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
1816
  /**
982
1817
  * Get a filtered and mapped array of items
1818
+ *
983
1819
  * @param array Array to search in
984
1820
  * @param filterKey Key to get an item's value for matching
985
1821
  * @param filterValue Value to match against
986
1822
  * @param mapKey Key to get an item's value for mapping
987
1823
  * @returns Filtered and mapped array of items
1824
+ *
1825
+ * @example
1826
+ * ```typescript
1827
+ * select(
1828
+ * [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
1829
+ * 'id',
1830
+ * 2,
1831
+ * 'name',
1832
+ * ); // => ['Bob']
1833
+ * ```
988
1834
  */
989
1835
  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
1836
  /**
991
1837
  * Get a filtered and mapped array of items
1838
+ *
992
1839
  * @param array Array to search in
993
1840
  * @param filterCallback Filter callback to match items
994
1841
  * @param mapCallback Callback to map the matched items
995
1842
  * @returns Filtered and mapped array of items
1843
+ *
1844
+ * @example
1845
+ * ```typescript
1846
+ * select(
1847
+ * [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
1848
+ * item => item.id === 2,
1849
+ * item => item.name,
1850
+ * ); // => ['Bob']
1851
+ * ```
996
1852
  */
997
1853
  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
1854
  /**
@@ -1001,336 +1857,717 @@ declare function select<Item, FilterCallback extends (item: Item, index: number,
1001
1857
  * @param filterCallback Filter callback to match items
1002
1858
  * @param mapKey Key to get an item's value for mapping
1003
1859
  * @returns Filtered and mapped array of items
1860
+ *
1861
+ * @example
1862
+ * ```typescript
1863
+ * select(
1864
+ * [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
1865
+ * item => item.id,
1866
+ * 2,
1867
+ * 'name'
1868
+ * ); // => ['Bob']
1869
+ * ```
1004
1870
  */
1005
1871
  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
1872
  /**
1007
1873
  * Get a filtered and mapped array of items
1874
+ *
1008
1875
  * @param array Array to search in
1009
1876
  * @param filter Filter callback to match items
1010
1877
  * @param map Callback to map the matched items
1011
1878
  * @returns Filtered and mapped array of items
1879
+ *
1880
+ * @example
1881
+ * ```typescript
1882
+ * select(
1883
+ * [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
1884
+ * item => item.id === 2,
1885
+ * item => item.name,
1886
+ * ); // => ['Bob']
1887
+ * ```
1012
1888
  */
1013
1889
  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
1890
  /**
1015
1891
  * Get a filtered and mapped array of items
1892
+ *
1016
1893
  * @param array Array to search in
1017
1894
  * @param filter Filter callback to match items
1018
1895
  * @param map Key to get an item's value for mapping
1019
1896
  * @returns Filtered and mapped array of items
1897
+ *
1898
+ * @example
1899
+ * ```typescript
1900
+ * select(
1901
+ * [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
1902
+ * item => item.id === 2,
1903
+ * 'name'
1904
+ * ); // => ['Bob']
1905
+ * ```
1020
1906
  */
1021
1907
  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
1908
  /**
1023
1909
  * Get a filtered and mapped array of items
1910
+ *
1024
1911
  * @param array Array to search in
1025
1912
  * @param item Item to match against
1026
1913
  * @param map Callback to map the matched items
1027
1914
  * @returns Filtered and mapped array of items
1915
+ *
1916
+ * @example
1917
+ * ```typescript
1918
+ * select(
1919
+ * [1, 2, 3, 2, 1],
1920
+ * 3,
1921
+ * value => value ** 2,
1922
+ * ); // => [9]
1923
+ * ```
1028
1924
  */
1029
1925
  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
1926
  //#endregion
1039
1927
  //#region src/array/single.d.ts
1040
1928
  /**
1041
1929
  * Get the _only_ item matching the given value
1042
1930
  *
1043
1931
  * Throws an error if multiple items match the value
1932
+ *
1044
1933
  * @param array Array to search in
1045
1934
  * @param callback Callback to get an item's value for matching
1046
1935
  * @param value Value to match against
1047
1936
  * @returns Only item that matches the value, or `undefined` if no match is found
1937
+ *
1938
+ * @example
1939
+ * ```typescript
1940
+ * single(
1941
+ * [{id: 1}, {id: 2}, {id: 3}],
1942
+ * item => item.id,
1943
+ * 2
1944
+ * ); // => {id: 2}
1945
+ * ```
1048
1946
  */
1049
1947
  declare function single<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item | undefined;
1050
1948
  /**
1051
1949
  * Get the _only_ item matching the given value by key
1052
1950
  *
1053
1951
  * Throws an error if multiple items match the value
1952
+ *
1054
1953
  * @param array Array to search in
1055
1954
  * @param key Key to get an item's value for matching
1056
1955
  * @param value Value to match against
1057
1956
  * @returns Only item that matches the value, or `undefined` if no match is found
1957
+ *
1958
+ * @example
1959
+ * ```typescript
1960
+ * single(
1961
+ * [{id: 1}, {id: 2}, {id: 3}],
1962
+ * 'id',
1963
+ * 2
1964
+ * ); // => {id: 2}
1965
+ * ```
1058
1966
  */
1059
1967
  declare function single<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
1060
1968
  /**
1061
1969
  * Get the _only_ item matching the filter
1062
1970
  *
1063
1971
  * Throws an error if multiple items match the filter
1972
+ *
1064
1973
  * @param array Array to search in
1065
1974
  * @param filter Filter callback to match items
1066
1975
  * @returns Only item that matches the filter, or `undefined` if no match is found
1976
+ *
1977
+ * @example
1978
+ * ```typescript
1979
+ * single(
1980
+ * [{id: 1}, {id: 2}, {id: 3}],
1981
+ * item => item.id === 2
1982
+ * ); // => {id: 2}
1983
+ * ```
1067
1984
  */
1068
1985
  declare function single<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item | undefined;
1069
1986
  //#endregion
1070
1987
  //#region src/array/slice.d.ts
1071
1988
  /**
1072
1989
  * Drop items from the start of an array until they match a value
1990
+ *
1073
1991
  * @param array Original array
1074
- * @param key Key to get an item's value for matching
1992
+ * @param callback Callback to get an item's value for matching
1075
1993
  * @param value Value to match against
1076
1994
  * @returns New array with items dropped
1995
+ *
1996
+ * @example
1997
+ * ```typescript
1998
+ * drop(
1999
+ * [{id: 1}, {id: 2}, {id: 3}],
2000
+ * item => item.id,
2001
+ * 2,
2002
+ * ); // => [{id: 2}, {id: 3}]
2003
+ * ```
1077
2004
  */
1078
- declare function drop<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[];
2005
+ declare function drop<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[];
1079
2006
  /**
1080
2007
  * Drop items from the start of an array until they match a value
2008
+ *
1081
2009
  * @param array Original array
1082
- * @param callback Callback to get an item's value for matching
2010
+ * @param key Key to get an item's value for matching
1083
2011
  * @param value Value to match against
1084
- * @return New array with items dropped
2012
+ * @returns New array with items dropped
2013
+ *
2014
+ * @example
2015
+ * ```typescript
2016
+ * drop(
2017
+ * [{id: 1}, {id: 2}, {id: 3}],
2018
+ * 'id',
2019
+ * 2,
2020
+ * ); // => [{id: 2}, {id: 3}]
2021
+ * ```
1085
2022
  */
1086
- declare function drop<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[];
2023
+ declare function drop<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[];
1087
2024
  /**
1088
2025
  * Drop items from the start of an array while they match a filter
2026
+ *
1089
2027
  * @param array Original array
1090
2028
  * @param callback Filter callback to match items
1091
- * @return New array with items dropped
2029
+ * @returns New array with items dropped
2030
+ *
2031
+ * @example
2032
+ * ```typescript
2033
+ * drop(
2034
+ * [{id: 1}, {id: 2}, {id: 3}],
2035
+ * item => item.id === 2,
2036
+ * ); // => [{id: 2}, {id: 3}]
2037
+ * ```
1092
2038
  */
1093
2039
  declare function drop<Item extends PlainObject>(array: Item[], callback: (item: Item, index: number, array: Item[]) => boolean): Item[];
1094
2040
  /**
1095
2041
  * Drop a specified number of items, from the start if `>= 0`, or from the end if `< 0`
2042
+ *
1096
2043
  * @param array Original array
1097
2044
  * @param count Number of items to drop
1098
2045
  * @returns New array with items dropped
2046
+ *
2047
+ * @example
2048
+ * ```typescript
2049
+ * drop([1, 2, 3, 4, 5], 2); // => [3, 4, 5]
2050
+ * drop([1, 2, 3, 4, 5], -2); // => [1, 2, 3]
2051
+ * ```
1099
2052
  */
1100
2053
  declare function drop(array: unknown[], count: number): unknown[];
1101
2054
  /**
1102
2055
  * Slice an array, returning a new array with a specified range of items
2056
+ *
1103
2057
  * @param array Original array
1104
2058
  * @param start Start index _(inclusive)_
1105
2059
  * @param end End index _(exclusive)_
1106
- * @return New array with sliced items
2060
+ * @returns New array with sliced items
2061
+ *
2062
+ * @example
2063
+ * ```typescript
2064
+ * slice([1, 2, 3, 4, 5], 1, 4); // => [2, 3, 4]
2065
+ * ```
1107
2066
  */
1108
2067
  declare function slice<Item>(array: Item[], start: number, end: number): Item[];
1109
2068
  /**
1110
- * Slice an array, returning a new array with a specified number of items
2069
+ * Slice an array, returning a new array with a specified number of items _(from the start)_
2070
+ *
1111
2071
  * @param array Original array
1112
- * @param count Maximum sixe of the new array
1113
- * @return New array with sliced items
2072
+ * @param count Maximum size of the new array
2073
+ * @returns New array with sliced items
2074
+ *
2075
+ * @example
2076
+ * ```typescript
2077
+ * slice([1, 2, 3, 4, 5], 3); // => [1, 2, 3]
2078
+ * ```
1114
2079
  */
1115
2080
  declare function slice<Item>(array: Item[], count: number): Item[];
1116
2081
  /**
1117
2082
  * Slice an array
2083
+ *
1118
2084
  * @param array Array to slice
1119
2085
  * @returns Sliced array
2086
+ *
2087
+ * @example
2088
+ * ```typescript
2089
+ * slice([1, 2, 3]); // => [1, 2, 3]
2090
+ * ```
1120
2091
  */
1121
2092
  declare function slice<Item>(array: Item[]): Item[];
1122
2093
  /**
1123
2094
  * Take items from the start of an array until they match a value
2095
+ *
1124
2096
  * @param array Original array
1125
- * @param key Key to get an item's value for matching
2097
+ * @param callback Callback to get an item's value for matching
1126
2098
  * @param value Value to match against
1127
2099
  * @returns New array with taken items
2100
+ *
2101
+ * @example
2102
+ * ```typescript
2103
+ * take(
2104
+ * [{id: 1}, {id: 2}, {id: 3}],
2105
+ * item => item.id,
2106
+ * 2,
2107
+ * ); // => [{id: 1}]
2108
+ * ```
1128
2109
  */
1129
- declare function take<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[];
2110
+ declare function take<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[];
1130
2111
  /**
1131
2112
  * Take items from the start of an array until they match a value
2113
+ *
1132
2114
  * @param array Original array
1133
- * @param callback Callback to get an item's value for matching
2115
+ * @param key Key to get an item's value for matching
1134
2116
  * @param value Value to match against
1135
- * @return New array with taken items
2117
+ * @returns New array with taken items
2118
+ *
2119
+ * @example
2120
+ * ```typescript
2121
+ * take(
2122
+ * [{id: 1}, {id: 2}, {id: 3}],
2123
+ * 'id',
2124
+ * 2,
2125
+ * ); // => [{id: 1}]
2126
+ * ```
1136
2127
  */
1137
- declare function take<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[];
2128
+ declare function take<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[];
1138
2129
  /**
1139
2130
  * Take items from the start of an array while they match a filter
2131
+ *
1140
2132
  * @param array Original array
1141
2133
  * @param callback Filter callback to match items
1142
- * @return New array with taken items
2134
+ * @returns New array with taken items
2135
+ *
2136
+ * @example
2137
+ * ```typescript
2138
+ * take(
2139
+ * [{id: 1}, {id: 2}, {id: 3}],
2140
+ * item => item.id === 2,
2141
+ * ); // => [{id: 1}]
2142
+ * ```
1143
2143
  */
1144
2144
  declare function take<Item extends PlainObject>(array: Item[], callback: (item: Item, index: number, array: Item[]) => boolean): Item[];
1145
2145
  /**
1146
2146
  * Take a specified number of items, from the start if `>= 0`, or from the end if `< 0`
2147
+ *
1147
2148
  * @param array Original array
1148
2149
  * @param count Number of items to take
1149
2150
  * @returns New array with taken items
2151
+ *
2152
+ * @example
2153
+ * ```typescript
2154
+ * take([1, 2, 3, 4, 5], 2); // => [1, 2]
2155
+ * take([1, 2, 3, 4, 5], -2); // => [4, 5]
2156
+ * ```
1150
2157
  */
1151
2158
  declare function take(array: unknown[], count: number): unknown[];
1152
2159
  //#endregion
1153
2160
  //#region src/array/splice.d.ts
1154
2161
  /**
1155
2162
  * Adds items into an array at a specific index and removes a specific amount of items
2163
+ *
2164
+ * _(Uses chunking to avoid call stack size being exceeded)_
2165
+ *
1156
2166
  * @param array Original array
1157
2167
  * @param start Index to start splicing from
1158
2168
  * @param amount Number of items to remove
1159
2169
  * @param added Added items
1160
2170
  * @returns Removed items
2171
+ *
2172
+ * @example
2173
+ * ```typescript
2174
+ * splice(
2175
+ * [1, 2, 3, 4, 5],
2176
+ * 2,
2177
+ * 2,
2178
+ * [6, 7]
2179
+ * ); // => [3, 4], array becomes [1, 2, 6, 7, 5]
2180
+ * ```
1161
2181
  */
1162
2182
  declare function splice<Item>(array: Item[], start: number, amount: number, added: Item[]): Item[];
1163
2183
  /**
1164
2184
  * Adds items into an array at a specific index
2185
+ *
2186
+ * _(Uses chunking to avoid call stack size being exceeded)_
2187
+ *
1165
2188
  * @param array Original array
1166
2189
  * @param start Index to start splicing from
1167
2190
  * @param added Added items
1168
2191
  * @returns Removed items
2192
+ *
2193
+ * @example
2194
+ * ```typescript
2195
+ * splice(
2196
+ * [1, 2, 3, 4, 5],
2197
+ * 2,
2198
+ * [6, 7]
2199
+ * ); // => [], array becomes [1, 2, 6, 7, 3, 4, 5]
2200
+ * ```
1169
2201
  */
1170
2202
  declare function splice<Item>(array: Item[], start: number, added: Item[]): Item[];
1171
2203
  /**
1172
2204
  * Removes and returns _(up to)_ a specific amount of items from an array, starting from a specific index
2205
+ *
2206
+ * _(Uses chunking to avoid call stack size being exceeded)_
2207
+ *
1173
2208
  * @param array Original array
1174
2209
  * @param start Index to start splicing from
1175
2210
  * @param amount Number of items to remove
1176
2211
  * @returns Removed items
2212
+ *
2213
+ * @example
2214
+ * ```typescript
2215
+ * splice(
2216
+ * [1, 2, 3, 4, 5],
2217
+ * 2,
2218
+ * 2,
2219
+ * ); // => [3, 4], array becomes [1, 2, 5]
2220
+ * ```
1177
2221
  */
1178
2222
  declare function splice<Item>(array: Item[], start: number, amount: number): Item[];
1179
2223
  /**
1180
2224
  * Removes and returns all items from an array starting from a specific index
2225
+ *
2226
+ * _(Uses chunking to avoid call stack size being exceeded)_
2227
+ *
1181
2228
  * @param array Original array
1182
2229
  * @param start Index to start splicing from
1183
2230
  * @returns Removed items
2231
+ *
2232
+ * @example
2233
+ * ```typescript
2234
+ * splice(
2235
+ * [1, 2, 3, 4, 5],
2236
+ * 2,
2237
+ * ); // => [3, 4, 5], array becomes [1, 2]
2238
+ * ```
1184
2239
  */
1185
2240
  declare function splice<Item>(array: Item[], start: number): Item[];
1186
2241
  //#endregion
1187
2242
  //#region src/array/to-set.d.ts
1188
2243
  /**
1189
2244
  * Create a Set from an array of items using a callback
2245
+ *
1190
2246
  * @param array Array to convert
1191
2247
  * @param callback Callback to get an item's value
1192
2248
  * @returns Set of values
2249
+ *
2250
+ * @example
2251
+ * ```typescript
2252
+ * toSet(
2253
+ * [{id: 1}, {id: 2}, {id: 3}],
2254
+ * item => item.id,
2255
+ * ); // => Set { 1, 2, 3 }
2256
+ * ```
1193
2257
  */
1194
2258
  declare function toSet<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback): Set<ReturnType<Callback>>;
1195
2259
  /**
1196
2260
  * Create a Set from an array of items using a key
2261
+ *
1197
2262
  * @param array Array to convert
1198
2263
  * @param key Key to use for value
1199
2264
  * @returns Set of values
2265
+ *
2266
+ * @example
2267
+ * ```typescript
2268
+ * toSet(
2269
+ * [{id: 1}, {id: 2}, {id: 3}],
2270
+ * 'id',
2271
+ * ); // => Set { 1, 2, 3 }
2272
+ * ```
1200
2273
  */
1201
2274
  declare function toSet<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Set<Item[ItemKey]>;
1202
2275
  /**
1203
2276
  * Create a Set from an array of items
2277
+ *
1204
2278
  * @param array Array to convert
1205
2279
  * @returns Set of items
2280
+ *
2281
+ * @example
2282
+ * ```typescript
2283
+ * toSet([1, 2, 3]); // => Set { 1, 2, 3 }
2284
+ * ```
1206
2285
  */
1207
2286
  declare function toSet<Item>(array: Item[]): Set<Item>;
1208
2287
  //#endregion
1209
2288
  //#region src/array/toggle.d.ts
1210
2289
  /**
1211
- * Toggle an item in an array: if the item exists, it will be removed; if it doesn't, it will be added
2290
+ * Toggle an item in an array
2291
+ *
2292
+ * If the item exists, it will be removed; if it doesn't, it will be added
2293
+ *
1212
2294
  * @param destination Array to toggle within
1213
2295
  * @param toggled Toggled items
1214
2296
  * @param callback Callback to find existing item
1215
2297
  * @returns Original array
2298
+ *
2299
+ * @example
2300
+ * ```typescript
2301
+ * toggle(
2302
+ * [{id: 1}, {id: 2}, {id: 3}],
2303
+ * [{id: 2}, {id: 4}],
2304
+ * item => item.id,
2305
+ * ); // => [{id: 1}, {id: 3}, {id: 4}]
2306
+ * ```
1216
2307
  */
1217
2308
  declare function toggle<Item>(destination: Item[], toggled: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
1218
2309
  /**
1219
- * Toggle an item in an array: if the item exists, it will be removed; if it doesn't, it will be added
2310
+ * Toggle an item in an array
2311
+ *
2312
+ * If the item exists, it will be removed; if it doesn't, it will be added
2313
+ *
1220
2314
  * @param destination Array to toggle within
1221
2315
  * @param toggled Toggled items
1222
2316
  * @param key Key to find existing item
1223
2317
  * @returns Original array
2318
+ *
2319
+ * @example
2320
+ * ```typescript
2321
+ * toggle(
2322
+ * [{id: 1}, {id: 2}, {id: 3}],
2323
+ * [{id: 2}, {id: 4}],
2324
+ * 'id',
2325
+ * ); // => [{id: 1}, {id: 3}, {id: 4}]
2326
+ * ```
1224
2327
  */
1225
2328
  declare function toggle<Item extends PlainObject, ItemKey extends keyof Item>(destination: Item[], toggled: Item[], key: ItemKey): Item[];
1226
2329
  /**
1227
- * Toggle an item in an array: if the item exists, it will be removed; if it doesn't, it will be added
2330
+ * Toggle an item in an array
2331
+ *
2332
+ * If the item exists, it will be removed; if it doesn't, it will be added
2333
+ *
1228
2334
  * @param destination Array to toggle within
1229
2335
  * @param toggled Toggled items
1230
2336
  * @returns Original array
2337
+ *
2338
+ * @example
2339
+ * ```typescript
2340
+ * toggle(
2341
+ * [1, 2, 3],
2342
+ * [2, 4],
2343
+ * ); // => [1, 3, 4]
2344
+ * ```
1231
2345
  */
1232
2346
  declare function toggle<Item>(destination: Item[], toggled: Item[]): Item[];
1233
2347
  //#endregion
1234
2348
  //#region src/array/union.d.ts
1235
2349
  /**
1236
2350
  * Get the combined, unique values from two arrays
2351
+ *
1237
2352
  * @param first First array
1238
2353
  * @param second Second array
1239
2354
  * @param callback Callback to get an item's value for comparison
1240
2355
  * @returns Combined, unique values from both arrays
2356
+ *
2357
+ * @example
2358
+ * ```typescript
2359
+ * union(
2360
+ * [{id: 1}, {id: 2}, {id: 3}],
2361
+ * [{id: 2}, {id: 4}],
2362
+ * item => item.id,
2363
+ * ); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}]
2364
+ * ```
1241
2365
  */
1242
2366
  declare function union<First, Second>(first: First[], second: Second[], callback: (item: First | Second) => unknown): (First | Second)[];
1243
2367
  /**
1244
2368
  * Get the combined, unique values from two arrays
2369
+ *
1245
2370
  * @param first First array
1246
2371
  * @param second Second array
1247
2372
  * @param key Key to get an item's value for comparison
1248
2373
  * @returns Combined, unique values from both arrays
2374
+ *
2375
+ * @example
2376
+ * ```typescript
2377
+ * union(
2378
+ * [{id: 1}, {id: 2}, {id: 3}],
2379
+ * [{id: 2}, {id: 4}],
2380
+ * 'id',
2381
+ * ); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}]
2382
+ * ```
1249
2383
  */
1250
2384
  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
2385
  /**
1252
2386
  * Get the combined, unique values from two arrays
2387
+ *
1253
2388
  * @param first First array
1254
2389
  * @param second Second array
1255
2390
  * @returns Combined, unique values from both arrays
2391
+ *
2392
+ * @example
2393
+ * ```typescript
2394
+ * union(
2395
+ * [1, 2, 3],
2396
+ * [2, 4],
2397
+ * ); // => [1, 2, 3, 4]
2398
+ * ```
1256
2399
  */
1257
2400
  declare function union<First, Second>(first: First[], second: Second[]): (First | Second)[];
1258
2401
  //#endregion
1259
2402
  //#region src/array/unique.d.ts
1260
2403
  /**
1261
2404
  * Get an array of unique items
2405
+ *
1262
2406
  * @param array Original array
1263
2407
  * @param callback Callback to get an item's value
1264
2408
  * @returns Array of unique items
2409
+ *
2410
+ * @example
2411
+ * ```typescript
2412
+ * unique(
2413
+ * [{id: 1}, {id: 2}, {id: 3}, {id: 2}],
2414
+ * item => item.id,
2415
+ * ); // => [{id: 1}, {id: 2}, {id: 3}]
2416
+ * ```
1265
2417
  */
1266
2418
  declare function unique<Item>(array: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
1267
2419
  /**
1268
2420
  * Get an array of unique items
2421
+ *
1269
2422
  * @param array Original array
1270
2423
  * @param key Key to use for unique value
1271
2424
  * @returns Array of unique items
2425
+ *
2426
+ * @example
2427
+ * ```typescript
2428
+ * unique(
2429
+ * [{id: 1}, {id: 2}, {id: 3}, {id: 2}],
2430
+ * 'id',
2431
+ * ); // => [{id: 1}, {id: 2}, {id: 3}]
2432
+ * ```
1272
2433
  */
1273
2434
  declare function unique<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Item[];
1274
2435
  /**
1275
2436
  * Get an array of unique items
2437
+ *
1276
2438
  * @param array Original array
1277
2439
  * @returns Array of unique items
2440
+ *
2441
+ * @example
2442
+ * ```typescript
2443
+ * unique([1, 2, 3, 2]); // => [1, 2, 3]
2444
+ * ```
1278
2445
  */
1279
2446
  declare function unique<Item>(array: Item[]): Item[];
1280
2447
  //#endregion
1281
2448
  //#region src/array/update.d.ts
1282
2449
  /**
1283
- * Update an item in an array: if the item exists, it will be updated; if it doesn't, it will be added
2450
+ * Update an item in an array
2451
+ *
2452
+ * If the item exists, it will be updated; if it doesn't, it will be added
2453
+ *
1284
2454
  * @param destination Array to update within
1285
2455
  * @param updated Updated items
1286
2456
  * @param callback Callback to find existing item
1287
2457
  * @returns Original array
2458
+ *
2459
+ * @example
2460
+ * ```typescript
2461
+ * update(
2462
+ * [{id: 1}, {id: 2}, {id: 3}],
2463
+ * [{id: 2, name: 'Updated'}, {id: 4, name: 'New'}],
2464
+ * item => item.id,
2465
+ * ); // => [{id: 1}, {id: 2, name: 'Updated'}, {id: 3}, {id: 4, name: 'New'}]
2466
+ * ```
1288
2467
  */
1289
2468
  declare function update<Item>(destination: Item[], updated: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
1290
2469
  /**
1291
- * Update an item in an array: if the item exists, it will be updated; if it doesn't, it will be added
2470
+ * Update an item in an array
2471
+ *
2472
+ * If the item exists, it will be updated; if it doesn't, it will be added
2473
+ *
1292
2474
  * @param destination Array to update within
1293
2475
  * @param updated Updated items
1294
2476
  * @param key Key to find existing item
1295
2477
  * @returns Original array
2478
+ *
2479
+ * @example
2480
+ * ```typescript
2481
+ * update(
2482
+ * [{id: 1}, {id: 2}, {id: 3}],
2483
+ * [{id: 2, name: 'Updated'}, {id: 4, name: 'New'}],
2484
+ * 'id',
2485
+ * ); // => [{id: 1}, {id: 2, name: 'Updated'}, {id: 3}, {id: 4, name: 'New'}]
2486
+ * ```
1296
2487
  */
1297
2488
  declare function update<Item extends PlainObject, ItemKey extends keyof Item>(destination: Item[], updated: Item[], key: ItemKey): Item[];
1298
2489
  /**
1299
- * Update an item in an array: if the item exists, it will be updated; if it doesn't, it will be added
2490
+ * Update an item in an array
2491
+ *
2492
+ * If the item exists, it will be updated; if it doesn't, it will be added
2493
+ *
1300
2494
  * @param destination Array to update within
1301
2495
  * @param updated Updated items
1302
2496
  * @returns Original array
2497
+ *
2498
+ * @example
2499
+ * ```typescript
2500
+ * update(
2501
+ * [1, 2, 3],
2502
+ * [2, 4],
2503
+ * ); // => [1, 2, 3, 4]
2504
+ * ```
1303
2505
  */
1304
2506
  declare function update<Item>(destination: Item[], updated: Item[]): Item[];
1305
2507
  //#endregion
1306
2508
  //#region src/array/last.d.ts
1307
2509
  /**
1308
2510
  * Get the last items matching the given value
2511
+ *
1309
2512
  * @param array Array to search in
1310
2513
  * @param callback Callback to get an item's value for matching
1311
2514
  * @param value Value to match against
1312
2515
  * @returns Last item that matches the value, or `undefined` if no match is found
2516
+ *
2517
+ * @example
2518
+ * ```typescript
2519
+ * last(
2520
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
2521
+ * item => item.value,
2522
+ * 10,
2523
+ * ); // => {id: 3, value: 10}
2524
+ * ```
1313
2525
  */
1314
2526
  declare function last<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item | undefined;
1315
2527
  /**
1316
2528
  * Get the first item matching the given value by key
2529
+ *
1317
2530
  * @param array Array to search in
1318
2531
  * @param key Key to get an item's value for matching
1319
2532
  * @param value Value to match against
1320
2533
  * @returns Last item that matches the value, or `undefined` if no match is found
2534
+ *
2535
+ * @example
2536
+ * ```typescript
2537
+ * last(
2538
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
2539
+ * 'value',
2540
+ * 10,
2541
+ * ); // => {id: 3, value: 10}
2542
+ * ```
1321
2543
  */
1322
2544
  declare function last<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
1323
2545
  /**
1324
2546
  * Get the last item matching the filter
2547
+ *
1325
2548
  * @param array Array to search in
1326
2549
  * @param filter Filter callback to match items
1327
2550
  * @returns Last item that matches the filter, or `undefined` if no match is found
2551
+ *
2552
+ * @example
2553
+ * ```typescript
2554
+ * last(
2555
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
2556
+ * item => item.value === 10,
2557
+ * ); // => {id: 3, value: 10}
2558
+ * ```
1328
2559
  */
1329
2560
  declare function last<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item | undefined;
1330
2561
  /**
1331
2562
  * Get the last item from an array
2563
+ *
1332
2564
  * @param array Array to get from
1333
- * @return Last item from the array, or `undefined` if the array is empty
2565
+ * @returns Last item from the array, or `undefined` if the array is empty
2566
+ *
2567
+ * @example
2568
+ * ```typescript
2569
+ * last([1, 2, 3]); // => 3
2570
+ * ```
1334
2571
  */
1335
2572
  declare function last<Item>(array: Item[]): Item | undefined;
1336
2573
  declare namespace last {
@@ -1341,41 +2578,79 @@ declare namespace last {
1341
2578
  * Get the last item matching the given value
1342
2579
  *
1343
2580
  * Available as `lastOrDefault` and `last.default`
2581
+ *
1344
2582
  * @param array Array to search in
1345
2583
  * @param defaultValue Default value to return if no match is found
1346
2584
  * @param callback Callback to get an item's value for matching
1347
2585
  * @param value Value to match against
1348
2586
  * @returns Last item that matches the value, or the default value if no match is found
2587
+ *
2588
+ * @example
2589
+ * ```typescript
2590
+ * lastOrDefault(
2591
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
2592
+ * {id: -1, value: 30},
2593
+ * item => item.value,
2594
+ * 30,
2595
+ * ); // => {id: -1, value: 30}
2596
+ * ```
1349
2597
  */
1350
2598
  declare function lastOrDefault<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], defaultValue: Item, callback: Callback, value: ReturnType<Callback>): Item;
1351
2599
  /**
1352
2600
  * Get the last item matching the given value by key
1353
2601
  *
1354
2602
  * Available as `lastOrDefault` and `last.default`
2603
+ *
1355
2604
  * @param array Array to search in
1356
2605
  * @param defaultValue Default value to return if no match is found
1357
2606
  * @param key Key to get an item's value for matching
1358
2607
  * @param value Value to match against
1359
2608
  * @returns Last item that matches the value, or the default value if no match is found
2609
+ *
2610
+ * @example
2611
+ * ```typescript
2612
+ * lastOrDefault(
2613
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
2614
+ * {id: -1, value: 30},
2615
+ * 'value',
2616
+ * 30,
2617
+ * ); // => {id: -1, value: 30}
2618
+ * ```
1360
2619
  */
1361
2620
  declare function lastOrDefault<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], defaultValue: Item, key: ItemKey, value: Item[ItemKey]): Item;
1362
2621
  /**
1363
2622
  * Get the last item matching the filter
1364
2623
  *
1365
2624
  * Available as `lastOrDefault` and `last.default`
2625
+ *
1366
2626
  * @param array Array to search in
1367
2627
  * @param defaultValue Default value to return if no match is found
1368
2628
  * @param filter Filter callback to match items
1369
2629
  * @returns Last item that matches the filter, or the default value if no match is found
2630
+ *
2631
+ * @example
2632
+ * ```typescript
2633
+ * lastOrDefault(
2634
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
2635
+ * {id: -1, value: 30},
2636
+ * item => item.value === 30,
2637
+ * ); // => {id: -1, value: 30}
2638
+ * ```
1370
2639
  */
1371
2640
  declare function lastOrDefault<Item>(array: Item[], defaultValue: Item, filter: (item: Item, index: number, array: Item[]) => boolean): Item;
1372
2641
  /**
1373
2642
  * Get the last item from an array
1374
2643
  *
1375
2644
  * Available as `lastOrDefault` and `last.default`
2645
+ *
1376
2646
  * @param array Array to get from
1377
2647
  * @param defaultValue Default value to return if the array is empty
1378
- * @return Last item from the array, or the default value if the array is empty
2648
+ * @returns Last item from the array, or the default value if the array is empty
2649
+ *
2650
+ * @example
2651
+ * ```typescript
2652
+ * lastOrDefault([], {id: -1, value: 30}); // => {id: -1, value: 30}
2653
+ * ```
1379
2654
  */
1380
2655
  declare function lastOrDefault<Item>(array: Item[], defaultValue: Item): Item;
1381
2656
  //#endregion
@@ -1386,36 +2661,66 @@ declare function lastOrDefault<Item>(array: Item[], defaultValue: Item): Item;
1386
2661
  * 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
2662
  *
1388
2663
  * If either of values are not present in the array, or if they overlap, the array will be returned unchanged
2664
+ *
1389
2665
  * @param array Array to move within
1390
2666
  * @param from Item or items to move
1391
2667
  * @param to Item or items to move to
1392
- * @param key Key to get an item's value for matching
2668
+ * @param callback Callback to get an item's value for matching
1393
2669
  * @returns Original array with items moved _(or unchanged if unable to move)_
2670
+ *
2671
+ * @example
2672
+ * ```typescript
2673
+ * const array = [{id: 1}, {id: 2}, {id: 3}, {id: 4}];
2674
+ *
2675
+ * move(array, {id: 1}, {id: 3}, item => item.id); // => [{id: 2}, {id: 3}, {id: 1}, {id: 4}]
2676
+ * move(array, [{id: 2}, {id: 3}], {id: 4}, item => item.id); // => [{id: 1}, {id: 4}, {id: 2}, {id: 3}]
2677
+ * move(array, {id: 5}, {id: 1}, item => item.id); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}] (unchanged)
2678
+ * ```
1394
2679
  */
1395
- declare function move<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], from: Item | Item[], to: Item | Item[], key: ItemKey): Item[];
2680
+ declare function move<Item>(array: Item[], from: Item | Item[], to: Item | Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
1396
2681
  /**
1397
2682
  * Move an item _(or array of items)_ to the position of another item _(or array of items)_ within an array
1398
2683
  *
1399
2684
  * 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
2685
  *
1401
2686
  * If either of values are not present in the array, or if they overlap, the array will be returned unchanged
2687
+ *
1402
2688
  * @param array Array to move within
1403
2689
  * @param from Item or items to move
1404
2690
  * @param to Item or items to move to
1405
- * @param callback Callback to get an item's value for matching
2691
+ * @param key Key to get an item's value for matching
1406
2692
  * @returns Original array with items moved _(or unchanged if unable to move)_
2693
+ *
2694
+ * @example
2695
+ * ```typescript
2696
+ * const array = [{id: 1}, {id: 2}, {id: 3}, {id: 4}];
2697
+ *
2698
+ * move(array, {id: 1}, {id: 3}, 'id'); // => [{id: 2}, {id: 3}, {id: 1}, {id: 4}]
2699
+ * move(array, [{id: 2}, {id: 3}], {id: 4}, 'id'); // => [{id: 1}, {id: 4}, {id: 2}, {id: 3}]
2700
+ * move(array, {id: 5}, {id: 1}, 'id'); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}] (unchanged)
2701
+ * ```
1407
2702
  */
1408
- declare function move<Item>(array: Item[], from: Item | Item[], to: Item | Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
2703
+ declare function move<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], from: Item | Item[], to: Item | Item[], key: ItemKey): Item[];
1409
2704
  /**
1410
2705
  * Move an item _(or array of items)_ to the position of another item _(or array of items)_ within an array
1411
2706
  *
1412
2707
  * 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
2708
  *
1414
2709
  * If either of values are not present in the array, or if they overlap, the array will be returned unchanged
2710
+ *
1415
2711
  * @param array Array to move within
1416
2712
  * @param from Item or items to move
1417
2713
  * @param to Item or items to move to
1418
2714
  * @returns Original array with items moved _(or unchanged if unable to move)_
2715
+ *
2716
+ * @example
2717
+ * ```typescript
2718
+ * const array = [1, 2, 3, 4];
2719
+ *
2720
+ * move(array, 1, 3); // => [2, 3, 1, 4]
2721
+ * move(array, [2, 3], 4); // => [1, 4, 2, 3]
2722
+ * move(array, 5, 1); // => [1, 2, 3, 4] (unchanged)
2723
+ * ```
1419
2724
  */
1420
2725
  declare function move<Item>(array: Item[], from: Item | Item[], to: Item | Item[]): Item[];
1421
2726
  declare namespace move {
@@ -1428,10 +2733,20 @@ declare namespace move {
1428
2733
  * If the from index is out of bounds, the array will be returned unchanged
1429
2734
  *
1430
2735
  * Available as `moveIndices` and `move.indices`
2736
+ *
1431
2737
  * @param array Array to move within
1432
2738
  * @param from Index to move from
1433
2739
  * @param to Index to move to
1434
2740
  * @returns Original array with item moved _(or unchanged if unable to move)_
2741
+ *
2742
+ * @example
2743
+ * ```typescript
2744
+ * const array = [1, 2, 3, 4];
2745
+ *
2746
+ * moveIndices(array, 0, 2); // => [2, 3, 1, 4]
2747
+ * moveIndices(array, -1, 0); // => [4, 2, 3, 1]
2748
+ * moveIndices(array, 5, 1); // => [4, 2, 3, 1] (unchanged)
2749
+ * ```
1435
2750
  */
1436
2751
  declare function moveIndices<Item>(array: Item[], from: number, to: number): Item[];
1437
2752
  /**
@@ -1440,36 +2755,66 @@ declare function moveIndices<Item>(array: Item[], from: number, to: number): Ite
1440
2755
  * If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged
1441
2756
  *
1442
2757
  * Available as `moveToIndex` and `move.toIndex`
2758
+ *
2759
+ * @example
2760
+ * ```typescript
2761
+ * const array = [{id: 1}, {id: 2}, {id: 3}, {id: 4}];
2762
+ *
2763
+ * moveToIndex(array, {id: 1}, 2, item => item.id); // => [{id: 2}, {id: 3}, {id: 1}, {id: 4}]
2764
+ * moveToIndex(array, [{id: 2}, {id: 3}], 3, item => item.id); // => [{id: 1}, {id: 4}, {id: 2}, {id: 3}]
2765
+ * moveToIndex(array, {id: 5}, 1, item => item.id); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}] (unchanged)
2766
+ * ```
2767
+ *
1443
2768
  * @param array Array to move within
1444
2769
  * @param value Item or items to move
1445
2770
  * @param index Index to move to
1446
- * @param key Key to get an item's value for matching
2771
+ * @param callback Callback to get an item's value for matching
1447
2772
  * @returns Original array with items moved _(or unchanged if unable to move)_
1448
2773
  */
1449
- declare function moveToIndex<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], value: Item | Item[], index: number, key: ItemKey): Item[];
2774
+ declare function moveToIndex<Item>(array: Item[], value: Item | Item[], index: number, callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
1450
2775
  /**
1451
2776
  * Move an item _(or array of items)_ to an index within an array
1452
2777
  *
1453
2778
  * If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged
1454
2779
  *
1455
2780
  * Available as `moveToIndex` and `move.toIndex`
2781
+ *
1456
2782
  * @param array Array to move within
1457
2783
  * @param value Item or items to move
1458
2784
  * @param index Index to move to
1459
- * @param callback Callback to get an item's value for matching
2785
+ * @param key Key to get an item's value for matching
1460
2786
  * @returns Original array with items moved _(or unchanged if unable to move)_
2787
+ *
2788
+ * @example
2789
+ * ```typescript
2790
+ * const array = [{id: 1}, {id: 2}, {id: 3}, {id: 4}];
2791
+ *
2792
+ * moveToIndex(array, {id: 1}, 2, 'id'); // => [{id: 2}, {id: 3}, {id: 1}, {id: 4}]
2793
+ * moveToIndex(array, [{id: 2}, {id: 3}], 3, 'id'); // => [{id: 1}, {id: 4}, {id: 2}, {id: 3}]
2794
+ * moveToIndex(array, {id: 5}, 1, 'id'); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}] (unchanged)
2795
+ * ```
1461
2796
  */
1462
- declare function moveToIndex<Item>(array: Item[], value: Item | Item[], index: number, callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
2797
+ declare function moveToIndex<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], value: Item | Item[], index: number, key: ItemKey): Item[];
1463
2798
  /**
1464
2799
  * Move an item _(or array of items)_ to an index within an array
1465
2800
  *
1466
2801
  * If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged
1467
2802
  *
1468
2803
  * Available as `moveToIndex` and `move.toIndex`
2804
+ *
1469
2805
  * @param array Array to move within
1470
2806
  * @param value Item or items to move
1471
2807
  * @param index Index to move to
1472
2808
  * @returns Original array with items moved _(or unchanged if unable to move)_
2809
+ *
2810
+ * @example
2811
+ * ```typescript
2812
+ * const array = [1, 2, 3, 4];
2813
+ *
2814
+ * moveToIndex(array, 1, 2); // => [2, 3, 1, 4]
2815
+ * moveToIndex(array, [2, 3], 3); // => [1, 4, 2, 3]
2816
+ * moveToIndex(array, 5, 1); // => [1, 2, 3, 4] (unchanged)
2817
+ * ```
1473
2818
  */
1474
2819
  declare function moveToIndex<Item>(array: Item[], value: Item | Item[], index: number): Item[];
1475
2820
  //#endregion
@@ -1546,6 +2891,7 @@ type SortDirection = 'ascending' | 'descending';
1546
2891
  type Sorter<Item> = {
1547
2892
  /**
1548
2893
  * Sort an array of items
2894
+ *
1549
2895
  * @param array Array to sort
1550
2896
  * @returns Sorted array
1551
2897
  */
@@ -1554,6 +2900,7 @@ type Sorter<Item> = {
1554
2900
  * Get the index for an item _(to be inserted into an array of items)_
1555
2901
  *
1556
2902
  * _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
2903
+ *
1557
2904
  * @param array Array to get the index from
1558
2905
  * @param item Item to get the index for
1559
2906
  * @returns Index for item
@@ -1561,6 +2908,7 @@ type Sorter<Item> = {
1561
2908
  index(array: Item[], item: Item): number;
1562
2909
  /**
1563
2910
  * Is the array sorted?
2911
+ *
1564
2912
  * @param array Array to check
1565
2913
  * @returns `true` if sorted, otherwise `false`
1566
2914
  */
@@ -1572,6 +2920,7 @@ type Sorter<Item> = {
1572
2920
  * _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
1573
2921
  *
1574
2922
  * Available as `getSortedIndex` and `sort.getIndex`
2923
+ *
1575
2924
  * @param array Array to get the index from
1576
2925
  * @param item Item to get the index for
1577
2926
  * @param sorters Sorters to use to determine sorting
@@ -1585,6 +2934,7 @@ declare function getSortedIndex<Item>(array: Item[], item: Item, sorters: Array<
1585
2934
  * _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
1586
2935
  *
1587
2936
  * Available as `getSortedIndex` and `sort.getIndex`
2937
+ *
1588
2938
  * @param array Array to get the index from
1589
2939
  * @param item Item to get the index for
1590
2940
  * @param sorter Sorter to use to determine sorting
@@ -1598,6 +2948,7 @@ declare function getSortedIndex<Item>(array: Item[], item: Item, sorter: ArraySo
1598
2948
  * _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
1599
2949
  *
1600
2950
  * Available as `getSortedIndex` and `sort.getIndex`
2951
+ *
1601
2952
  * @param array Array to get the index from
1602
2953
  * @param item Item to get the index for
1603
2954
  * @param descending Sorted in descending order? _(defaults to `false`)_
@@ -1608,6 +2959,7 @@ declare function getSortedIndex<Item>(array: Item[], item: Item, descending?: bo
1608
2959
  * Initialize a sort handler with sorters _(and an optional default direction)_
1609
2960
  *
1610
2961
  * Available as `initializeSorter` and `sort.initialize`
2962
+ *
1611
2963
  * @param sorters Sorters to use for sorting
1612
2964
  * @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
1613
2965
  * @returns Sort handler
@@ -1617,6 +2969,7 @@ declare function initializeSorter<Item>(sorters: Array<ArraySorter<Item>>, desce
1617
2969
  * Initialize a sort handler with a sorter _(and an optional default direction)_
1618
2970
  *
1619
2971
  * Available as `initializeSorter` and `sort.initialize`
2972
+ *
1620
2973
  * @param sorter Sorter to use for sorting
1621
2974
  * @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
1622
2975
  * @returns Sort handler
@@ -1626,12 +2979,14 @@ declare function initializeSorter<Item>(sorter: ArraySorter<Item>, descending?:
1626
2979
  * Initialize a sort handler _(with an optional default direction)_
1627
2980
  *
1628
2981
  * Available as `initializeSorter` and `sort.initialize`
2982
+ *
1629
2983
  * @param descending Sort in descending order? _(defaults to `false`)_
1630
2984
  * @returns Sort handler
1631
2985
  */
1632
2986
  declare function initializeSorter<Item>(descending?: boolean): Sorter<Item>;
1633
2987
  /**
1634
2988
  * Is the array sorted according to the sorters _(and the optional default direction)_?
2989
+ *
1635
2990
  * @param array Array to check
1636
2991
  * @param sorters Sorters to determine sorting
1637
2992
  * @param descending Sorted in descending order? _(defaults to `false`; overridden by individual sorters)_
@@ -1640,6 +2995,7 @@ declare function initializeSorter<Item>(descending?: boolean): Sorter<Item>;
1640
2995
  declare function isSorted<Item>(array: Item[], sorters: Array<ArraySorter<Item>>, descending?: boolean): boolean;
1641
2996
  /**
1642
2997
  * Is the array sorted according to the sorter _(and the optional default direction)_?
2998
+ *
1643
2999
  * @param array Array to check
1644
3000
  * @param sorter Sorter to determine sorting
1645
3001
  * @param descending Sorted in descending order? _(defaults to `false`; overridden by individual sorters)_
@@ -1650,6 +3006,7 @@ declare function isSorted<Item>(array: Item[], sorter: ArraySorter<Item>, descen
1650
3006
  * Is the array sorted?
1651
3007
  *
1652
3008
  * Available as `isSorted` and `sort.is`
3009
+ *
1653
3010
  * @param array Array to check
1654
3011
  * @param descending Sorted in descending order? _(defaults to `false`)_
1655
3012
  * @returns `true` if sorted, otherwise `false`
@@ -1657,10 +3014,19 @@ declare function isSorted<Item>(array: Item[], sorter: ArraySorter<Item>, descen
1657
3014
  declare function isSorted<Item>(array: Item[], descending?: boolean): boolean;
1658
3015
  /**
1659
3016
  * Sort an array of items using a comparison callback
3017
+ *
1660
3018
  * @param array Array to sort
1661
3019
  * @param comparator Comparator to use for sorting
1662
3020
  * @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
1663
3021
  * @returns Sorted array
3022
+ *
3023
+ * @example
3024
+ * ```typescript
3025
+ * sort(
3026
+ * [{id: 3}, {id: 1}, {id: 2}],
3027
+ * (first, second) => first.id - second.id,
3028
+ * ); // => [{id: 1}, {id: 2}, {id: 3}]
3029
+ * ```
1664
3030
  */
1665
3031
  declare function sort<Item>(array: Item[], comparator: (first: Item, second: Item) => number, descending?: boolean): Item[];
1666
3032
  /**
@@ -1699,62 +3065,166 @@ declare const SORT_DIRECTION_DESCENDING: SortDirection;
1699
3065
  * Swap two smaller arrays within a larger array
1700
3066
  *
1701
3067
  * If either of the smaller arrays are not present in the larger array, or if they overlap, the larger array will be returned unchanged
3068
+ *
1702
3069
  * @param array Array of items to swap
1703
3070
  * @param first First array
1704
3071
  * @param second Second array
1705
- * @param key Key to get an item's value for matching
3072
+ * @param callback Callback to get an item's value for matching
1706
3073
  * @returns Original array with items swapped _(or unchanged if unable to swap)_
3074
+ *
3075
+ * @example
3076
+ * ```typescript
3077
+ * swap(
3078
+ * [
3079
+ * {id: 1, name: 'Alice'},
3080
+ * {id: 2, name: 'Bob'},
3081
+ * {id: 3, name: 'Charlie'},
3082
+ * ],
3083
+ * [
3084
+ * {id: 2, name: 'Bob'},
3085
+ * ],
3086
+ * [
3087
+ * {id: 3, name: 'Charlie'},
3088
+ * ],
3089
+ * item => item.id,
3090
+ * ); // => [
3091
+ * // {id: 1, name: 'Alice'},
3092
+ * // {id: 3, name: 'Charlie'},
3093
+ * // {id: 2, name: 'Bob'},
3094
+ * // ]
3095
+ * ```
1707
3096
  */
1708
- declare function swap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], first: Item[], second: Item[], key: ItemKey): Item[];
3097
+ declare function swap<Item>(array: Item[], first: Item[], second: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
1709
3098
  /**
1710
3099
  * Swap two smaller arrays within a larger array
1711
3100
  *
1712
3101
  * If either of the smaller arrays are not present in the larger array, or if they overlap, the larger array will be returned unchanged
3102
+ *
1713
3103
  * @param array Array of items to swap
1714
3104
  * @param first First array
1715
3105
  * @param second Second array
1716
- * @param callback Callback to get an item's value for matching
3106
+ * @param key Key to get an item's value for matching
1717
3107
  * @returns Original array with items swapped _(or unchanged if unable to swap)_
3108
+ *
3109
+ * @example
3110
+ * ```typescript
3111
+ * swap(
3112
+ * [
3113
+ * {id: 1, name: 'Alice'},
3114
+ * {id: 2, name: 'Bob'},
3115
+ * {id: 3, name: 'Charlie'},
3116
+ * ],
3117
+ * [
3118
+ * {id: 2, name: 'Bob'},
3119
+ * ],
3120
+ * [
3121
+ * {id: 3, name: 'Charlie'},
3122
+ * ],
3123
+ * 'id',
3124
+ * ); // => [
3125
+ * // {id: 1, name: 'Alice'},
3126
+ * // {id: 3, name: 'Charlie'},
3127
+ * // {id: 2, name: 'Bob'},
3128
+ * // ]
3129
+ * ```
1718
3130
  */
1719
- declare function swap<Item>(array: Item[], first: Item[], second: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
3131
+ declare function swap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], first: Item[], second: Item[], key: ItemKey): Item[];
1720
3132
  /**
1721
3133
  * Swap two smaller arrays within a larger array
1722
3134
  *
1723
3135
  * If either of the smaller arrays are not present in the larger array, or if they overlap, the larger array will be returned unchanged
3136
+ *
1724
3137
  * @param array Array of items to swap
1725
3138
  * @param first First array
1726
3139
  * @param second Second array
1727
3140
  * @returns Original array with items swapped _(or unchanged if unable to swap)_
3141
+ *
3142
+ * @example
3143
+ * ```typescript
3144
+ * swap(
3145
+ * [1, 2, 3, 4, 5, 6],
3146
+ * [1, 2],
3147
+ * [5, 6],
3148
+ * ); // => [5, 6, 3, 4, 1, 2]
3149
+ * ```
1728
3150
  */
1729
3151
  declare function swap<Item>(array: Item[], first: Item[], second: Item[]): Item[];
1730
3152
  /**
1731
3153
  * Swap two indiced items in an array
1732
3154
  *
1733
3155
  * If either of the items are not present in the array, the array will be returned unchanged
3156
+ *
1734
3157
  * @param array Array of items to swap
1735
3158
  * @param first First item
1736
3159
  * @param second Second item
1737
- * @param key Key to get an item's value for matching
3160
+ * @param callback Callback to get an item's value for matching
1738
3161
  * @returns Original array with items swapped _(or unchanged if unable to swap)_
3162
+ *
3163
+ * @example
3164
+ * ```typescript
3165
+ * swap(
3166
+ * [
3167
+ * {id: 1, name: 'Alice'},
3168
+ * {id: 2, name: 'Bob'},
3169
+ * {id: 3, name: 'Charlie'},
3170
+ * ],
3171
+ * {id: 2, name: 'Bob'},
3172
+ * {id: 3, name: 'Charlie'},
3173
+ * item => item.id,
3174
+ * ); // => [
3175
+ * // {id: 1, name: 'Alice'},
3176
+ * // {id: 3, name: 'Charlie'},
3177
+ * // {id: 2, name: 'Bob'},
3178
+ * // ]
3179
+ * ```
1739
3180
  */
1740
- declare function swap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], first: Item, second: Item, key: ItemKey): Item[];
3181
+ declare function swap<Item>(array: Item[], first: Item, second: Item, callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
1741
3182
  /**
1742
3183
  * Swap two indiced items in an array
1743
3184
  *
1744
3185
  * If either of the items are not present in the array, the array will be returned unchanged
3186
+ *
1745
3187
  * @param array Array of items to swap
1746
3188
  * @param first First item
1747
3189
  * @param second Second item
1748
- * @param callback Callback to get an item's value for matching
3190
+ * @param key Key to get an item's value for matching
1749
3191
  * @returns Original array with items swapped _(or unchanged if unable to swap)_
3192
+ *
3193
+ * @example
3194
+ * ```typescript
3195
+ * swap(
3196
+ * [
3197
+ * {id: 1, name: 'Alice'},
3198
+ * {id: 2, name: 'Bob'},
3199
+ * {id: 3, name: 'Charlie'},
3200
+ * ],
3201
+ * {id: 2, name: 'Bob'},
3202
+ * {id: 3, name: 'Charlie'},
3203
+ * 'id',
3204
+ * ); // => [
3205
+ * // {id: 1, name: 'Alice'},
3206
+ * // {id: 3, name: 'Charlie'},
3207
+ * // {id: 2, name: 'Bob'},
3208
+ * // ]
3209
+ * ```
1750
3210
  */
1751
- declare function swap<Item>(array: Item[], first: Item, second: Item, callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
3211
+ declare function swap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], first: Item, second: Item, key: ItemKey): Item[];
1752
3212
  /**
1753
3213
  * Swap two indiced items in an array
3214
+ *
1754
3215
  * @param array Array of items to swap
1755
3216
  * @param first First item
1756
3217
  * @param second Second item
1757
3218
  * @returns Original array with items swapped _(or unchanged if unable to swap)_
3219
+ *
3220
+ * @example
3221
+ * ```typescript
3222
+ * swap(
3223
+ * [1, 2, 3, 4, 5, 6],
3224
+ * 2,
3225
+ * 5,
3226
+ * ); // => [1, 5, 3, 4, 2, 6]
3227
+ * ```
1758
3228
  */
1759
3229
  declare function swap<Item>(array: Item[], first: Item, second: Item): Item[];
1760
3230
  declare namespace swap {
@@ -1766,6 +3236,7 @@ declare namespace swap {
1766
3236
  * If either index is out of bounds, the array will be returned unchanged
1767
3237
  *
1768
3238
  * Available as `swapIndices` and `swap.indices`
3239
+ *
1769
3240
  * @param array Array of items to swap
1770
3241
  * @param first First index _(can be negative to count from the end)_
1771
3242
  * @param second Second index _(can be negative to count from the end)_
@@ -1778,64 +3249,130 @@ declare function swapIndices<Item>(array: Item[], first: number, second: number)
1778
3249
  * Create a Map from an array of items using callbacks
1779
3250
  *
1780
3251
  * If multiple items have the same key, the latest item's value will be used
3252
+ *
1781
3253
  * @param array Array to convert
1782
3254
  * @param key Callback to get an item's grouping key
1783
3255
  * @param value Callback to get an item's value
1784
3256
  * @returns Map of keyed values
3257
+ *
3258
+ * @example
3259
+ * ```typescript
3260
+ * toMap(
3261
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3262
+ * item => item.value,
3263
+ * item => item.id,
3264
+ * ); // => Map { 10 => 3, 20 => 2 }
3265
+ * ```
1785
3266
  */
1786
3267
  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
3268
  /**
1788
3269
  * Create a Map from an array of items using a callback and value
1789
3270
  *
1790
3271
  * If multiple items have the same key, the latest item's value will be used
3272
+ *
1791
3273
  * @param array Array to convert
1792
3274
  * @param key Callback to get an item's grouping key
1793
3275
  * @param value Key to use for value
1794
3276
  * @returns Map of keyed values
3277
+ *
3278
+ * @example
3279
+ * ```typescript
3280
+ * toMap(
3281
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3282
+ * item => item.value,
3283
+ * 'id',
3284
+ * ); // => Map { 10 => 3, 20 => 2 }
3285
+ * ```
1795
3286
  */
1796
3287
  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
3288
  /**
1798
3289
  * Create a Map from an array of items using a key and callback
1799
3290
  *
1800
3291
  * If multiple items have the same key, the latest item's value will be used
3292
+ *
1801
3293
  * @param array Array to convert
1802
3294
  * @param key Key to use for grouping
1803
3295
  * @param value Callback to get an item's value
1804
3296
  * @returns Map of keyed values
3297
+ *
3298
+ * @example
3299
+ * ```typescript
3300
+ * toMap(
3301
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3302
+ * 'value',
3303
+ * item => item.id,
3304
+ * ); // => Map { 10 => 3, 20 => 2 }
3305
+ * ```
1805
3306
  */
1806
3307
  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
3308
  /**
1808
3309
  * Create a Map from an array of items using a key and value
1809
3310
  *
1810
3311
  * If multiple items have the same key, the latest item's value will be used
3312
+ *
1811
3313
  * @param array Array to convert
1812
3314
  * @param key Key to use for grouping
1813
3315
  * @param value Key to use for value
1814
3316
  * @returns Map of keyed values
3317
+ *
3318
+ * @example
3319
+ * ```typescript
3320
+ * toMap(
3321
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3322
+ * 'value',
3323
+ * 'id',
3324
+ * ); // => Map { 10 => 3, 20 => 2 }
3325
+ * ```
1815
3326
  */
1816
3327
  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
3328
  /**
1818
3329
  * Create a Map from an array of items using a callback
1819
3330
  *
1820
3331
  * If multiple items have the same key, the latest item will be used
3332
+ *
1821
3333
  * @param array Array to convert
1822
3334
  * @param callback Callback to get an item's grouping key
1823
3335
  * @returns Map of keyed items
3336
+ *
3337
+ * @example
3338
+ * ```typescript
3339
+ * toMap(
3340
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3341
+ * item => item.value,
3342
+ * ); // => Map { 10 => {id: 3, value: 10}, 20 => {id: 2, value: 20} }
3343
+ * ```
1824
3344
  */
1825
3345
  declare function toMap<Item, Callback extends (item: Item, index: number, array: Item[]) => Key$1>(array: Item[], callback: Callback): Map<ReturnType<Callback>, Item>;
1826
3346
  /**
1827
3347
  * Create a Map from an array of items using a key
1828
3348
  *
1829
3349
  * If multiple items have the same key, the latest item will be used
3350
+ *
1830
3351
  * @param array Array to convert
1831
3352
  * @param key Key to use for grouping
1832
3353
  * @returns Map of keyed items
3354
+ *
3355
+ * @example
3356
+ * ```typescript
3357
+ * toMap(
3358
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3359
+ * 'value',
3360
+ * ); // => Map { 10 => {id: 3, value: 10}, 20 => {id: 2, value: 20} }
3361
+ * ```
1833
3362
  */
1834
3363
  declare function toMap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Map<Item[ItemKey], Item>;
1835
3364
  /**
1836
3365
  * Create a Map from an array of items _(using indices as keys)_
3366
+ *
1837
3367
  * @param array Array to convert
1838
3368
  * @returns Map of indiced items
3369
+ *
3370
+ * @example
3371
+ * ```typescript
3372
+ * toMap(
3373
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3374
+ * ); // => Map { 0 => {id: 1, value: 10}, 1 => {id: 2, value: 20}, 2 => {id: 3, value: 10} }
3375
+ * ```
1839
3376
  */
1840
3377
  declare function toMap<Item>(array: Item[]): Map<number, Item>;
1841
3378
  declare namespace toMap {
@@ -1845,58 +3382,116 @@ declare namespace toMap {
1845
3382
  * Create a Map from an array of items using callbacks, grouping values into arrays
1846
3383
  *
1847
3384
  * Available as `toMapArrays` and `toMap.arrays`
3385
+ *
1848
3386
  * @param array Array to convert
1849
3387
  * @param key Callback to get an item's grouping key
1850
3388
  * @param value Callback to get an item's value
1851
3389
  * @returns Map of keyed arrays of values
3390
+ *
3391
+ * @example
3392
+ * ```typescript
3393
+ * toMapArrays(
3394
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3395
+ * item => item.value,
3396
+ * item => item.id,
3397
+ * ); // => Map { 10 => [1, 3], 20 => [2] }
3398
+ * ```
1852
3399
  */
1853
3400
  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
3401
  /**
1855
3402
  * Create a Map from an array of items using a callback and value, grouping values into arrays
1856
3403
  *
1857
3404
  * Available as `toMapArrays` and `toMap.arrays`
3405
+ *
1858
3406
  * @param array Array to convert
1859
3407
  * @param key Callback to get an item's grouping key
1860
3408
  * @param value Key to use for value
1861
3409
  * @returns Map of keyed arrays of values
3410
+ *
3411
+ * @example
3412
+ * ```typescript
3413
+ * toMapArrays(
3414
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3415
+ * item => item.value,
3416
+ * 'id',
3417
+ * ); // => Map { 10 => [1, 3], 20 => [2] }
3418
+ * ```
1862
3419
  */
1863
3420
  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
3421
  /**
1865
3422
  * Create a Map from an array of items using a key and callback, grouping values into arrays
1866
3423
  *
1867
3424
  * Available as `toMapArrays` and `toMap.arrays`
3425
+ *
1868
3426
  * @param array Array to convert
1869
3427
  * @param key Key to use for grouping
1870
3428
  * @param value Callback to get an item's value
1871
3429
  * @returns Map of keyed arrays of values
3430
+ *
3431
+ * @example
3432
+ * ```typescript
3433
+ * toMapArrays(
3434
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3435
+ * 'value',
3436
+ * item => item.id,
3437
+ * ); // => Map { 10 => [1, 3], 20 => [2] }
3438
+ * ```
1872
3439
  */
1873
3440
  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
3441
  /**
1875
3442
  * Create a Map from an array of items using a key and value, grouping values into arrays
1876
3443
  *
1877
3444
  * Available as `toMapArrays` and `toMap.arrays`
3445
+ *
1878
3446
  * @param array Array to convert
1879
3447
  * @param key Key to use for grouping
1880
3448
  * @param value Key to use for value
1881
3449
  * @returns Map of keyed arrays of values
3450
+ *
3451
+ * @example
3452
+ * ```typescript
3453
+ * toMapArrays(
3454
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3455
+ * 'value',
3456
+ * 'id',
3457
+ * ); // => Map { 10 => [1, 3], 20 => [2] }
3458
+ * ```
1882
3459
  */
1883
3460
  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
3461
  /**
1885
3462
  * Create a Map from an array of items using a callback, grouping items into arrays
1886
3463
  *
1887
3464
  * Available as `toMapArrays` and `toMap.arrays`
3465
+ *
1888
3466
  * @param array Array to convert
1889
3467
  * @param callback Callback to get an item's grouping key
1890
3468
  * @returns Map of keyed arrays of items
3469
+ *
3470
+ * @example
3471
+ * ```typescript
3472
+ * toMapArrays(
3473
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3474
+ * item => item.value,
3475
+ * ); // => Map { 10 => [{id: 1, value: 10}, {id: 3, value: 10}], 20 => [{id: 2, value: 20}] }
3476
+ * ```
1891
3477
  */
1892
3478
  declare function toMapArrays<Item, Callback extends (item: Item, index: number, array: Item[]) => Key$1>(array: Item[], callback: Callback): Map<ReturnType<Callback>, Item[]>;
1893
3479
  /**
1894
3480
  * Create a Map from an array of items using a key, grouping items into arrays
1895
3481
  *
1896
3482
  * Available as `toMapArrays` and `toMap.arrays`
3483
+ *
1897
3484
  * @param array Array to convert
1898
3485
  * @param key Key to use for grouping
1899
3486
  * @returns Map of keyed arrays of items
3487
+ *
3488
+ * @example
3489
+ * ```typescript
3490
+ * toMapArrays(
3491
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3492
+ * 'value',
3493
+ * ); // => Map { 10 => [{id: 1, value: 10}, {id: 3, value: 10}], 20 => [{id: 2, value: 20}] }
3494
+ * ```
1900
3495
  */
1901
3496
  declare function toMapArrays<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Map<Item[ItemKey], Item[]>;
1902
3497
  //#endregion
@@ -1905,64 +3500,130 @@ declare function toMapArrays<Item extends PlainObject, ItemKey extends keyof Ite
1905
3500
  * Create a record from an array of items using callbacks
1906
3501
  *
1907
3502
  * If multiple items have the same key, the latest item will be used
3503
+ *
1908
3504
  * @param array Array to convert
1909
3505
  * @param key Callback to get an item's grouping key
1910
3506
  * @param value Callback to get an item's value
1911
3507
  * @returns Record of keyed values
3508
+ *
3509
+ * @example
3510
+ * ```typescript
3511
+ * toRecord(
3512
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3513
+ * item => item.value,
3514
+ * item => item.id,
3515
+ * ); // => { 10: 3, 20: 2 }
3516
+ * ```
1912
3517
  */
1913
3518
  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
3519
  /**
1915
3520
  * Create a record from an array of items using a callback and value
1916
3521
  *
1917
3522
  * If multiple items have the same key, the latest item will be used
3523
+ *
1918
3524
  * @param array Array to convert
1919
3525
  * @param callback Callback to get an item's grouping key
1920
3526
  * @param value Key to use for value
1921
3527
  * @returns Record with keys
3528
+ *
3529
+ * @example
3530
+ * ```typescript
3531
+ * toRecord(
3532
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3533
+ * item => item.value,
3534
+ * 'id',
3535
+ * ); // => { 10: 3, 20: 2 }
3536
+ * ```
1922
3537
  */
1923
3538
  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
3539
  /**
1925
3540
  * Create a record from an array of items using a key and callback
1926
3541
  *
1927
3542
  * If multiple items have the same key, the latest item will be used
3543
+ *
1928
3544
  * @param array Array to convert
1929
3545
  * @param key Key to use for grouping
1930
3546
  * @param callback Callback to get an item's value
1931
3547
  * @returns Record with keys
3548
+ *
3549
+ * @example
3550
+ * ```typescript
3551
+ * toRecord(
3552
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3553
+ * 'value',
3554
+ * item => item.id,
3555
+ * ); // => { 10: 3, 20: 2 }
3556
+ * ```
1932
3557
  */
1933
3558
  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
3559
  /**
1935
3560
  * Create a record from an array of items using a key and value
1936
3561
  *
1937
3562
  * If multiple items have the same key, the latest item will be used
3563
+ *
1938
3564
  * @param array Array to convert
1939
3565
  * @param key Key to use for grouping
1940
3566
  * @param value Key to use for value
1941
3567
  * @returns Record of keyed values
3568
+ *
3569
+ * @example
3570
+ * ```typescript
3571
+ * toRecord(
3572
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3573
+ * 'value',
3574
+ * 'id',
3575
+ * ); // => { 10: 3, 20: 2 }
3576
+ * ```
1942
3577
  */
1943
3578
  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
3579
  /**
1945
3580
  * Create a record from an array of items using a callback
1946
3581
  *
1947
3582
  * If multiple items have the same key, the latest item will be used
3583
+ *
1948
3584
  * @param array Array to convert
1949
3585
  * @param callback Callback to get an item's grouping key
1950
3586
  * @returns Record of keyed values
3587
+ *
3588
+ * @example
3589
+ * ```typescript
3590
+ * toRecord(
3591
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3592
+ * item => item.value,
3593
+ * ); // => { 10: {id: 3, value: 10}, 20: {id: 2, value: 20} }
3594
+ * ```
1951
3595
  */
1952
3596
  declare function toRecord<Item, Callback extends (item: Item, index: number, array: Item[]) => Key$1>(array: Item[], callback: Callback): Record<ReturnType<Callback>, Item>;
1953
3597
  /**
1954
3598
  * Create a record from an array of items using a key
1955
3599
  *
1956
3600
  * If multiple items have the same key, the latest item will be used
3601
+ *
1957
3602
  * @param array Array to convert
1958
3603
  * @param key Key to use for grouping
1959
3604
  * @returns Record of keyed values
3605
+ *
3606
+ * @example
3607
+ * ```typescript
3608
+ * toRecord(
3609
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3610
+ * 'value',
3611
+ * ); // => { 10: {id: 3, value: 10}, 20: {id: 2, value: 20} }
3612
+ * ```
1960
3613
  */
1961
3614
  declare function toRecord<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Simplify<Record<KeyedValue<Item, ItemKey>, Item>>;
1962
3615
  /**
1963
3616
  * Create a record from an array of items _(using indices as keys)_
3617
+ *
1964
3618
  * @param array Array to convert
1965
3619
  * @returns Record of indiced values
3620
+ *
3621
+ * @example
3622
+ * ```typescript
3623
+ * toRecord(
3624
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3625
+ * ); // => { 0: {id: 1, value: 10}, 1: {id: 2, value: 20}, 2: {id: 3, value: 10} }
3626
+ * ```
1966
3627
  */
1967
3628
  declare function toRecord<Item>(array: Item[]): Record<number, Item>;
1968
3629
  declare namespace toRecord {
@@ -1972,58 +3633,116 @@ declare namespace toRecord {
1972
3633
  * Create a record from an array of items using callbacks, grouping values into arrays
1973
3634
  *
1974
3635
  * Available as `toRecordArrays` and `toRecord.arrays`
3636
+ *
1975
3637
  * @param array Array to convert
1976
3638
  * @param key Callback to get an item's grouping key
1977
3639
  * @param value Callback to get an item's value
1978
3640
  * @returns Record of keyed arrays of values
3641
+ *
3642
+ * @example
3643
+ * ```typescript
3644
+ * toRecordArrays(
3645
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3646
+ * item => item.value,
3647
+ * item => item.id,
3648
+ * ); // => { 10: [1, 3], 20: [2] }
3649
+ * ```
1979
3650
  */
1980
3651
  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
3652
  /**
1982
3653
  * Create a record from an array of items using a callback and value, grouping values into arrays
1983
3654
  *
1984
3655
  * Available as `toRecordArrays` and `toRecord.arrays`
3656
+ *
1985
3657
  * @param array Array to convert
1986
3658
  * @param callback Callback to get an item's grouping key
1987
3659
  * @param value Key to use for value
1988
3660
  * @returns Record of keyed arrays of values
3661
+ *
3662
+ * @example
3663
+ * ```typescript
3664
+ * toRecordArrays(
3665
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3666
+ * item => item.value,
3667
+ * 'id',
3668
+ * ); // => { 10: [1, 3], 20: [2] }
3669
+ * ```
1989
3670
  */
1990
3671
  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
3672
  /**
1992
3673
  * Create a record from an array of items using a key and callback, grouping values into arrays
1993
3674
  *
1994
3675
  * Available as `toRecordArrays` and `toRecord.arrays`
3676
+ *
1995
3677
  * @param array Array to convert
1996
3678
  * @param key Key to use for grouping
1997
3679
  * @param callback Callback to get an item's value
1998
3680
  * @returns Record of keyed arrays of values
3681
+ *
3682
+ * @example
3683
+ * ```typescript
3684
+ * toRecordArrays(
3685
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3686
+ * 'value',
3687
+ * item => item.id,
3688
+ * ); // => { 10: [1, 3], 20: [2] }
3689
+ * ```
1999
3690
  */
2000
3691
  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
3692
  /**
2002
3693
  * Create a record from an array of items using a key and value, grouping values into arrays
2003
3694
  *
2004
3695
  * Available as `toRecordArrays` and `toRecord.arrays`
3696
+ *
2005
3697
  * @param array Array to convert
2006
3698
  * @param key Key to use for grouping
2007
3699
  * @param value Key to use for value
2008
3700
  * @returns Record of keyed arrays of values
3701
+ *
3702
+ * @example
3703
+ * ```typescript
3704
+ * toRecordArrays(
3705
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3706
+ * 'value',
3707
+ * 'id',
3708
+ * ); // => { 10: [1, 3], 20: [2] }
3709
+ * ```
2009
3710
  */
2010
3711
  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
3712
  /**
2012
3713
  * Create a record from an array of items using a callback, grouping items into arrays
2013
3714
  *
2014
3715
  * Available as `toRecordArrays` and `toRecord.arrays`
3716
+ *
2015
3717
  * @param array Array to convert
2016
3718
  * @param callback Callback to get an item's grouping key
2017
3719
  * @returns Record of keyed arrays of items
3720
+ *
3721
+ * @example
3722
+ * ```typescript
3723
+ * toRecordArrays(
3724
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3725
+ * item => item.value,
3726
+ * ); // => { 10: [{id: 1, value: 10}, {id: 3, value: 10}], 20: [{id: 2, value: 20}] }
3727
+ * ```
2018
3728
  */
2019
3729
  declare function toRecordArrays<Item, Callback extends (item: Item, index: number, array: Item[]) => Key$1>(array: Item[], callback: Callback): Record<ReturnType<Callback>, Item[]>;
2020
3730
  /**
2021
3731
  * Create a record from an array of items using a key, grouping items into arrays
2022
3732
  *
2023
3733
  * Available as `toRecordArrays` and `toRecord.arrays`
3734
+ *
2024
3735
  * @param array Array to convert
2025
3736
  * @param key Key to use for grouping
2026
3737
  * @returns Record of keyed arrays of items
3738
+ *
3739
+ * @example
3740
+ * ```typescript
3741
+ * toRecordArrays(
3742
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
3743
+ * 'value',
3744
+ * ); // => { 10: [{id: 1, value: 10}, {id: 3, value: 10}], 20: [{id: 2, value: 20}] }
3745
+ * ```
2027
3746
  */
2028
3747
  declare function toRecordArrays<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Simplify<Record<KeyedValue<Item, ItemKey>, Item[]>>;
2029
3748
  //#endregion
@@ -2844,16 +4563,38 @@ declare function registerEqualizer<Instance>(constructor: Constructor<Instance>,
2844
4563
  //#region src/internal/value/get.d.ts
2845
4564
  /**
2846
4565
  * Get the value from an object using a known path
4566
+ *
4567
+ * @example
4568
+ * ```typescript
4569
+ * const data = {foo: {bar: {baz: 42}}};
4570
+ *
4571
+ * getValue(data, 'foo'); // {bar: {baz: 42}}
4572
+ * getValue(data, 'foo.bar'); // {baz: 42}
4573
+ * getValue(data, 'foo.bar.baz'); // 42
4574
+ * getValue(data, 'foo.nope'); // undefined
4575
+ * ```
4576
+ *
2847
4577
  * @param data Object to get value from
2848
- * @param path Path for value, e.g., `foo.bar.baz`
4578
+ * @param path Path for value
2849
4579
  * @returns Found value, or `undefined`
2850
4580
  */
2851
4581
  declare function getValue<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path): NestedValue<Data, Path>;
2852
4582
  /**
2853
4583
  * Get the value from an object using an unknown path
4584
+ *
4585
+ * @example
4586
+ * ```typescript
4587
+ * const data = {foo: {bar: {baz: 42}}};
4588
+ *
4589
+ * getValue(data, 'foo'); // {bar: {baz: 42}}
4590
+ * getValue(data, 'foo.bar'); // {baz: 42}
4591
+ * getValue(data, 'Foo.Bar.Baz', true); // 42
4592
+ * getValue(data, 'foo.nope'); // undefined
4593
+ * ```
4594
+ *
2854
4595
  * @param data Object to get value from
2855
- * @param path Path for value, e.g., `foo.bar.baz`
2856
- * @param ignoreCase If `true`, the path matching is case-insensitive
4596
+ * @param path Path for value
4597
+ * @param ignoreCase If `true`, path matching is case-insensitive
2857
4598
  * @returns Found value, or `undefined`
2858
4599
  */
2859
4600
  declare function getValue<Data extends PlainObject>(data: Data, path: string, ignoreCase?: boolean): unknown;
@@ -2863,7 +4604,7 @@ declare function getValue<Data extends PlainObject>(data: Data, path: string, ig
2863
4604
  * Check if a nested property is defined in an object
2864
4605
  * @param data Object to check in
2865
4606
  * @param path Path for property
2866
- * @return `true` if the property exists, `false` otherwise
4607
+ * @returns `true` if the property exists, `false` otherwise
2867
4608
  */
2868
4609
  declare function hasValue<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path): boolean;
2869
4610
  /**
@@ -2871,7 +4612,7 @@ declare function hasValue<Data extends PlainObject, Path extends NestedKeys<Data
2871
4612
  * @param data Object to check in
2872
4613
  * @param path Path for property
2873
4614
  * @param ignoreCase If `true`, the path matching is case-insensitive
2874
- * @return `true` if the property exists, `false` otherwise
4615
+ * @returns `true` if the property exists, `false` otherwise
2875
4616
  */
2876
4617
  declare function hasValue<Data extends PlainObject>(data: Data, path: string, ignoreCase?: boolean): boolean;
2877
4618
  declare namespace hasValue {
@@ -2884,7 +4625,7 @@ declare namespace hasValue {
2884
4625
  * @param data Object to check in
2885
4626
  * @param path Path for property
2886
4627
  * @param ignoreCase If `true`, the path matching is case-insensitive
2887
- * @return Result object
4628
+ * @returns Result object
2888
4629
  */
2889
4630
  declare function hasValueResult<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path, ignoreCase?: boolean): Result<NestedValue<Data, ToString<Path>>, string>;
2890
4631
  /**
@@ -2894,7 +4635,7 @@ declare function hasValueResult<Data extends PlainObject, Path extends NestedKey
2894
4635
  * @param data Object to check in
2895
4636
  * @param path Path for property
2896
4637
  * @param ignoreCase If `true`, the path matching is case-insensitive
2897
- * @return Result object
4638
+ * @returns Result object
2898
4639
  */
2899
4640
  declare function hasValueResult<Data extends PlainObject>(data: Data, path: string, ignoreCase?: boolean): Result<unknown, string>;
2900
4641
  //#endregion
@@ -3358,7 +5099,7 @@ declare function inMap<Value>(map: Map<unknown, Value>, value: Value): boolean;
3358
5099
  * @param map Map to check in
3359
5100
  * @param value Value to check for
3360
5101
  * @param key To return the key for the value
3361
- * @return The key for the value if it exists, otherwise `undefined`
5102
+ * @returns The key for the value if it exists, otherwise `undefined`
3362
5103
  */
3363
5104
  declare function inMap<Key, Value>(map: Map<Key, Value>, value: Value, key: true): Key;
3364
5105
  /**
@@ -3500,10 +5241,6 @@ declare function smush<Value extends PlainObject>(value: Value): Smushed<Value>;
3500
5241
  * Thanks, type-fest!
3501
5242
  */
3502
5243
  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
5244
  /**
3508
5245
  * An unsmushed object, with all dot notation keys turned into nested keys
3509
5246
  */
@@ -3520,13 +5257,16 @@ declare function unsmush<Value extends PlainObject>(value: Value): Unsmushed<Val
3520
5257
  * Options for assigning values
3521
5258
  */
3522
5259
  type AssignOptions = Omit<MergeOptions, 'assignValues'>;
3523
- /**
3524
- * Assign values from multiple arrays or objects to the first one
3525
- * @param to Value to assign to
3526
- * @param from Values to assign
3527
- * @returns Assigned value
3528
- */
3529
- type Assigner<Model extends ArrayOrPlainObject = ArrayOrPlainObject> = (to: NestedPartial<Model>, from: NestedPartial<Model>[]) => Model;
5260
+ type Assigner = {
5261
+ /**
5262
+ * Assign values from one or more objects to the first one
5263
+ *
5264
+ * @param to Value to assign to
5265
+ * @param from Values to assign
5266
+ * @returns Assigned value
5267
+ */
5268
+ <To extends PlainObject, From extends PlainObject[]>(to: To, from: [...From]): To & UnionToIntersection<From[number]>;
5269
+ };
3530
5270
  /**
3531
5271
  * Options for merging values
3532
5272
  */
@@ -3560,20 +5300,24 @@ type MergeOptions = {
3560
5300
  */
3561
5301
  skipNullableInArrays?: boolean;
3562
5302
  };
5303
+ type Merger = {
5304
+ /**
5305
+ * Merge multiple arrays or objects into a single one
5306
+ *
5307
+ * @param values Values to merge
5308
+ * @returns Merged value
5309
+ */
5310
+ <Values extends ArrayOrPlainObject[]>(values: NestedPartial<Values[number]>[]): UnionToIntersection<Values[number]>;
5311
+ };
3563
5312
  /**
3564
- * Merge multiple arrays or objects into a single one
3565
- * @param values Values to merge
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
5313
+ * Assign values from one or more objects to the first one
5314
+ *
3571
5315
  * @param to Value to assign to
3572
5316
  * @param from Values to assign
3573
5317
  * @param options Assigning options
3574
5318
  * @returns Assigned value
3575
5319
  */
3576
- declare function assign<Model extends ArrayOrPlainObject>(to: NestedPartial<Model>, from: NestedPartial<Model>[], options?: AssignOptions): Model;
5320
+ declare function assign<To extends PlainObject, From extends PlainObject[]>(to: To, from: [...From], options?: AssignOptions): To & UnionToIntersection<From[number]>;
3577
5321
  declare namespace assign {
3578
5322
  var initialize: typeof initializeAssigner;
3579
5323
  }
@@ -3581,32 +5325,28 @@ declare namespace assign {
3581
5325
  * Create an assigner with predefined options
3582
5326
  *
3583
5327
  * Available as `initializeAssigner` and `assign.initialize`
5328
+ *
3584
5329
  * @param options Assigning options
3585
5330
  * @returns Assigner function
3586
5331
  */
3587
- declare function initializeAssigner<Model extends ArrayOrPlainObject>(options?: AssignOptions): Assigner<Model>;
5332
+ declare function initializeAssigner(options?: AssignOptions): Assigner;
3588
5333
  /**
3589
5334
  * Create a merger with predefined options
3590
5335
  *
3591
5336
  * Available as `initializeMerger` and `merge.initialize`
5337
+ *
3592
5338
  * @param options Merging options
3593
5339
  * @returns Merger function
3594
5340
  */
3595
5341
  declare function initializeMerger(options?: MergeOptions): Merger;
3596
5342
  /**
3597
5343
  * Merge multiple arrays or objects into a single one
5344
+ *
3598
5345
  * @param values Values to merge
3599
5346
  * @param options Merging options
3600
5347
  * @returns Merged value
3601
5348
  */
3602
- declare function merge<Model extends ArrayOrPlainObject>(values: NestedPartial<Model>[], options?: MergeOptions): Model;
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;
5349
+ declare function merge<Values extends ArrayOrPlainObject[]>(values: [...Values], options?: MergeOptions): UnionToIntersection<Values[number]>;
3610
5350
  declare namespace merge {
3611
5351
  var initialize: typeof initializeMerger;
3612
5352
  }
@@ -3639,7 +5379,7 @@ declare function initializeTransformer<Value extends PlainObject>(transform: Tra
3639
5379
  *
3640
5380
  * Available as `initializeTransformer` and `transform.initialize`
3641
5381
  * @param transformers Keyed transformer functions
3642
- * @return Transformer
5382
+ * @returns Transformer
3643
5383
  */
3644
5384
  declare function initializeTransformer<Value extends PlainObject>(transformers: TransformCallbacks<Value>): Transformer<Value>;
3645
5385
  /**
@@ -4323,6 +6063,17 @@ declare const logger: Logger;
4323
6063
  //#region src/internal/math/aggregate.d.ts
4324
6064
  /**
4325
6065
  * Get the maximum value from a list of items
6066
+ *
6067
+ * @example
6068
+ * ```typescript
6069
+ * max(
6070
+ * [{id: 1, value: 10}, {id: 2, value: 20}],
6071
+ * item => item.value,
6072
+ * ); // 20
6073
+ *
6074
+ * max([], item => item.value); // Number.NaN
6075
+ * ```
6076
+ *
4326
6077
  * @param items List of items
4327
6078
  * @param callback Callback to get an item's value
4328
6079
  * @returns Maximum value, or `NaN` if no maximum can be found
@@ -4330,6 +6081,17 @@ declare const logger: Logger;
4330
6081
  declare function max<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): number;
4331
6082
  /**
4332
6083
  * Get the maximum value from a list of items
6084
+ *
6085
+ * @example
6086
+ * ```typescript
6087
+ * max(
6088
+ * [{id: 1, value: 10}, {id: 2, value: 20}],
6089
+ * 'value',
6090
+ * ); // 20
6091
+ *
6092
+ * max([], 'value'); // Number.NaN
6093
+ * ```
6094
+ *
4333
6095
  * @param items List of items
4334
6096
  * @param key Key to use for value
4335
6097
  * @returns Maximum value, or `NaN` if no maximum can be found
@@ -4337,6 +6099,13 @@ declare function max<Item>(items: Item[], callback: (item: Item, index: number,
4337
6099
  declare function max<Item extends PlainObject, ItemKey extends keyof NumericalValues<Item>>(items: Item[], key: ItemKey): number;
4338
6100
  /**
4339
6101
  * Get the maximum value from a list of numbers
6102
+ *
6103
+ * @example
6104
+ * ```typescript
6105
+ * max([10, 20]); // 20
6106
+ * max([]); // Number.NaN
6107
+ * ```
6108
+ *
4340
6109
  * @param values List of numbers
4341
6110
  * @returns Maximum value, or `NaN` if no maximum can be found
4342
6111
  */
@@ -5654,4 +7423,4 @@ declare class SizedSet<Value = unknown> extends Set<Value> {
5654
7423
  get(value: Value, update?: boolean): Value | undefined;
5655
7424
  }
5656
7425
  //#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 };
7426
+ 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 };