@vinicunca/perkakas 0.0.11 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,27 +1,29 @@
1
+ import { IsAny, ReadonlyTuple, MergeDeep } from 'type-fest';
2
+
1
3
  /**
2
4
  * Using event.code is not predictable since each machine may have different output
3
5
  */
4
6
  declare const KEY_CODES: {
5
- readonly TAB: "Tab";
7
+ readonly ALT: "Alt";
6
8
  readonly ARROW_DOWN: "ArrowDown";
7
- readonly ARROW_UP: "ArrowUp";
8
9
  readonly ARROW_LEFT: "ArrowLeft";
9
10
  readonly ARROW_RIGHT: "ArrowRight";
11
+ readonly ARROW_UP: "ArrowUp";
12
+ readonly AT: "@";
13
+ readonly BACKSPACE: "Backspace";
14
+ readonly CTRL: "Control";
15
+ readonly DELETE: "Delete";
16
+ readonly END: "End";
10
17
  readonly ENTER: "Enter";
11
18
  readonly ESC: "Escape";
12
- readonly SPACE: "Space";
13
- readonly SHIFT: "Shift";
19
+ readonly HOME: "Home";
14
20
  readonly KEY_F: "KEY_F";
15
- readonly CTRL: "Control";
16
- readonly ALT: "Alt";
17
21
  readonly META: "Meta";
18
- readonly AT: "@";
19
- readonly DELETE: "Delete";
20
- readonly BACKSPACE: "Backspace";
21
- readonly HOME: "Home";
22
- readonly END: "End";
23
- readonly PAGE_UP: "PageUp";
24
22
  readonly PAGE_DOWN: "PageDown";
23
+ readonly PAGE_UP: "PageUp";
24
+ readonly SHIFT: "Shift";
25
+ readonly SPACE: "Space";
26
+ readonly TAB: "Tab";
25
27
  };
26
28
 
27
29
  /**
@@ -90,7 +92,7 @@ declare function anyPass<T>(fns: ReadonlyArray<(data: T) => boolean>): (data: T)
90
92
 
91
93
  type Pred<T, K> = (input: T) => K;
92
94
  type PredIndexed<T, K> = (input: T, index: number, array: Array<T>) => K;
93
- type PredIndexedOptional<T, K> = (input: T, index?: number, array?: Array<T>) => K;
95
+ type PredIndexedOptional<T, K> = (input: T, index?: number, array?: ReadonlyArray<T>) => K;
94
96
  type NonEmptyArray<T> = [T, ...Array<T>];
95
97
  /**
96
98
  * This should only be used for defining generics which extend any kind of JS
@@ -104,9 +106,17 @@ type NonEmptyArray<T> = [T, ...Array<T>];
104
106
  *
105
107
  * @see This was inspired by the type-definition of Promise.all (https://github.com/microsoft/TypeScript/blob/1df5717b120cddd325deab8b0f2b2c3eecaf2b01/src/lib/es2015.promise.d.ts#L21)
106
108
  */
107
- type IterableContainer<T = unknown> = ReadonlyArray<T> | [];
109
+ type IterableContainer<T = unknown> = [] | ReadonlyArray<T>;
110
+ type ObjectKeys$1<T extends object> = `${Exclude<keyof T, symbol>}`;
111
+ /**
112
+ * An extension of Extract for type predicates which falls back to the base
113
+ * in order to narrow the `unknown` case.
114
+ * @example
115
+ * function isMyType<T>(data: T | MyType): data is NarrowedTo<T, MyType> { ... }
116
+ */
117
+ type NarrowedTo<T, Base> = Extract<T, Base> extends never ? Base : IsAny<T> extends true ? Base : Extract<T, Base>;
108
118
 
109
- type Chunked<T extends IterableContainer> = T[number] extends never ? [] : T extends readonly [unknown, ...Array<unknown>] | readonly [...Array<unknown>, unknown] ? NonEmptyArray<NonEmptyArray<T[number]>> : Array<NonEmptyArray<T[number]>>;
119
+ type Chunked<T extends IterableContainer> = T[number] extends never ? [] : T extends readonly [...Array<unknown>, unknown] | readonly [unknown, ...Array<unknown>] ? NonEmptyArray<NonEmptyArray<T[number]>> : Array<NonEmptyArray<T[number]>>;
110
120
  /**
111
121
  * Split an array into groups the length of `size`. If `array` can't be split evenly, the final chunk will be the remaining elements.
112
122
  * @param array the array
@@ -143,7 +153,7 @@ declare function chunk<T extends IterableContainer>(size: number): (array: T) =>
143
153
  * @category Array
144
154
  * @pipeable
145
155
  */
146
- declare function compact<T>(items: ReadonlyArray<T | null | undefined | false | '' | 0>): Array<T>;
156
+ declare function compact<T>(items: ReadonlyArray<'' | 0 | T | false | null | undefined>): Array<T>;
147
157
 
148
158
  /**
149
159
  * Combines two arrays.
@@ -156,7 +166,7 @@ declare function compact<T>(items: ReadonlyArray<T | null | undefined | false |
156
166
  * @dataFirst
157
167
  * @category Array
158
168
  */
159
- declare function concat<T, K>(arr1: ReadonlyArray<T>, arr2: ReadonlyArray<K>): Array<T | K>;
169
+ declare function concat<T, K>(arr1: ReadonlyArray<T>, arr2: ReadonlyArray<K>): Array<K | T>;
160
170
  /**
161
171
  * Combines two arrays.
162
172
  * @param arr2 the second array
@@ -167,7 +177,7 @@ declare function concat<T, K>(arr1: ReadonlyArray<T>, arr2: ReadonlyArray<K>): A
167
177
  * @dataLast
168
178
  * @category Array
169
179
  */
170
- declare function concat<T, K>(arr2: ReadonlyArray<K>): (arr1: ReadonlyArray<T>) => Array<T | K>;
180
+ declare function concat<T, K>(arr2: ReadonlyArray<K>): (arr1: ReadonlyArray<T>) => Array<K | T>;
171
181
 
172
182
  /**
173
183
  * Counts how many values of the collection pass the specified predicate.
@@ -188,23 +198,23 @@ declare namespace countBy {
188
198
  function indexed<T>(fn: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => number;
189
199
  }
190
200
 
191
- type LazyResult<T> = LazyEmpty | LazyNext<T> | LazyMany<T>;
201
+ type LazyResult<T> = LazyEmpty | LazyMany<T> | LazyNext<T>;
192
202
  interface LazyEmpty {
193
203
  done: boolean;
194
- hasNext: false;
195
204
  hasMany?: false | undefined;
205
+ hasNext: false;
196
206
  next?: undefined;
197
207
  }
198
208
  interface LazyNext<T> {
199
209
  done: boolean;
200
- hasNext: true;
201
210
  hasMany?: false | undefined;
211
+ hasNext: true;
202
212
  next: T;
203
213
  }
204
214
  interface LazyMany<T> {
205
215
  done: boolean;
206
- hasNext: true;
207
216
  hasMany: true;
217
+ hasNext: true;
208
218
  next: Array<T>;
209
219
  }
210
220
 
@@ -302,6 +312,7 @@ declare namespace difference {
302
312
  declare function dropLast<T>(array: ReadonlyArray<T>, n: number): Array<T>;
303
313
  /**
304
314
  * Removes last `n` elements from the `array`.
315
+ * @param array the target array
305
316
  * @param n the number of elements to skip
306
317
  * @signature
307
318
  * P.dropLast(n)(array)
@@ -327,6 +338,7 @@ declare function dropLast<T>(n: number): (array: ReadonlyArray<T>) => Array<T>;
327
338
  declare function drop<T>(array: ReadonlyArray<T>, n: number): Array<T>;
328
339
  /**
329
340
  * Removes first `n` elements from the `array`.
341
+ * @param array the target array
330
342
  * @param n the number of elements to skip
331
343
  * @signature
332
344
  * P.drop(n)(array)
@@ -341,6 +353,142 @@ declare namespace drop {
341
353
  function lazy<T>(n: number): (value: T) => LazyResult<T>;
342
354
  }
343
355
 
356
+ declare const COMPARATORS: {
357
+ readonly asc: <T>(x: T, y: T) => boolean;
358
+ readonly desc: <T_1>(x: T_1, y: T_1) => boolean;
359
+ };
360
+ /**
361
+ * An order rule defines a projection/extractor that returns a comparable from
362
+ * the data being compared. It would be run on each item being compared, and a
363
+ * comparator would then be used on the results to determine the order.
364
+ *
365
+ * There are 2 forms of the order rule, a simple one which only provides the
366
+ * projection function and assumes ordering is ascending, and a 2-tuple where
367
+ * the first element is the projection function and the second is the direction;
368
+ * this allows changing the direction without defining a more complex projection
369
+ * to simply negate the value (e.g. `(x) => -x`).
370
+ *
371
+ * We rely on the javascript implementation of `<` and `>` for comparison, which
372
+ * will attempt to transform both operands into a primitive comparable value via
373
+ * the built in `valueOf` function (and then `toString`). It's up to the caller
374
+ * to make sure that the projection is returning a value that makes sense for
375
+ * this logic.
376
+ *
377
+ * It's important to note that there is no built-in caching/memoization of
378
+ * projection function and therefore no guarantee that it would only be called
379
+ * once.
380
+ */
381
+ type OrderRule<T> = Projection<T> | readonly [projection: Projection<T>, direction: keyof typeof COMPARATORS];
382
+ type Projection<T> = (x: T) => Comparable$1;
383
+ type Comparable$1 = {
384
+ [Symbol.toPrimitive](hint: string): ComparablePrimitive$1;
385
+ } | {
386
+ toString(): string;
387
+ } | {
388
+ valueOf(): ComparablePrimitive$1;
389
+ } | ComparablePrimitive$1;
390
+ type ComparablePrimitive$1 = boolean | number | string;
391
+
392
+ /**
393
+ * Drop the first `n` items from `data` based on the provided ordering criteria.
394
+ * This allows you to avoid sorting the array before dropping the items.
395
+ * The complexity of this function is *O(Nlogn)* where `N` is the length of the array.
396
+ *
397
+ * For the opposite operation (to keep `n` elements) see `takeFirstBy`.
398
+ *
399
+ * @params data - the input array
400
+ * @params n - the number of items to drop. If `n` is non-positive no items would be dropped and a *clone* of the input would be returned, if `n` is bigger then data.length no items would be returned.
401
+ * @param rules - A variadic array of order rules defining the sorting criteria. Each order rule is a projection function that extracts a comparable value from the data. Sorting is based on these extracted values using the native `<` and `>` operators. Earlier rules take precedence over later ones. Use the syntax `[projection, "desc"]` for descending order.
402
+ * @returns a subset of the input array.
403
+ * @signature
404
+ * P.dropFirstBy(data, n, ...rules);
405
+ * @example
406
+ * P.dropFirstBy(['aa', 'aaaa', 'a', 'aaa'], 2, x => x.length); // => ['aaa', 'aaaa']
407
+ * @dataFirst
408
+ * @category Array
409
+ */
410
+ declare function dropFirstBy<T>(data: ReadonlyArray<T>, n: number, ...rules: Readonly<NonEmptyArray<OrderRule<T>>>): Array<T>;
411
+ /**
412
+ * Drop the first `n` items from `data` based on the provided ordering criteria. This allows you to avoid sorting the array before dropping the items. The complexity of this function is *O(Nlogn)* where `N` is the length of the array.
413
+ *
414
+ * For the opposite operation (to keep `n` elements) see `takeFirstBy`.
415
+ *
416
+ * @params data - the input array
417
+ * @params n - the number of items to drop. If `n` is non-positive no items would be dropped and a *clone* of the input would be returned, if `n` is bigger then data.length no items would be returned.
418
+ * @param rules - A variadic array of order rules defining the sorting criteria. Each order rule is a projection function that extracts a comparable value from the data. Sorting is based on these extracted values using the native `<` and `>` operators. Earlier rules take precedence over later ones. Use the syntax `[projection, "desc"]` for descending order.
419
+ * @returns a subset of the input array.
420
+ * @signature
421
+ * P.dropFirstBy(n, ...rules)(data);
422
+ * @example
423
+ * P.pipe(['aa', 'aaaa', 'a', 'aaa'], P.dropFirstBy(2, x => x.length)); // => ['aaa', 'aaaa']
424
+ * @dataLast
425
+ * @category Array
426
+ */
427
+ declare function dropFirstBy<T>(n: number, ...rules: Readonly<NonEmptyArray<OrderRule<T>>>): (data: ReadonlyArray<T>) => Array<T>;
428
+
429
+ /**
430
+ * Removes elements from the end of the array until the predicate returns false.
431
+ *
432
+ * The predicate is applied to each element in the array starting from the end and moving towards the beginning, until the predicate returns false. The returned array includes elements from the beginning of the array, up to and including the element that produced false for the predicate.
433
+ *
434
+ * @param data the array
435
+ * @param predicate the predicate
436
+ * @signature
437
+ * P.dropLastWhile(data, predicate)
438
+ * @example
439
+ * P.dropLastWhile([1, 2, 10, 3, 4], x => x < 10) // => [1, 2, 10]
440
+ * @dataFirst
441
+ * @category Array
442
+ */
443
+ declare function dropLastWhile<T>(data: ReadonlyArray<T>, predicate: (item: T) => boolean): Array<T>;
444
+ /**
445
+ * Removes elements from the end of the array until the predicate returns false.
446
+ *
447
+ * The predicate is applied to each element in the array starting from the end and moving towards the beginning, until the predicate returns false. The returned array includes elements from the beginning of the array, up to and including the element that produced false for the predicate.
448
+ *
449
+ * @param predicate the predicate
450
+ * @signature
451
+ * P.dropLastWhile(predicate)(data)
452
+ * @example
453
+ * P.pipe([1, 2, 10, 3, 4], P.dropLastWhile(x => x < 10)) // => [1, 2, 10]
454
+ * @dataLast
455
+ * @category Array
456
+ */
457
+ declare function dropLastWhile<T>(predicate: (item: T) => boolean): (data: ReadonlyArray<T>) => Array<T>;
458
+
459
+ /**
460
+ * Removes elements from the beginning of the array until the predicate returns false.
461
+ *
462
+ * The predicate is applied to each element in the array,
463
+ * until the predicate returns false.
464
+ * The returned array includes the rest of the elements,
465
+ * starting with the element that produced false for the predicate.
466
+ *
467
+ * @param data the array
468
+ * @param predicate the predicate
469
+ * @signature
470
+ * P.dropWhile(data, predicate)
471
+ * @example
472
+ * P.dropWhile([1, 2, 10, 3, 4], x => x < 10) // => [10, 3, 4]
473
+ * @dataFirst
474
+ * @category Array
475
+ */
476
+ declare function dropWhile<T>(data: ReadonlyArray<T>, predicate: (item: T) => boolean): Array<T>;
477
+ /**
478
+ * Removes elements from the beginning of the array until the predicate returns false.
479
+ *
480
+ * The predicate is applied to each element in the array, until the predicate returns false. The returned array includes the rest of the elements, starting with the element that produced false for the predicate.
481
+ *
482
+ * @param predicate the predicate
483
+ * @signature
484
+ * P.dropWhile(predicate)(data)
485
+ * @example
486
+ * P.pipe([1, 2, 10, 3, 4], P.dropWhile(x => x < 10)) // => [10, 3, 4]
487
+ * @dataLast
488
+ * @category Array
489
+ */
490
+ declare function dropWhile<T>(predicate: (item: T) => boolean): (data: ReadonlyArray<T>) => Array<T>;
491
+
344
492
  /**
345
493
  * Filter the elements of an array that meet the condition specified in a callback function.
346
494
  * @param array The array to filter.
@@ -382,9 +530,9 @@ declare namespace filter {
382
530
  */
383
531
  function indexed<T, S extends T>(fn: (input: T, index: number, array: Array<T>) => input is S): (array: ReadonlyArray<T>) => Array<S>;
384
532
  function indexed<T>(fn: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => Array<T>;
385
- const lazy: <T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<T>;
386
- const lazyIndexed: (<T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<T>) & {
387
- indexed: true;
533
+ const lazy: <T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: readonly T[] | undefined) => LazyResult<T>;
534
+ const lazyIndexed: (<T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: readonly T[] | undefined) => LazyResult<T>) & {
535
+ readonly indexed: true;
388
536
  };
389
537
  }
390
538
 
@@ -435,20 +583,20 @@ declare namespace findIndex {
435
583
  } | {
436
584
  done: boolean;
437
585
  hasNext: boolean;
438
- next?: undefined;
586
+ next?: never;
439
587
  }) & {
440
588
  single: true;
441
589
  };
442
- const lazyIndexed: (<T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => {
590
+ const lazyIndexed: ((fn: PredIndexedOptional<unknown, boolean>) => (value: unknown, index?: number | undefined, array?: unknown[] | undefined) => {
443
591
  done: boolean;
444
592
  hasNext: boolean;
445
593
  next: number;
446
594
  } | {
447
595
  done: boolean;
448
596
  hasNext: boolean;
449
- next?: undefined;
597
+ next?: never;
450
598
  }) & {
451
- indexed: true;
599
+ readonly indexed: true;
452
600
  } & {
453
601
  single: true;
454
602
  };
@@ -587,18 +735,18 @@ declare namespace find {
587
735
  }) & {
588
736
  single: true;
589
737
  };
590
- const lazyIndexed: (<T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => {
738
+ const lazyIndexed: ((fn: PredIndexedOptional<unknown, boolean>) => (value: unknown, index?: number | undefined, array?: unknown[] | undefined) => {
591
739
  done: boolean;
592
740
  hasNext: boolean;
593
- next: T;
741
+ next: unknown;
594
742
  }) & {
595
- indexed: true;
743
+ readonly indexed: true;
596
744
  } & {
597
745
  single: true;
598
746
  };
599
747
  }
600
748
 
601
- type FirstOut<T extends IterableContainer> = T extends [] ? undefined : T extends readonly [unknown, ...Array<unknown>] ? T[0] : T extends readonly [...infer Pre, infer Last] ? Pre[0] | Last : T[0] | undefined;
749
+ type FirstOut<T extends IterableContainer> = T extends [] ? undefined : T extends readonly [unknown, ...Array<unknown>] ? T[0] : T extends readonly [...infer Pre, infer Last] ? Last | Pre[0] : T[0] | undefined;
602
750
  /**
603
751
  * Gets the first element of `array`.
604
752
  * Note: In `pipe`, use `first()` form instead of `first`. Otherwise, the inferred type is lost.
@@ -631,6 +779,60 @@ declare namespace first {
631
779
  }
632
780
  }
633
781
 
782
+ type FirstBy<T extends IterableContainer> = (T extends readonly [unknown, ...ReadonlyArray<unknown>] ? never : T extends readonly [...ReadonlyArray<unknown>, unknown] ? never : undefined) | T[number];
783
+ /**
784
+ * Find the first element in the array that adheres to the order rules provided. This is a superset of what a typical `maxBy` or `minBy` function would do as it allows defining "tie-breaker" rules when values are equal, and allows comparing items using any logic. This function is equivalent to calling `P.first(P.sortBy(...))` but runs at *O(n)* instead of *O(nlogn)*.
785
+ *
786
+ * Use `nthBy` if you need an element other that the first, or `takeFirstBy` if you more than just the first element.
787
+ *
788
+ * @param data an array of items
789
+ * @param rules - A variadic array of order rules defining the sorting criteria. Each order rule is a projection function that extracts a comparable value from the data. Sorting is based on these extracted values using the native `<` and `>` operators. Earlier rules take precedence over later ones. Use the syntax `[projection, "desc"]` for descending ordeP.
790
+ * @returns the first element by the order criteria, or `undefined` if the array
791
+ * is empty. (The function provides strong typing if the input type assures the
792
+ * array isn't empty).
793
+ * @signature
794
+ * P.firstBy(...rules)(data);
795
+ * @example
796
+ * const max = P.pipe([1,2,3], P.firstBy([P.identity, "desc"])); // => 3;
797
+ * const min = P.pipe([1,2,3], P.firstBy([1,2,3])); // => 1;
798
+ *
799
+ * const data = [{ a: "a" }, { a: "aa" }, { a: "aaa" }] as const;
800
+ * const maxBy = P.pipe(data, P.firstBy([(item) => item.a.length, "desc"])); // => { a: "aaa" };
801
+ * const minBy = P.pipe(data, P.firstBy((item) => item.a.length)); // => { a: "a" };
802
+ *
803
+ * const data = [{type: "cat", size: 1}, {type: "cat", size: 2}, {type: "dog", size: 3}] as const;
804
+ * const multi = P.pipe(data, P.firstBy(P.prop('type'), [P.prop('size'), 'desc'])); // => {type: "cat", size: 2}
805
+ * @dataLast
806
+ * @category Array
807
+ */
808
+ declare function firstBy<T extends IterableContainer>(...rules: Readonly<NonEmptyArray<OrderRule<T[number]>>>): (data: T) => FirstBy<T>;
809
+ /**
810
+ * Find the first element in the array that adheres to the order rules provided. This is a superset of what a typical `maxBy` or `minBy` function would do as it allows defining "tie-breaker" rules when values are equal, and allows comparing items using any logic. This function is equivalent to calling `P.first(P.sortBy(...))` but runs at *O(n)* instead of *O(nlogn)*.
811
+ *
812
+ * Use `nthBy` if you need an element other that the first, or `takeFirstBy` if you more than just the first element.
813
+ *
814
+ * @param data an array of items
815
+ * @param rules - A variadic array of order rules defining the sorting criteria. Each order rule is a projection function that extracts a comparable value from the data. Sorting is based on these extracted values using the native `<` and `>` operators. Earlier rules take precedence over later ones. Use the syntax `[projection, "desc"]` for descending ordeP.
816
+ * @returns the first element by the order criteria, or `undefined` if the array
817
+ * is empty. (The function provides strong typing if the input type assures the
818
+ * array isn't empty).
819
+ * @signature
820
+ * P.firstBy(data, ...rules);
821
+ * @example
822
+ * const max = P.firstBy([1,2,3], [P.identity, "desc"]); // => 3;
823
+ * const min = P.firstBy([1,2,3], P.identity); // => 1;
824
+ *
825
+ * const data = [{ a: "a" }, { a: "aa" }, { a: "aaa" }] as const;
826
+ * const maxBy = P.firstBy(data, [(item) => item.a.length, "desc"]); // => { a: "aaa" };
827
+ * const minBy = P.firstBy(data, (item) => item.a.length); // => { a: "a" };
828
+ *
829
+ * const data = [{type: "cat", size: 1}, {type: "cat", size: 2}, {type: "dog", size: 3}] as const;
830
+ * const multi = P.firstBy(data, P.prop('type'), [P.prop('size'), 'desc']); // => {type: "cat", size: 2}
831
+ * @dataFirst
832
+ * @category Array
833
+ */
834
+ declare function firstBy<T extends IterableContainer>(data: T, ...rules: Readonly<NonEmptyArray<OrderRule<T[number]>>>): FirstBy<T>;
835
+
634
836
  /**
635
837
  * Map each element of an array into an object using a defined callback function and flatten the result.
636
838
  * @param array The array to map.
@@ -693,7 +895,7 @@ declare namespace flatMapToObj {
693
895
  * @pipeable
694
896
  * @category Array
695
897
  */
696
- declare function flatMap<T, K>(array: ReadonlyArray<T>, fn: (input: T) => K | Array<K>): Array<K>;
898
+ declare function flatMap<T, K>(array: ReadonlyArray<T>, fn: (input: T) => K | ReadonlyArray<K>): Array<K>;
697
899
  /**
698
900
  * Map each element of an array using a defined callback function and flatten the mapped result.
699
901
  * @param fn The function mapper.
@@ -705,18 +907,18 @@ declare function flatMap<T, K>(array: ReadonlyArray<T>, fn: (input: T) => K | Ar
705
907
  * @pipeable
706
908
  * @category Array
707
909
  */
708
- declare function flatMap<T, K>(fn: (input: T) => K | Array<K>): (array: ReadonlyArray<T>) => Array<K>;
910
+ declare function flatMap<T, K>(fn: (input: T) => K | ReadonlyArray<K>): (array: ReadonlyArray<T>) => Array<K>;
709
911
  declare namespace flatMap {
710
- function lazy<T, K>(fn: (input: T) => K | Array<K>): (value: T) => {
912
+ function lazy<T, K>(fn: (input: T) => K | ReadonlyArray<K>): (value: T) => {
711
913
  done: boolean;
712
- hasNext: boolean;
713
914
  hasMany: boolean;
714
- next: K[];
915
+ hasNext: boolean;
916
+ next: K & any[];
715
917
  } | {
716
918
  done: boolean;
717
919
  hasNext: boolean;
718
- next: K;
719
- hasMany?: undefined;
920
+ next: K | readonly K[];
921
+ hasMany?: never;
720
922
  };
721
923
  }
722
924
 
@@ -814,18 +1016,18 @@ declare function forEach<T>(fn: Pred<T, void>): (array: ReadonlyArray<T>) => Arr
814
1016
  declare namespace forEach {
815
1017
  function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, void>): Array<T>;
816
1018
  function indexed<T>(fn: PredIndexed<T, void>): (array: ReadonlyArray<T>) => Array<T>;
817
- const lazy: <T>(fn: PredIndexedOptional<T, void>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<T>;
818
- const lazyIndexed: (<T>(fn: PredIndexedOptional<T, void>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<T>) & {
819
- indexed: true;
1019
+ const lazy: <T>(fn: PredIndexedOptional<T, void>) => (value: T, index?: number | undefined, array?: readonly T[] | undefined) => LazyResult<T>;
1020
+ const lazyIndexed: (<T>(fn: PredIndexedOptional<T, void>) => (value: T, index?: number | undefined, array?: readonly T[] | undefined) => LazyResult<T>) & {
1021
+ readonly indexed: true;
820
1022
  };
821
1023
  }
822
1024
 
823
- interface Strict$5 {
1025
+ interface Strict$7 {
824
1026
  <Value, Key extends PropertyKey = PropertyKey>(items: ReadonlyArray<Value>, fn: (item: Value) => Key | undefined): StrictOut$2<Value, Key>;
825
1027
  <Value, Key extends PropertyKey = PropertyKey>(fn: (item: Value) => Key | undefined): (items: ReadonlyArray<Value>) => StrictOut$2<Value, Key>;
826
1028
  readonly indexed: {
827
- <Value, Key extends PropertyKey = PropertyKey>(items: ReadonlyArray<Value>, fn: PredIndexed<Value, Key | undefined>): StrictOut$2<Value, Key>;
828
1029
  <Value, Key extends PropertyKey = PropertyKey>(fn: PredIndexed<Value, Key | undefined>): (items: ReadonlyArray<Value>) => StrictOut$2<Value, Key>;
1030
+ <Value, Key extends PropertyKey = PropertyKey>(items: ReadonlyArray<Value>, fn: PredIndexed<Value, Key | undefined>): StrictOut$2<Value, Key>;
829
1031
  };
830
1032
  }
831
1033
  type StrictOut$2<Value, Key extends PropertyKey = PropertyKey> = string extends Key ? Record<Key, NonEmptyArray<Value>> : number extends Key ? Record<Key, NonEmptyArray<Value>> : symbol extends Key ? Record<Key, NonEmptyArray<Value>> : Partial<Record<Key, NonEmptyArray<Value>>>;
@@ -851,9 +1053,54 @@ declare function groupBy<T>(fn: (item: T) => PropertyKey | undefined): (array: R
851
1053
  declare namespace groupBy {
852
1054
  function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, PropertyKey | undefined>): Record<string, NonEmptyArray<T>>;
853
1055
  function indexed<T>(fn: PredIndexed<T, PropertyKey | undefined>): (array: ReadonlyArray<T>) => Record<string, NonEmptyArray<T>>;
854
- const strict: Strict$5;
1056
+ const strict: Strict$7;
855
1057
  }
856
1058
 
1059
+ type ArrayMinN<T, N extends number> = number extends N ? Array<T> : N extends 0 ? Array<T> : [...ReadonlyTuple<T, N>, ...Array<T>];
1060
+ /**
1061
+ * Checks if the given array has at least the defined number of elements, and
1062
+ * refines the output type accordingly so that those indices are defined when
1063
+ * accessing the array even when using typescript's 'noUncheckedIndexAccess'.
1064
+ *
1065
+ * @param data the input array
1066
+ * @param minimum the minimum number of elements the array must have
1067
+ * @return true if the array's length is *at least* `minimum`.
1068
+ * @signature
1069
+ * P.hasAtLeast(data, minimum)
1070
+ * @example
1071
+ * P.hasAtLeast([], 4); // => false
1072
+ *
1073
+ * const data: number[] = [1,2,3,4];
1074
+ * P.hasAtLeast(data, 1); // => true
1075
+ * data[0]; // 1, with type `number`
1076
+ * @dataFirst
1077
+ * @category Array
1078
+ */
1079
+ declare function hasAtLeast<T, N extends number>(data: ReadonlyArray<T>, minimum: N): data is ArrayMinN<T, N>;
1080
+ /**
1081
+ * Checks if the given array has at least the defined number of elements, and
1082
+ * refines the output type accordingly so that those indices are defined when
1083
+ * accessing the array even when using typescript's 'noUncheckedIndexAccess'.
1084
+ *
1085
+ * @param data the input array
1086
+ * @param minimum the minimum number of elements the array must have
1087
+ * @return true if the array's length is *at least* `minimum`.
1088
+ * @signature
1089
+ * P.hasAtLeast(minimum)(data)
1090
+ * @example
1091
+ * P.pipe([], P.hasAtLeast(4)); // => false
1092
+ *
1093
+ * const data = [[1,2], [3], [4,5]];
1094
+ * P.pipe(
1095
+ * data,
1096
+ * P.filter(P.hasAtLeast(2)),
1097
+ * P.map(([, second]) => second),
1098
+ * ); // => [2,5], with type `number[]`
1099
+ * @dataLast
1100
+ * @category Array
1101
+ */
1102
+ declare function hasAtLeast<N extends number>(minimum: N): <T>(data: ReadonlyArray<T>) => data is ArrayMinN<T, N>;
1103
+
857
1104
  /**
858
1105
  * Converts a list of objects into an object indexing the objects by the given key.
859
1106
  * @param array the array
@@ -968,9 +1215,9 @@ declare namespace intersectionWith {
968
1215
  function lazy<TFirst, TSecond>(other: Array<TSecond>, comparator: Comparator<TFirst, TSecond>): (value: TFirst) => LazyResult<TFirst>;
969
1216
  }
970
1217
 
971
- type Joinable = bigint | boolean | number | string | null | undefined;
1218
+ type Joinable = bigint | boolean | null | number | string | undefined;
972
1219
  type Joined<T extends IterableContainer, Glue extends string> = T[number] extends never ? '' : T extends readonly [Joinable?] ? `${NullishCoalesce<T[0], ''>}` : T extends readonly [infer First, ...infer Tail] ? `${NullishCoalesce<First, ''>}${Glue}${Joined<Tail, Glue>}` : T extends readonly [...infer Head, infer Last] ? `${Joined<Head, Glue>}${Glue}${NullishCoalesce<Last, ''>}` : string;
973
- type NullishCoalesce<T, Fallback> = T extends Joinable ? T extends undefined | null ? NonNullable<T> | Fallback : T : never;
1220
+ type NullishCoalesce<T, Fallback> = T extends Joinable ? T extends null | undefined ? Fallback | NonNullable<T> : T : never;
974
1221
  /**
975
1222
  * Joins the elements of the array by: casting them to a string and
976
1223
  * concatenating them one to the other, with the provided glue string in between
@@ -990,7 +1237,7 @@ type NullishCoalesce<T, Fallback> = T extends Joinable ? T extends undefined | n
990
1237
  * @dataFirst
991
1238
  * @category Array
992
1239
  */
993
- declare function join<T extends ReadonlyArray<Joinable> | [], Glue extends string>(data: T, glue: Glue): Joined<T, Glue>;
1240
+ declare function join<T extends [] | ReadonlyArray<Joinable>, Glue extends string>(data: T, glue: Glue): Joined<T, Glue>;
994
1241
  /**
995
1242
  * Joins the elements of the array by: casting them to a string and
996
1243
  * concatenating them one to the other, with the provided glue string in between
@@ -1009,7 +1256,7 @@ declare function join<T extends ReadonlyArray<Joinable> | [], Glue extends strin
1009
1256
  * @dataLast
1010
1257
  * @category Array
1011
1258
  */
1012
- declare function join<T extends ReadonlyArray<Joinable> | [], Glue extends string>(glue: Glue): (data: T) => Joined<T, Glue>;
1259
+ declare function join<T extends [] | ReadonlyArray<Joinable>, Glue extends string>(glue: Glue): (data: T) => Joined<T, Glue>;
1013
1260
 
1014
1261
  /**
1015
1262
  * Gets the last element of `array`.
@@ -1047,7 +1294,7 @@ type Enumerable<T> = ArrayLike<T> | Iterable<T>;
1047
1294
  declare function length<T>(items: Enumerable<T>): number;
1048
1295
  declare function length<T>(): (items: Enumerable<T>) => number;
1049
1296
 
1050
- interface Strict$4 {
1297
+ interface Strict$6 {
1051
1298
  <T extends IterableContainer, K>(items: T, mapper: Pred<T[number], K>): StrictOut$1<T, K>;
1052
1299
  <T extends IterableContainer, K>(mapper: Pred<T[number], K>): (items: T) => StrictOut$1<T, K>;
1053
1300
  readonly indexed: {
@@ -1099,11 +1346,11 @@ declare function map<T, K>(fn: Pred<T, K>): (array: ReadonlyArray<T>) => Array<K
1099
1346
  declare namespace map {
1100
1347
  function indexed<T, K>(array: ReadonlyArray<T>, fn: PredIndexed<T, K>): Array<K>;
1101
1348
  function indexed<T, K>(fn: PredIndexed<T, K>): (array: ReadonlyArray<T>) => Array<K>;
1102
- const lazy: <T, K>(fn: PredIndexedOptional<T, K>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<K>;
1103
- const lazyIndexed: (<T, K>(fn: PredIndexedOptional<T, K>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<K>) & {
1104
- indexed: true;
1349
+ const lazy: <T, K>(fn: PredIndexedOptional<T, K>) => (value: T, index?: number | undefined, array?: readonly T[] | undefined) => LazyResult<K>;
1350
+ const lazyIndexed: (<T, K>(fn: PredIndexedOptional<T, K>) => (value: T, index?: number | undefined, array?: readonly T[] | undefined) => LazyResult<K>) & {
1351
+ readonly indexed: true;
1105
1352
  };
1106
- const strict: Strict$4;
1353
+ const strict: Strict$6;
1107
1354
  }
1108
1355
 
1109
1356
  /**
@@ -1121,7 +1368,7 @@ declare namespace map {
1121
1368
  * @indexed
1122
1369
  * @category Array
1123
1370
  */
1124
- declare function mapToObj<T, K extends keyof any, V>(array: ReadonlyArray<T>, fn: (element: T) => [K, V]): Record<K, V>;
1371
+ declare function mapToObj<T, K extends PropertyKey, V>(array: ReadonlyArray<T>, fn: (element: T) => [K, V]): Record<K, V>;
1125
1372
  /**
1126
1373
  * Map each element of an array into an object using a defined callback function.
1127
1374
  * @param fn The mapping function, which should return a tuple of [key, value], similar to Object.fromEntries
@@ -1142,10 +1389,10 @@ declare function mapToObj<T, K extends keyof any, V>(array: ReadonlyArray<T>, fn
1142
1389
  * @indexed
1143
1390
  * @category Array
1144
1391
  */
1145
- declare function mapToObj<T, K extends keyof any, V>(fn: (element: T) => [K, V]): (array: ReadonlyArray<T>) => Record<K, V>;
1392
+ declare function mapToObj<T, K extends PropertyKey, V>(fn: (element: T) => [K, V]): (array: ReadonlyArray<T>) => Record<K, V>;
1146
1393
  declare namespace mapToObj {
1147
- function indexed<T, K extends keyof any, V>(array: ReadonlyArray<T>, fn: (element: T, index: number, array: ReadonlyArray<T>) => [K, V]): Record<K, V>;
1148
- function indexed<T, K extends keyof any, V>(fn: (element: T, index: number, array: ReadonlyArray<T>) => [K, V]): (array: ReadonlyArray<T>) => Record<K, V>;
1394
+ function indexed<T, K extends PropertyKey, V>(array: ReadonlyArray<T>, fn: (element: T, index: number, array: ReadonlyArray<T>) => [K, V]): Record<K, V>;
1395
+ function indexed<T, K extends PropertyKey, V>(fn: (element: T, index: number, array: ReadonlyArray<T>) => [K, V]): (array: ReadonlyArray<T>) => Record<K, V>;
1149
1396
  }
1150
1397
 
1151
1398
  /**
@@ -1278,6 +1525,83 @@ declare namespace minBy {
1278
1525
  function indexed<T>(fn: PredIndexed<T, number>): (array: ReadonlyArray<T>) => T | undefined;
1279
1526
  }
1280
1527
 
1528
+ /**
1529
+ * Retrieves the element that would be at the given index if the array were sorted according to specified rules.
1530
+ * This function uses the *QuickSelect* algorithm running at an average complexity of *O(n)*.
1531
+ * Semantically it is equivalent to `sortBy(data, ...rules).at(index)` which would run at *O(nlogn)*.
1532
+ *
1533
+ * See also `firstBy` which provides an even more efficient algorithm and a stricter return type,
1534
+ * but only for `index === 0`.
1535
+ * See `takeFirstBy` to get all the elements up to and including `index`.
1536
+ *
1537
+ * @param data - The input array.
1538
+ * @param index - The zero-based index for selecting the element in the sorted order. Negative indices count backwards from the end.
1539
+ * @param rules - A variadic array of order rules defining the sorting criteria. Each order rule is a projection function that extracts a comparable value from the data. Sorting is based on these extracted values using the native `<` and `>` operators. Earlier rules take precedence over later ones. Use the syntax `[projection, "desc"]` for descending order.
1540
+ * @returns The element at the specified index in the sorted order, or `undefined` if the index is out of bounds.
1541
+ * @signature
1542
+ * P.nthBy(data, index, ...rules);
1543
+ * @example
1544
+ * P.nthBy([2,1,4,5,3,], 2, identity); // => 3
1545
+ * @dataFirst
1546
+ * @category Array
1547
+ */
1548
+ declare function nthBy<T extends IterableContainer>(data: T, index: number, ...rules: Readonly<NonEmptyArray<OrderRule<T[number]>>>): T[number] | undefined;
1549
+ /**
1550
+ * Retrieves the element that would be at the given index if the array were sorted according to specified rules.
1551
+ * This function uses the *QuickSelect* algorithm running at an average complexity of *O(n)*.
1552
+ * Semantically it is equivalent to `sortBy(data, ...rules)[index]` which would run at *O(nlogn)*.
1553
+ *
1554
+ * See also `firstBy` which provides an even more efficient algorithm and a stricter return type,
1555
+ * but only for `index === 0`.
1556
+ * See `takeFirstBy` to get all the elements up to and including `index`.
1557
+ *
1558
+ * @param data - The input array.
1559
+ * @param index - The zero-based index for selecting the element in the sorted order. Negative indices count backwards from the end.
1560
+ * @param rules - A variadic array of order rules defining the sorting criteria. Each order rule is a projection function that extracts a comparable value from the data. Sorting is based on these extracted values using the native `<` and `>` operators. Earlier rules take precedence over later ones. Use the syntax `[projection, "desc"]` for descending order.
1561
+ * @returns The element at the specified index in the sorted order, or `undefined` if the index is out of bounds.
1562
+ * @signature
1563
+ * P.nthBy(index, ...rules)(data);
1564
+ * @example
1565
+ * P.pipe([2,1,4,5,3,], P.nthBy(2, identity)); // => 3
1566
+ * @dataLast
1567
+ * @category Array
1568
+ */
1569
+ declare function nthBy<T extends IterableContainer>(index: number, ...rules: Readonly<NonEmptyArray<OrderRule<T[number]>>>): (data: T) => T[number] | undefined;
1570
+
1571
+ type Only<T extends IterableContainer> = T extends readonly [...Array<unknown>, unknown, unknown] | readonly [] | readonly [unknown, ...Array<unknown>, unknown] | readonly [unknown, unknown, ...Array<unknown>] ? undefined : T extends readonly [unknown] ? T[number] : T[number] | undefined;
1572
+ /**
1573
+ * Returns the first and only element of `array`, or undefined otherwise.
1574
+ * Note: In `pipe`, use `only()` form instead of `only`. Otherwise, the
1575
+ * inferred type is lost.
1576
+ * @param array the target array
1577
+ * @signature
1578
+ * P.only(array)
1579
+ * @example
1580
+ * P.only([]) // => undefined
1581
+ * P.only([1]) // => 1
1582
+ * P.only([1, 2]) // => undefined
1583
+ * @pipeable
1584
+ * @category Array
1585
+ * @dataFirst
1586
+ */
1587
+ declare function only<T extends IterableContainer>(array: Readonly<T>): Only<T>;
1588
+ /**
1589
+ * Returns the first and only element of `array`, or undefined otherwise.
1590
+ * Note: In `pipe`, use `only()` form instead of `only`. Otherwise, the
1591
+ * inferred type is lost.
1592
+ * @param array the target array
1593
+ * @signature
1594
+ * P.only(array)
1595
+ * @example
1596
+ * P.only([]) // => undefined
1597
+ * P.only([1]) // => 1
1598
+ * P.only([1, 2]) // => undefined
1599
+ * @pipeable
1600
+ * @category Array
1601
+ * @dataLast
1602
+ */
1603
+ declare function only<T extends IterableContainer>(): (array: Readonly<T>) => Only<T>;
1604
+
1281
1605
  /**
1282
1606
  * Splits a collection into two groups, the first of which contains elements the `predicate` type guard passes, and the second one containing the rest.
1283
1607
  * @param items the items to split
@@ -1359,6 +1683,45 @@ declare function range(start: number, end: number): Array<number>;
1359
1683
  */
1360
1684
  declare function range(end: number): (start: number) => Array<number>;
1361
1685
 
1686
+ /**
1687
+ * Calculates the rank of an item in an array based on `rules`. The rank is the position where the item would appear in the sorted array. This function provides an efficient way to determine the rank in *O(n)* time, compared to *O(nlogn)* for the equivalent `sortedIndex(sortBy(data, ...rules), item)`.
1688
+ *
1689
+ * @param data - The input array.
1690
+ * @param item - The item whose rank is to be determined.
1691
+ * @param rules - A variadic array of order rules defining the sorting criteria. Each order rule is a projection function that extracts a comparable value from the data. Sorting is based on these extracted values using the native `<` and `>` operators. Earlier rules take precedence over later ones. Use the syntax `[projection, "desc"]` for descending order.
1692
+ * @returns - The rank of the item in the sorted array in the range [0..data.length]
1693
+ * @signature
1694
+ * P.rankBy(data, item, ...rules)
1695
+ * @example
1696
+ * const DATA = [{ a: 5 }, { a: 1 }, { a: 3 }] as const;
1697
+ * P.rankBy(DATA, 0, P.prop('a')) // => 0
1698
+ * P.rankBy(DATA, 1, P.prop('a')) // => 1
1699
+ * P.rankBy(DATA, 2, P.prop('a')) // => 1
1700
+ * P.rankBy(DATA, 3, P.prop('a')) // => 2
1701
+ * @dataFirst
1702
+ * @category Array
1703
+ */
1704
+ declare function rankBy<T>(data: ReadonlyArray<T>, item: T, ...rules: Readonly<NonEmptyArray<OrderRule<T>>>): number;
1705
+ /**
1706
+ * Calculates the rank of an item in an array based on `rules`. The rank is the position where the item would appear in the sorted array. This function provides an efficient way to determine the rank in *O(n)* time, compared to *O(nlogn)* for the equivalent `sortedIndex(sortBy(data, ...rules), item)`.
1707
+ *
1708
+ * @param data - The input array.
1709
+ * @param item - The item whose rank is to be determined.
1710
+ * @param rules - A variadic array of order rules defining the sorting criteria. Each order rule is a projection function that extracts a comparable value from the data. Sorting is based on these extracted values using the native `<` and `>` operators. Earlier rules take precedence over later ones. Use the syntax `[projection, "desc"]` for descending order.
1711
+ * @returns - The rank of the item in the sorted array in the range [0..data.length]
1712
+ * @signature
1713
+ * P.rankBy(item, ...rules)(data)
1714
+ * @example
1715
+ * const DATA = [{ a: 5 }, { a: 1 }, { a: 3 }] as const;
1716
+ * P.pipe(DATA, P.rankBy(0, P.prop('a'))) // => 0
1717
+ * P.pipe(DATA, P.rankBy(1, P.prop('a'))) // => 1
1718
+ * P.pipe(DATA, P.rankBy(2, P.prop('a'))) // => 1
1719
+ * P.pipe(DATA, P.rankBy(3, P.prop('a'))) // => 2
1720
+ * @dataLast
1721
+ * @category Array
1722
+ */
1723
+ declare function rankBy<T>(item: T, ...rules: Readonly<NonEmptyArray<OrderRule<T>>>): (data: ReadonlyArray<T>) => number;
1724
+
1362
1725
  /**
1363
1726
  * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
1364
1727
  * @param items the array to reduce
@@ -1428,9 +1791,9 @@ declare function reject<T>(fn: Pred<T, boolean>): (items: ReadonlyArray<T>) => A
1428
1791
  declare namespace reject {
1429
1792
  function indexed<T, K>(array: ReadonlyArray<T>, fn: PredIndexed<T, boolean>): Array<K>;
1430
1793
  function indexed<T, K>(fn: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => Array<K>;
1431
- const lazy: <T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<T>;
1432
- const lazyIndexed: (<T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<T>) & {
1433
- indexed: true;
1794
+ const lazy: <T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: readonly T[] | undefined) => LazyResult<T>;
1795
+ const lazyIndexed: (<T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: readonly T[] | undefined) => LazyResult<T>) & {
1796
+ readonly indexed: true;
1434
1797
  };
1435
1798
  }
1436
1799
 
@@ -1532,7 +1895,7 @@ declare function shuffle<T>(items: ReadonlyArray<T>): Array<T>;
1532
1895
  */
1533
1896
  declare function shuffle<T>(): (items: ReadonlyArray<T>) => Array<T>;
1534
1897
 
1535
- interface Strict$3 {
1898
+ interface Strict$5 {
1536
1899
  <T extends IterableContainer>(items: T, cmp: (a: T[number], b: T[number]) => number): Sorted<T>;
1537
1900
  <T extends IterableContainer>(cmp: (a: T[number], b: T[number]) => number): (items: T) => Sorted<T>;
1538
1901
  }
@@ -1579,22 +1942,22 @@ declare function sort<T>(items: ReadonlyArray<T>, cmp: (a: T, b: T) => number):
1579
1942
  */
1580
1943
  declare function sort<T>(cmp: (a: T, b: T) => number): (items: ReadonlyArray<T>) => Array<T>;
1581
1944
  declare namespace sort {
1582
- const strict: Strict$3;
1945
+ const strict: Strict$5;
1583
1946
  }
1584
1947
 
1585
1948
  declare const ALL_DIRECTIONS: readonly ["asc", "desc"];
1586
1949
  type Direction = (typeof ALL_DIRECTIONS)[number];
1587
- type ComparablePrimitive = number | string | boolean;
1588
- type Comparable = ComparablePrimitive | {
1950
+ type ComparablePrimitive = boolean | number | string;
1951
+ type Comparable = {
1589
1952
  valueOf(): ComparablePrimitive;
1590
- };
1953
+ } | ComparablePrimitive;
1591
1954
  type SortProjection<T> = (x: T) => Comparable;
1592
1955
  type SortPair<T> = readonly [
1593
1956
  projector: SortProjection<T>,
1594
1957
  direction: Direction
1595
1958
  ];
1596
- type SortRule<T> = SortProjection<T> | SortPair<T>;
1597
- interface Strict$2 {
1959
+ type SortRule<T> = SortPair<T> | SortProjection<T>;
1960
+ interface Strict$4 {
1598
1961
  <T extends IterableContainer>(...sortRules: Readonly<NonEmptyArray<SortRule<T[number]>>>): (array: T) => SortedBy<T>;
1599
1962
  <T extends IterableContainer>(array: T, ...sortRules: Readonly<NonEmptyArray<SortRule<T[number]>>>): SortedBy<T>;
1600
1963
  }
@@ -1676,9 +2039,40 @@ declare function sortBy<T>(...sortRules: Readonly<NonEmptyArray<SortRule<T>>>):
1676
2039
  */
1677
2040
  declare function sortBy<T>(array: ReadonlyArray<T>, ...sortRules: Readonly<NonEmptyArray<SortRule<T>>>): Array<T>;
1678
2041
  declare namespace sortBy {
1679
- const strict: Strict$2;
2042
+ const strict: Strict$4;
1680
2043
  }
1681
2044
 
2045
+ /**
2046
+ * Removes elements from an array and, inserts new elements in their place.
2047
+ * @param items the array to splice.
2048
+ * @param start the index from which to start removing elements.
2049
+ * @param deleteCount the number of elements to remove.
2050
+ * @param replacement the elements to insert into the array in place of the deleted elements.
2051
+ * @signature
2052
+ * P.splice(items, start, deleteCount, replacement)
2053
+ * @example
2054
+ * P.splice([1,2,3,4,5,6,7,8], 2, 3, []); //=> [1,2,6,7,8]
2055
+ * P.splice([1,2,3,4,5,6,7,8], 2, 3, [9, 10]); //=> [1,2,9,10,6,7,8]
2056
+ * @dataFirst
2057
+ * @category Array
2058
+ */
2059
+ declare function splice<T>(items: ReadonlyArray<T>, start: number, deleteCount: number, replacement: ReadonlyArray<T>): Array<T>;
2060
+ /**
2061
+ * Removes elements from an array and, inserts new elements in their place.
2062
+ * @param items the array to splice.
2063
+ * @param start the index from which to start removing elements.
2064
+ * @param deleteCount the number of elements to remove.
2065
+ * @param replacement the elements to insert into the array in place of the deleted elements.
2066
+ * @signature
2067
+ * P.splice(start, deleteCount, replacement)(items)
2068
+ * @example
2069
+ * P.pipe([1,2,3,4,5,6,7,8], P.splice(2, 3, [])) // => [1,2,6,7,8]
2070
+ * P.pipe([1,2,3,4,5,6,7,8], P.splice(2, 3, [9, 10])) // => [1,2,9,10,6,7,8]
2071
+ * @dataLast
2072
+ * @category Array
2073
+ */
2074
+ declare function splice<T>(start: number, deleteCount: number, replacement: ReadonlyArray<T>): (items: ReadonlyArray<T>) => Array<T>;
2075
+
1682
2076
  /**
1683
2077
  * Splits a given array at a given index.
1684
2078
  * @param array the array to split
@@ -1861,6 +2255,47 @@ declare namespace take {
1861
2255
  function lazy<T>(n: number): (value: T) => LazyResult<T>;
1862
2256
  }
1863
2257
 
2258
+ /**
2259
+ * Take the first `n` items from `data` based on the provided ordering criteria.
2260
+ * This allows you to avoid sorting the array before taking the items.
2261
+ * The complexity of this function is *O(Nlogn)* where `N` is the length of the array.
2262
+ *
2263
+ * For the opposite operation (to drop `n` elements) see `dropFirstBy`.
2264
+ *
2265
+ * @params data - the input array
2266
+ * @params n - the number of items to take. If `n` is non-positive no items would be returned, if `n` is bigger then data.length a *clone* of `data` would be returned.
2267
+ * @param rules - A variadic array of order rules defining the sorting criteria.
2268
+ * Each order rule is a projection function that extracts a comparable value from the data. Sorting is based on these extracted values using the native `<` and `>` operators. Earlier rules take precedence over later ones. Use the syntax `[projection, "desc"]` for descending order.
2269
+ * @returns a subset of the input array.
2270
+ * @signature
2271
+ * P.takeFirstBy(data, n, ...rules);
2272
+ * @example
2273
+ * P.takeFirstBy(['aa', 'aaaa', 'a', 'aaa'], 2, x => x.length); // => ['a', 'aa']
2274
+ * @dataFirst
2275
+ * @category Array
2276
+ */
2277
+ declare function takeFirstBy<T>(data: ReadonlyArray<T>, n: number, ...rules: Readonly<NonEmptyArray<OrderRule<T>>>): Array<T>;
2278
+ /**
2279
+ * Take the first `n` items from `data` based on the provided ordering criteria.
2280
+ * This allows you to avoid sorting the array before taking the items.
2281
+ * The complexity of this function is *O(Nlogn)* where `N` is the length of the array.
2282
+ *
2283
+ * For the opposite operation (to drop `n` elements) see `dropFirstBy`.
2284
+ *
2285
+ * @params data - the input array
2286
+ * @params n - the number of items to take. If `n` is non-positive no items would be returned, if `n` is bigger then data.length a *clone* of `data` would be returned.
2287
+ * @param rules - A variadic array of order rules defining the sorting criteria.
2288
+ * Each order rule is a projection function that extracts a comparable value from the data. Sorting is based on these extracted values using the native `<` and `>` operators. Earlier rules take precedence over later ones. Use the syntax `[projection, "desc"]` for descending order.
2289
+ * @returns a subset of the input array.
2290
+ * @signature
2291
+ * P.takeFirstBy(n, ...rules)(data);
2292
+ * @example
2293
+ * R.pipe(['aa', 'aaaa', 'a', 'aaa'], P.takeFirstBy(2, x => x.length)); // => ['a', 'aa']
2294
+ * @dataLast
2295
+ * @category Array
2296
+ */
2297
+ declare function takeFirstBy<T>(n: number, ...rules: Readonly<NonEmptyArray<OrderRule<T>>>): (data: ReadonlyArray<T>) => Array<T>;
2298
+
1864
2299
  /**
1865
2300
  * Returns elements from the array until predicate returns false.
1866
2301
  * @param array the array
@@ -1905,7 +2340,7 @@ declare function takeWhile<T>(fn: (item: T) => boolean): (array: ReadonlyArray<T
1905
2340
  declare function uniq<T>(array: ReadonlyArray<T>): Array<T>;
1906
2341
  declare function uniq<T>(): (array: ReadonlyArray<T>) => Array<T>;
1907
2342
  declare namespace uniq {
1908
- function lazy(): (value: any) => LazyResult<any>;
2343
+ function lazy<T>(): (value: T) => LazyResult<T>;
1909
2344
  }
1910
2345
 
1911
2346
  declare function uniqBy<T, K>(array: ReadonlyArray<T>, transformer: (item: T) => K): Array<T>;
@@ -1931,7 +2366,7 @@ declare function uniqBy<T, K>(array: ReadonlyArray<T>, transformer: (item: T) =>
1931
2366
  declare function uniqBy<T, K>(transformer: (item: T) => K): (array: ReadonlyArray<T>) => Array<T>;
1932
2367
 
1933
2368
  type IsEquals<T> = (a: T, b: T) => boolean;
1934
- declare function _lazy<T>(isEquals: IsEquals<T>): (value: T, index?: number, array?: Array<T>) => LazyResult<T>;
2369
+ declare function _lazy<T>(isEquals: IsEquals<T>): (value: T, index?: number, array?: ReadonlyArray<T>) => LazyResult<T>;
1935
2370
  /**
1936
2371
  * Returns a new array containing only one copy of each element in the original list.
1937
2372
  * Elements are compared by custom comparator isEquals.
@@ -1968,35 +2403,59 @@ declare function uniqWith<T>(array: ReadonlyArray<T>, isEquals: IsEquals<T>): Ar
1968
2403
  declare function uniqWith<T>(isEquals: IsEquals<T>): (array: ReadonlyArray<T>) => Array<T>;
1969
2404
  declare namespace uniqWith {
1970
2405
  const lazy: typeof _lazy & {
1971
- indexed: true;
2406
+ readonly indexed: true;
1972
2407
  };
1973
2408
  }
1974
2409
 
2410
+ interface Strict$3 {
2411
+ <F extends IterableContainer, S extends IterableContainer>(first: F, second: S): Zip<F, S>;
2412
+ <S extends IterableContainer>(second: S): <F extends IterableContainer>(first: F) => Zip<F, S>;
2413
+ }
2414
+ type Zip<Left extends IterableContainer, Right extends IterableContainer> = Left extends readonly [] ? [] : Right extends readonly [] ? [] : Left extends readonly [infer LeftHead, ...infer LeftRest] ? Right extends readonly [infer RightHead, ...infer RightRest] ? [
2415
+ [LeftHead, RightHead],
2416
+ ...Zip<LeftRest, RightRest>
2417
+ ] : [
2418
+ [LeftHead, Right[number]],
2419
+ ...Zip<LeftRest, Right>
2420
+ ] : Right extends readonly [infer RightHead, ...infer RightRest] ? [[Left[number], RightHead], ...Zip<Left, RightRest>] : Array<[Left[number], Right[number]]>;
1975
2421
  /**
1976
2422
  * Creates a new list from two supplied lists by pairing up equally-positioned items.
1977
2423
  * The length of the returned list will match the shortest of the two inputs.
2424
+ *
2425
+ * If the input array are tuples, you can use the strict option
2426
+ * to get another tuple instead of a generic array type.
1978
2427
  * @param first the first input list
1979
2428
  * @param second the second input list
1980
2429
  * @signature
1981
2430
  * P.zip(first, second)
1982
2431
  * @example
1983
- * P.zip([1, 2], ['a', 'b']) // => [1, 'a'], [2, 'b']
2432
+ * P.zip([1, 2], ['a', 'b']) // => [[1, 'a'], [2, 'b']] (type: [number, string][])
2433
+ * P.zip.strict([1, 2] as const, ['a', 'b'] as const) // => [[1, 'a'], [2, 'b']] (type: [[1, 'a'], [2, 'b']])
1984
2434
  * @dataFirst
1985
2435
  * @category Array
2436
+ * @strict
1986
2437
  */
1987
2438
  declare function zip<F, S>(first: ReadonlyArray<F>, second: ReadonlyArray<S>): Array<[F, S]>;
1988
2439
  /**
1989
2440
  * Creates a new list from two supplied lists by pairing up equally-positioned items.
1990
2441
  * The length of the returned list will match the shortest of the two inputs.
2442
+ *
2443
+ * If the input array are tuples, you can use the strict option
2444
+ * to get another tuple instead of a generic array type.
1991
2445
  * @param second the second input list
1992
2446
  * @signature
1993
2447
  * P.zip(second)(first)
1994
2448
  * @example
1995
- * P.zip(['a', 'b'])([1, 2]) // => [[1, 'a'], [2, 'b']
2449
+ * P.zip(['a', 'b'])([1, 2]) // => [[1, 'a'], [2, 'b']] (type: [number, string][])
2450
+ * P.zip.strict(['a', 'b'] as const)([1, 2] as const) // => [[1, 'a'], [2, 'b']] (type: [[1, 'a'], [2, 'b']])
1996
2451
  * @dataLast
1997
2452
  * @category Array
2453
+ * @strict
1998
2454
  */
1999
2455
  declare function zip<S>(second: ReadonlyArray<S>): <F>(first: ReadonlyArray<F>) => Array<[F, S]>;
2456
+ declare namespace zip {
2457
+ const strict: Strict$3;
2458
+ }
2000
2459
 
2001
2460
  /**
2002
2461
  * Creates a new object from two supplied lists by pairing up equally-positioned items.
@@ -2010,7 +2469,7 @@ declare function zip<S>(second: ReadonlyArray<S>): <F>(first: ReadonlyArray<F>)
2010
2469
  * @dataFirst
2011
2470
  * @category Array
2012
2471
  */
2013
- declare function zipObj<F extends string | number | symbol, S>(first: ReadonlyArray<F>, second: ReadonlyArray<S>): Record<F, S>;
2472
+ declare function zipObj<F extends number | string | symbol, S>(first: ReadonlyArray<F>, second: ReadonlyArray<S>): Record<F, S>;
2014
2473
  /**
2015
2474
  * Creates a new object from two supplied lists by pairing up equally-positioned items.
2016
2475
  * Key/value pairing is truncated to the length of the shorter of the two lists
@@ -2022,8 +2481,9 @@ declare function zipObj<F extends string | number | symbol, S>(first: ReadonlyAr
2022
2481
  * @dataLast
2023
2482
  * @category Array
2024
2483
  */
2025
- declare function zipObj<S>(second: ReadonlyArray<S>): <F extends string | number | symbol>(first: ReadonlyArray<F>) => Record<F, S>;
2484
+ declare function zipObj<S>(second: ReadonlyArray<S>): <F extends number | string | symbol>(first: ReadonlyArray<F>) => Record<F, S>;
2026
2485
 
2486
+ type ZippingFunction<F = unknown, S = unknown, R = unknown> = (f: F, s: S) => R;
2027
2487
  /**
2028
2488
  * Creates a new list from two supplied lists by calling the supplied function
2029
2489
  * with the same-positioned element from each list.
@@ -2037,7 +2497,7 @@ declare function zipObj<S>(second: ReadonlyArray<S>): <F extends string | number
2037
2497
  * @dataFirst
2038
2498
  * @category Array
2039
2499
  */
2040
- declare function zipWith<F, S, R>(first: Array<F>, second: Array<S>, fn: (f: F, s: S) => R): Array<R>;
2500
+ declare function zipWith<F, S, R>(first: ReadonlyArray<F>, second: ReadonlyArray<S>, fn: ZippingFunction<F, S, R>): Array<R>;
2041
2501
  /**
2042
2502
  * Creates a new list from two supplied lists by calling the supplied function
2043
2503
  * with the same-positioned element from each list.
@@ -2049,7 +2509,7 @@ declare function zipWith<F, S, R>(first: Array<F>, second: Array<S>, fn: (f: F,
2049
2509
  * @dataLast
2050
2510
  * @category Array
2051
2511
  */
2052
- declare function zipWith<F, S, R>(fn: (f: F, s: S) => R): (first: Array<F>, second: Array<S>) => Array<R>;
2512
+ declare function zipWith<F, S, R>(fn: ZippingFunction<F, S, R>): (first: ReadonlyArray<F>, second: ReadonlyArray<S>) => Array<R>;
2053
2513
  /**
2054
2514
  * Creates a new list from two supplied lists by calling the supplied function
2055
2515
  * with the same-positioned element from each list.
@@ -2062,7 +2522,114 @@ declare function zipWith<F, S, R>(fn: (f: F, s: S) => R): (first: Array<F>, seco
2062
2522
  * @dataLast
2063
2523
  * @category Array
2064
2524
  */
2065
- declare function zipWith<F, S, R>(fn: (f: F, s: S) => R, second: Array<S>): (first: Array<F>) => Array<R>;
2525
+ declare function zipWith<F, S, R>(fn: ZippingFunction<F, S, R>, second: ReadonlyArray<S>): (first: ReadonlyArray<F>) => Array<R>;
2526
+
2527
+ type Case<In, Out, Thru extends In = In> = readonly [
2528
+ when: ((data: In) => boolean) | ((data: In) => data is Thru),
2529
+ then: (data: Thru) => Out
2530
+ ];
2531
+ /**
2532
+ * Executes a transformer function based on the first matching predicate,
2533
+ * functioning like a series of `if...else if...` statements. It sequentially
2534
+ * evaluates each case and, upon finding a truthy predicate, runs the
2535
+ * corresponding transformer, and returns, ignoring any further cases, even if
2536
+ * they would match.
2537
+ *
2538
+ * !IMPORTANT! - Unlike similar implementations in frameworks like Lodash and
2539
+ * Ramda, this implementation does **NOT** return a default/fallback
2540
+ * `undefined` value when none of the cases match; and instead will **throw** an
2541
+ * exception in those cases.
2542
+ * To add a default case use the `conditional.defaultCase` helper as the final
2543
+ * case of your implementation. By default it returns `undefined`, but could be
2544
+ * provided a transformer in order to return something else.
2545
+ *
2546
+ * Due to TypeScript's inability to infer the result of negating a type-
2547
+ * predicate we can't refine the types used in subsequent cases based on
2548
+ * previous conditions. Using a `switch (true)` statement or ternary operators
2549
+ * is recommended for more precise type control when such type narrowing is
2550
+ * needed.
2551
+ *
2552
+ * @param data - The input data to be evaluated against the provided cases.
2553
+ * @param cases - A list of (up to 10) tuples, each defining a case. Each tuple
2554
+ * consists of a predicate (or a type-predicate) and a transformer function that
2555
+ * processes the data if its case matches.
2556
+ * @returns The output of the matched transformer. If no cases match, an
2557
+ * exception is thrown. The return type is a union of the return types of all
2558
+ * provided transformers.
2559
+ * @signature
2560
+ * P.conditional(...cases)(data);
2561
+ * @example
2562
+ * const nameOrId = 3 as string | number;
2563
+ * P.pipe(
2564
+ * nameOrId,
2565
+ * P.conditional(
2566
+ * [P.isString, (name) => `Hello ${name}`],
2567
+ * [P.isNumber, (id) => `Hello ID: ${id}`],
2568
+ * P.conditional.defaultCase(
2569
+ * (something) => `Hello something (${JSON.stringify(something)})`,
2570
+ * ),
2571
+ * ),
2572
+ * ); //=> 'Hello ID: 3'
2573
+ * @dataLast
2574
+ * @category Function
2575
+ */
2576
+ declare function conditional<T, Return0, Return1 = never, Return2 = never, Return3 = never, Return4 = never, Return5 = never, Return6 = never, Return7 = never, Return8 = never, Return9 = never, Thru0 extends T = T, Thru1 extends T = T, Thru2 extends T = T, Thru3 extends T = T, Thru4 extends T = T, Thru5 extends T = T, Thru6 extends T = T, Thru7 extends T = T, Thru8 extends T = T, Thru9 extends T = T>(case0: Case<T, Return0, Thru0>, case1?: Case<T, Return1, Thru1>, case2?: Case<T, Return2, Thru2>, case3?: Case<T, Return3, Thru3>, case4?: Case<T, Return4, Thru4>, case5?: Case<T, Return5, Thru5>, case6?: Case<T, Return6, Thru6>, case7?: Case<T, Return7, Thru7>, case8?: Case<T, Return8, Thru8>, case9?: Case<T, Return9, Thru9>): (data: T) => Return0 | Return1 | Return2 | Return3 | Return4 | Return5 | Return6 | Return7 | Return8 | Return9;
2577
+ /**
2578
+ * Executes a transformer function based on the first matching predicate,
2579
+ * functioning like a series of `if...else if...` statements. It sequentially
2580
+ * evaluates each case and, upon finding a truthy predicate, runs the
2581
+ * corresponding transformer, and returns, ignoring any further cases, even if
2582
+ * they would match.
2583
+ *
2584
+ * !IMPORTANT! - Unlike similar implementations in frameworks like Lodash and
2585
+ * Ramda, this implementation does **NOT** return a default/fallback
2586
+ * `undefined` value when none of the cases match; and instead will **throw** an
2587
+ * exception in those cases.
2588
+ * To add a default case use the `conditional.defaultCase` helper as the final
2589
+ * case of your implementation. By default it returns `undefined`, but could be
2590
+ * provided a transformer in order to return something else.
2591
+ *
2592
+ * Due to TypeScript's inability to infer the result of negating a type-
2593
+ * predicate we can't refine the types used in subsequent cases based on
2594
+ * previous conditions. Using a `switch (true)` statement or ternary operators
2595
+ * is recommended for more precise type control when such type narrowing is
2596
+ * needed.
2597
+ *
2598
+ * @param data - The input data to be evaluated against the provided cases.
2599
+ * @param cases - A list of (up to 10) tuples, each defining a case. Each tuple
2600
+ * consists of a predicate (or a type-predicate) and a transformer function that
2601
+ * processes the data if its case matches.
2602
+ * @returns The output of the matched transformer. If no cases match, an
2603
+ * exception is thrown. The return type is a union of the return types of all
2604
+ * provided transformers.
2605
+ * @signature
2606
+ * P.conditional(data, ...cases);
2607
+ * @example
2608
+ * const nameOrId = 3 as string | number;
2609
+ * P.conditional(
2610
+ * nameOrId,
2611
+ * [P.isString, (name) => `Hello ${name}`],
2612
+ * [P.isNumber, (id) => `Hello ID: ${id}`],
2613
+ * P.conditional.defaultCase(
2614
+ * (something) => `Hello something (${JSON.stringify(something)})`,
2615
+ * ),
2616
+ * ); //=> 'Hello ID: 3'
2617
+ * @dataFirst
2618
+ * @category Function
2619
+ */
2620
+ declare function conditional<T, Return0, Return1 = never, Return2 = never, Return3 = never, Return4 = never, Return5 = never, Return6 = never, Return7 = never, Return8 = never, Return9 = never, Thru0 extends T = T, Thru1 extends T = T, Thru2 extends T = T, Thru3 extends T = T, Thru4 extends T = T, Thru5 extends T = T, Thru6 extends T = T, Thru7 extends T = T, Thru8 extends T = T, Thru9 extends T = T>(data: T, case0: Case<T, Return0, Thru0>, case1?: Case<T, Return1, Thru1>, case2?: Case<T, Return2, Thru2>, case3?: Case<T, Return3, Thru3>, case4?: Case<T, Return4, Thru4>, case5?: Case<T, Return5, Thru5>, case6?: Case<T, Return6, Thru6>, case7?: Case<T, Return7, Thru7>, case8?: Case<T, Return8, Thru8>, case9?: Case<T, Return9, Thru9>): Return0 | Return1 | Return2 | Return3 | Return4 | Return5 | Return6 | Return7 | Return8 | Return9;
2621
+ declare namespace conditional {
2622
+ /**
2623
+ * A simplified case that accepts all data. Put this as the last case to
2624
+ * prevent an exception from being thrown when none of the previous cases
2625
+ * match.
2626
+ * If this is not the last case it will short-circuit anything after it.
2627
+ * @param then - You only need to provide the transformer, the predicate is
2628
+ * implicit. @default () => undefined, which is how Lodash and Ramda handle
2629
+ * the final fallback case.
2630
+ */
2631
+ function defaultCase<In>(then?: (data: In) => unknown): readonly [() => boolean, (data: In) => unknown];
2632
+ }
2066
2633
 
2067
2634
  /**
2068
2635
  * Creates a data-last pipe function. First function must be always annotated. Other functions are automatically inferred.
@@ -2116,6 +2683,97 @@ declare function noop(): undefined;
2116
2683
  */
2117
2684
  declare function once<T>(fn: () => T): () => T;
2118
2685
 
2686
+ interface Debouncer<F extends (...args: any) => unknown, IsNullable extends boolean = true> {
2687
+ /**
2688
+ * The last computed value of the debounced function.
2689
+ */
2690
+ readonly cachedValue: ReturnType<F> | undefined;
2691
+ /**
2692
+ * Invoke the debounced function.
2693
+ * @param args - same as the args for the debounced function.
2694
+ * @returns - the last computed value of the debounced function with the
2695
+ * latest args provided to it. If `timing` does not include `leading` then the
2696
+ * the function would return `undefined` until the first cool-down period is
2697
+ * over, otherwise the function would always return the return type of the
2698
+ * debounced function.
2699
+ */
2700
+ readonly call: (...args: Parameters<F>) => ReturnType<F> | (true extends IsNullable ? undefined : never);
2701
+ /**
2702
+ * Cancels any debounced functions without calling them, effectively resetting
2703
+ * the debouncer to the same state it is when initially created.
2704
+ */
2705
+ readonly cancel: () => void;
2706
+ /**
2707
+ * Similar to `cancel`, but would also trigger the `trailing` invocation if
2708
+ * the debouncer would run one at the end of the cool-down period.
2709
+ */
2710
+ readonly flush: () => ReturnType<F> | undefined;
2711
+ /**
2712
+ * Is `true` when there is an active cool-down period currently debouncing
2713
+ * invocations.
2714
+ */
2715
+ readonly isPending: boolean;
2716
+ }
2717
+ interface DebounceOptions {
2718
+ readonly maxWaitMs?: number;
2719
+ readonly waitMs?: number;
2720
+ }
2721
+ /**
2722
+ * Wraps `func` with a debouncer object that "debounces" (delays) invocations of the function during a defined cool-down period (`waitMs`). It can be configured to invoke the function either at the start of the cool-down period, the end of it, or at both ends (`timing`).
2723
+ * It can also be configured to allow invocations during the cool-down period (`maxWaitMs`).
2724
+ * It stores the latest call's arguments so they could be used at the end of the cool-down period when invoking `func` (if configured to invoke the function at the end of the cool-down period).
2725
+ * It stores the value returned by `func` whenever its invoked. This value is returned on every call, and is accessible via the `cachedValue` property of the debouncer. Its important to note that the value might be different from the value that would be returned from running `func` with the current arguments as it is a cached value from a previous invocation.
2726
+ * **Important**: The cool-down period defines the minimum between two invocations, and not the maximum. The period will be **extended** each time a call is made until a full cool-down period has elapsed without any additional calls.
2727
+ * @param func The function to debounce, the returned `call` function will have
2728
+ * the exact same signature.
2729
+ * @param options An object allowing further customization of the debouncer:
2730
+ * - `timing?: 'leading' | 'trailing' |'both'`. The default is `'trailing'`.
2731
+ * `leading` would result in the function being invoked at the start of the
2732
+ * cool-down period; `trailing` would result in the function being invoked at
2733
+ * the end of the cool-down period (using the args from the last call to the
2734
+ * debouncer). When `both` is selected the `trailing` invocation would only
2735
+ * take place if there were more than one call to the debouncer during the
2736
+ * cool-down period. **DEFAULT: 'trailing'**
2737
+ * - `waitMs?: number`. The length of the cool-down period in milliseconds. The
2738
+ * debouncer would wait until this amount of time has passed without **any**
2739
+ * additional calls to the debouncer before triggering the end-of-cool-down-
2740
+ * period event. When this happens, the function would be invoked (if `timing`
2741
+ * isn't `'leading'`) and the debouncer state would be reset. **DEFAULT: 0**
2742
+ * - `maxWaitMs?: number`. The length of time since a debounced call (a call
2743
+ * that the debouncer prevented from being invoked) was made until it would be
2744
+ * invoked. Because the debouncer can be continually triggered and thus never
2745
+ * reach the end of the cool-down period, this allows the function to still
2746
+ * be invoked occasionally. IMPORTANT: This param is ignored when `timing` is
2747
+ * `'leading'`.
2748
+ * @returns a debouncer object. The main function is `call`. In addition to it
2749
+ * the debouncer comes with the following additional functions and properties:
2750
+ * - `cancel` method to cancel delayed `func` invocations
2751
+ * - `flush` method to end the cool-down period immediately.
2752
+ * - `cachedValue` the latest return value of an invocation (if one occurred).
2753
+ * - `isPending` flag to check if there is an inflight cool-down window.
2754
+ * @signature
2755
+ * P.debounce(func, options);
2756
+ * @example
2757
+ * const debouncer = debounce(identity, { timing: 'trailing', waitMs: 1000 });
2758
+ * const result1 = debouncer.call(1); // => undefined
2759
+ * const result2 = debouncer.call(2); // => undefined
2760
+ * // after 1 second
2761
+ * const result3 = debouncer.call(3); // => 2
2762
+ * // after 1 second
2763
+ * debouncer.cachedValue; // => 3
2764
+ * @dataFirst
2765
+ * @category Function
2766
+ * @see https://css-tricks.com/debouncing-throttling-explained-examples/
2767
+ */
2768
+ declare function debounce<F extends (...args: any) => any>(func: F, options: {
2769
+ readonly timing?: 'trailing';
2770
+ } & DebounceOptions): Debouncer<F>;
2771
+ declare function debounce<F extends (...args: any) => any>(func: F, options: ({
2772
+ readonly timing: 'both';
2773
+ } & DebounceOptions) | ({
2774
+ readonly timing: 'leading';
2775
+ } & Omit<DebounceOptions, 'maxWaitMs'>)): Debouncer<F, false>;
2776
+
2119
2777
  /**
2120
2778
  * Perform left-to-right function composition.
2121
2779
  * @param value The initial value.
@@ -2192,7 +2850,6 @@ declare function purry(fn: any, args: IArguments | ReadonlyArray<any>, lazy?: an
2192
2850
  */
2193
2851
  declare function sleep(timeout: number): Promise<void>;
2194
2852
 
2195
- type DefinitelyArray<T> = Extract<T, Array<any> | ReadonlyArray<any>> extends never ? ReadonlyArray<unknown> : Extract<T, Array<any> | ReadonlyArray<any>>;
2196
2853
  /**
2197
2854
  * A function that checks if the passed parameter is an Array and narrows its type accordingly
2198
2855
  * @param data the variable to check
@@ -2205,9 +2862,8 @@ type DefinitelyArray<T> = Extract<T, Array<any> | ReadonlyArray<any>> extends ne
2205
2862
  * P.isArray('somethingElse') //=> false
2206
2863
  * @category Guard
2207
2864
  */
2208
- declare function isArray<T>(data: T | ReadonlyArray<unknown>): data is DefinitelyArray<T>;
2865
+ declare function isArray<T>(data: ReadonlyArray<unknown> | T): data is NarrowedTo<T, ReadonlyArray<unknown>>;
2209
2866
 
2210
- type DefinitelyBoolean<T> = Extract<T, boolean> extends never ? boolean : Extract<T, boolean> extends any ? boolean : Extract<T, number>;
2211
2867
  /**
2212
2868
  * A function that checks if the passed parameter is a boolean and narrows its type accordingly
2213
2869
  * @param data the variable to check
@@ -2220,7 +2876,7 @@ type DefinitelyBoolean<T> = Extract<T, boolean> extends never ? boolean : Extrac
2220
2876
  * P.isBoolean('somethingElse') //=> false
2221
2877
  * @category Guard
2222
2878
  */
2223
- declare function isBoolean<T>(data: T | boolean): data is DefinitelyBoolean<T>;
2879
+ declare function isBoolean<T>(data: T | boolean): data is NarrowedTo<T, boolean>;
2224
2880
 
2225
2881
  /**
2226
2882
  * A function that checks if the passed parameter is a Date and narrows its type accordingly
@@ -2273,7 +2929,7 @@ declare namespace isDefined {
2273
2929
  * @category Function
2274
2930
  */
2275
2931
  declare function isEmpty(data: string): data is '';
2276
- declare function isEmpty(data: ReadonlyArray<unknown> | []): data is [];
2932
+ declare function isEmpty(data: [] | ReadonlyArray<unknown>): data is [];
2277
2933
  declare function isEmpty<T extends Readonly<Record<PropertyKey, unknown>>>(data: T): data is Record<keyof T, never>;
2278
2934
 
2279
2935
  type DefinitelyError<T> = Extract<T, Error> extends never ? Error : Extract<T, Error>;
@@ -2288,7 +2944,7 @@ type DefinitelyError<T> = Extract<T, Error> extends never ? Error : Extract<T, E
2288
2944
  * P.isError('somethingElse') //=> false
2289
2945
  * @category Guard
2290
2946
  */
2291
- declare function isError<T>(data: T | Error): data is DefinitelyError<T>;
2947
+ declare function isError<T>(data: Error | T): data is DefinitelyError<T>;
2292
2948
 
2293
2949
  type DefinitelyFunction<T> = Extract<T, Function> extends never ? Function : Extract<T, Function>;
2294
2950
  /**
@@ -2302,7 +2958,7 @@ type DefinitelyFunction<T> = Extract<T, Function> extends never ? Function : Ext
2302
2958
  * P.isFunction('somethingElse') //=> false
2303
2959
  * @category Guard
2304
2960
  */
2305
- declare function isFunction<T>(data: T | Function): data is DefinitelyFunction<T>;
2961
+ declare function isFunction<T>(data: Function | T): data is DefinitelyFunction<T>;
2306
2962
 
2307
2963
  /**
2308
2964
  * A function that checks if the passed parameter is Nil (null or undefined) and narrows its type accordingly
@@ -2348,36 +3004,45 @@ declare function isNonNull<T>(data: T | null): data is T;
2348
3004
  declare function isNot<T, S extends T>(predicate: (data: T) => data is S): (data: T) => data is Exclude<T, S>;
2349
3005
  declare function isNot<T>(predicate: (data: T) => any): (data: T) => boolean;
2350
3006
 
2351
- type DefinitelyNumber<T> = Extract<T, number> extends never ? number : Extract<T, number> extends any ? number : Extract<T, number>;
2352
3007
  /**
2353
3008
  * A function that checks if the passed parameter is a number and narrows its type accordingly
2354
3009
  * @param data the variable to check
2355
3010
  * @signature
2356
- * R.isNumber(data)
3011
+ * P.isNumber(data)
2357
3012
  * @returns true if the passed input is a number, false otherwise
2358
3013
  * @example
2359
- * R.isNumber(1) //=> true
2360
- * R.isNumber('notANumber') //=> false
3014
+ * P.isNumber(1) //=> true
3015
+ * P.isNumber('notANumber') //=> false
2361
3016
  * @category Guard
2362
3017
  */
2363
- declare function isNumber<T>(data: T | number): data is DefinitelyNumber<T>;
3018
+ declare function isNumber<T>(data: T | number): data is NarrowedTo<T, number>;
2364
3019
 
2365
- type DefinitelyObject<T> = Exclude<Extract<T, object>, Array<any> | Function | ReadonlyArray<any>> extends never ? Record<string, unknown> : Exclude<Extract<T, object>, Array<any> | Function | ReadonlyArray<any>>;
2366
3020
  /**
2367
- * A function that checks if the passed parameter is of type Object and narrows its type accordingly
2368
- * @param data the variable to check
3021
+ * Checks if `data` is a "plain" object. A plain object is defined as an object with string keys and values of any type, including primitives, other objects, functions, classes, etc (aka struct/shape/record/simple). Technically, a plain object is one whose prototype is either `Object.prototype` or `null`, ensuring it does not inherit properties or methods from other object types.
3022
+ *
3023
+ * This function is narrower in scope than `isObjectType`, which accepts any entity considered an `"object"` by JavaScript's `typeof`.
3024
+ *
3025
+ * Note that Maps, Arrays, and Sets are not considered plain objects and would return `false`.
3026
+ *
3027
+ * @param data - The variable to check.
3028
+ * @returns - The input type, narrowed to only plain objects.
2369
3029
  * @signature
2370
3030
  * P.isObject(data)
2371
- * @returns true if the passed input is an Object, Promise, Date or Error, false otherwise
2372
3031
  * @example
3032
+ * // true
2373
3033
  * P.isObject({}) //=> true
2374
- * P.isObject(Promise.resolve("something")) //=> true
2375
- * P.isObject(new Date()) //=> true
2376
- * P.isObject(new Error("error")) //=> true
3034
+ * P.isObject({ a: 123 }) //=> true
3035
+ *
3036
+ * // false
3037
+ * P.isObject([]) //=> false
3038
+ * P.isObject(Promise.resolve("something")) //=> false
3039
+ * P.isObject(new Date()) //=> false
3040
+ * P.isObject(new Error("error")) //=> false
2377
3041
  * P.isObject('somethingElse') //=> false
3042
+ * P.isObject(null) //=> false
2378
3043
  * @category Guard
2379
3044
  */
2380
- declare function isObject<T>(data: T | object): data is DefinitelyObject<T>;
3045
+ declare function isObject<T>(data: Record<PropertyKey, unknown> | T): data is NarrowedTo<T, Record<PropertyKey, unknown>>;
2381
3046
 
2382
3047
  /**
2383
3048
  * A function that checks if the passed parameter is a Promise and narrows its type accordingly
@@ -2393,7 +3058,6 @@ declare function isObject<T>(data: T | object): data is DefinitelyObject<T>;
2393
3058
  */
2394
3059
  declare function isPromise<T, S>(data: Promise<T> | S): data is Promise<T>;
2395
3060
 
2396
- type DefinitelyString<T> = Extract<T, string> extends never ? string : Extract<T, string> extends any ? string : Extract<T, string>;
2397
3061
  /**
2398
3062
  * A function that checks if the passed parameter is a string and narrows its type accordingly
2399
3063
  * @param data the variable to check
@@ -2405,7 +3069,20 @@ type DefinitelyString<T> = Extract<T, string> extends never ? string : Extract<T
2405
3069
  * P.isString(1) //=> false
2406
3070
  * @category Guard
2407
3071
  */
2408
- declare function isString<T>(data: T | string): data is DefinitelyString<T>;
3072
+ declare function isString<T>(data: T | string): data is NarrowedTo<T, string>;
3073
+
3074
+ /**
3075
+ * A function that checks if the passed parameter is a symbol and narrows its type accordingly
3076
+ * @param data the variable to check
3077
+ * @signature
3078
+ * P.isSymbol(data)
3079
+ * @returns true if the passed input is a symbol, false otherwise
3080
+ * @example
3081
+ * P.isSymbol(Symbol('foo')) //=> true
3082
+ * P.isSymbol(1) //=> false
3083
+ * @category Guard
3084
+ */
3085
+ declare function isSymbol<T>(data: T | symbol): data is NarrowedTo<T, symbol>;
2409
3086
 
2410
3087
  /**
2411
3088
  * A function that checks if the passed parameter is truthy and narrows its type accordingly
@@ -2422,7 +3099,71 @@ declare function isString<T>(data: T | string): data is DefinitelyString<T>;
2422
3099
  * P.isTruthy('') //=> false
2423
3100
  * @category Guard
2424
3101
  */
2425
- declare function isTruthy<T>(data: T): data is Exclude<T, null | undefined | false | '' | 0>;
3102
+ declare function isTruthy<T>(data: T): data is Exclude<T, '' | 0 | false | null | undefined>;
3103
+
3104
+ /**
3105
+ * Adds two numbers.
3106
+ * @param value The number.
3107
+ * @param addend The number to add to the value.
3108
+ * @signature
3109
+ * P.add(value, addend);
3110
+ * @example
3111
+ * P.add(10, 5) // => 15
3112
+ * P.add(10, -5) // => 5
3113
+ * P.reduce([1, 2, 3, 4], P.add, 0) // => 10
3114
+ * @dataFirst
3115
+ * @category Number
3116
+ */
3117
+ declare function add(value: number, addend: number): number;
3118
+ /**
3119
+ * Adds two numbers.
3120
+ * @param value The number.
3121
+ * @param addend The number to add to the value.
3122
+ * @signature
3123
+ * P.add(addend)(value);
3124
+ * @example
3125
+ * P.add(5)(10) // => 15
3126
+ * P.add(-5)(10) // => 5
3127
+ * P.map([1, 2, 3, 4], P.add(1)) // => [2, 3, 4, 5]
3128
+ * @dataLast
3129
+ * @category Number
3130
+ */
3131
+ declare function add(addend: number): (value: number) => number;
3132
+
3133
+ /**
3134
+ * Rounds up a given number to a specific precision.
3135
+ * If you'd like to round up to an integer (i.e. use this function with constant `precision === 0`),
3136
+ * use `Math.ceil` instead, as it won't incur the additional library overhead.
3137
+ * @param value The number to round up.
3138
+ * @param precision The precision to round up to. Must be an integer between -15 and 15.
3139
+ * @signature
3140
+ * P.ceil(value, precision);
3141
+ * @example
3142
+ * P.ceil(123.9876, 3) // => 123.988
3143
+ * P.ceil(483.22243, 1) // => 483.3
3144
+ * P.ceil(8541, -1) // => 8550
3145
+ * P.ceil(456789, -3) // => 457000
3146
+ * @dataFirst
3147
+ * @category Number
3148
+ */
3149
+ declare function ceil(value: number, precision: number): number;
3150
+ /**
3151
+ * Rounds up a given number to a specific precision.
3152
+ * If you'd like to round up to an integer (i.e. use this function with constant `precision === 0`),
3153
+ * use `Math.ceil` instead, as it won't incur the additional library overhead.
3154
+ * @param value The number to round up.
3155
+ * @param precision The precision to round up to. Must be an integer between -15 and 15.
3156
+ * @signature
3157
+ * P.ceil(precision)(value);
3158
+ * @example
3159
+ * P.ceil(3)(123.9876) // => 123.988
3160
+ * P.ceil(1)(483.22243) // => 483.3
3161
+ * P.ceil(-1)(8541) // => 8550
3162
+ * P.ceil(-3)(456789) // => 457000
3163
+ * @dataLast
3164
+ * @category Number
3165
+ */
3166
+ declare function ceil(precision: number): (value: number) => number;
2426
3167
 
2427
3168
  /**
2428
3169
  * Clamp the given value within the inclusive min and max bounds.
@@ -2440,8 +3181,8 @@ declare function isTruthy<T>(data: T): data is Exclude<T, null | undefined | fal
2440
3181
  * @category Number
2441
3182
  */
2442
3183
  declare function clamp(value: number, limits: {
2443
- min?: number;
2444
3184
  max?: number;
3185
+ min?: number;
2445
3186
  }): number;
2446
3187
  /**
2447
3188
  * Clamp the given value within the inclusive min and max bounds.
@@ -2458,10 +3199,163 @@ declare function clamp(value: number, limits: {
2458
3199
  * @category Number
2459
3200
  */
2460
3201
  declare function clamp(limits: {
2461
- min?: number;
2462
3202
  max?: number;
3203
+ min?: number;
2463
3204
  }): (value: number) => number;
2464
3205
 
3206
+ /**
3207
+ * Divides two numbers.
3208
+ * @param value The number.
3209
+ * @param divisor The number to divide the value by.
3210
+ * @signature
3211
+ * P.divide(value, divisor);
3212
+ * @example
3213
+ * P.divide(12, 3) // => 4
3214
+ * P.reduce([1, 2, 3, 4], P.divide, 24) // => 1
3215
+ * @dataFirst
3216
+ * @category Number
3217
+ */
3218
+ declare function divide(value: number, divisor: number): number;
3219
+ /**
3220
+ * Divides two numbers.
3221
+ * @param value The number.
3222
+ * @param divisor The number to divide the value by.
3223
+ * @signature
3224
+ * P.divide(divisor)(value);
3225
+ * @example
3226
+ * P.divide(3)(12) // => 4
3227
+ * P.map([2, 4, 6, 8], P.divide(2)) // => [1, 2, 3, 4]
3228
+ * @dataLast
3229
+ * @category Number
3230
+ */
3231
+ declare function divide(divisor: number): (value: number) => number;
3232
+
3233
+ /**
3234
+ * Rounds down a given number to a specific precision.
3235
+ * If you'd like to round down to an integer (i.e. use this function with constant `precision === 0`),
3236
+ * use `Math.floor` instead, as it won't incur the additional library overhead.
3237
+ * @param value The number to round down.
3238
+ * @param precision The precision to round down to. Must be an integer between -15 and 15.
3239
+ * @signature
3240
+ * P.floor(value, precision);
3241
+ * @example
3242
+ * P.floor(123.9876, 3) // => 123.987
3243
+ * P.floor(483.22243, 1) // => 483.2
3244
+ * P.floor(8541, -1) // => 8540
3245
+ * P.floor(456789, -3) // => 456000
3246
+ * @dataFirst
3247
+ * @category Number
3248
+ */
3249
+ declare function floor(value: number, precision: number): number;
3250
+ /**
3251
+ * Rounds down a given number to a specific precision.
3252
+ * If you'd like to round down to an integer (i.e. use this function with constant `precision === 0`),
3253
+ * use `Math.floor` instead, as it won't incur the additional library overhead.
3254
+ * @param value The number to round down.
3255
+ * @param precision The precision to round down to. Must be an integer between -15 and 15.
3256
+ * @signature
3257
+ * P.floor(precision)(value);
3258
+ * @example
3259
+ * P.floor(3)(123.9876) // => 123.987
3260
+ * P.floor(1)(483.22243) // => 483.2
3261
+ * P.floor(-1)(8541) // => 8540
3262
+ * P.floor(-3)(456789) // => 456000
3263
+ * @dataLast
3264
+ * @category Number
3265
+ */
3266
+ declare function floor(precision: number): (value: number) => number;
3267
+
3268
+ /**
3269
+ * Multiplies two numbers.
3270
+ * @param value The number.
3271
+ * @param multiplicand The number to multiply the value by.
3272
+ * @signature
3273
+ * P.multiply(value, multiplicand);
3274
+ * @example
3275
+ * P.multiply(3, 4) // => 12
3276
+ * P.reduce([1, 2, 3, 4], P.multiply, 1) // => 24
3277
+ * @dataFirst
3278
+ * @category Number
3279
+ */
3280
+ declare function multiply(value: number, multiplicand: number): number;
3281
+ /**
3282
+ * Multiplies two numbers.
3283
+ * @param value The number.
3284
+ * @param multiplicand The number to multiply the value by.
3285
+ * @signature
3286
+ * P.multiply(multiplicand)(value);
3287
+ * @example
3288
+ * P.multiply(4)(3) // => 12
3289
+ * P.map([1, 2, 3, 4], P.multiply(2)) // => [2, 4, 6, 8]
3290
+ * @dataLast
3291
+ * @category Number
3292
+ */
3293
+ declare function multiply(multiplicand: number): (value: number) => number;
3294
+
3295
+ /**
3296
+ * Rounds a given number to a specific precision.
3297
+ * If you'd like to round to an integer (i.e. use this function with constant `precision === 0`),
3298
+ * use `Math.round` instead, as it won't incur the additional library overhead.
3299
+ * @param value The number to round.
3300
+ * @param precision The precision to round to. Must be an integer between -15 and 15.
3301
+ * @signature
3302
+ * P.round(value, precision);
3303
+ * @example
3304
+ * P.round(123.9876, 3) // => 123.988
3305
+ * P.round(483.22243, 1) // => 483.2
3306
+ * P.round(8541, -1) // => 8540
3307
+ * P.round(456789, -3) // => 457000
3308
+ * @dataFirst
3309
+ * @category Number
3310
+ */
3311
+ declare function round(value: number, precision: number): number;
3312
+ /**
3313
+ * Rounds a given number to a specific precision.
3314
+ * If you'd like to round to an integer (i.e. use this function with constant `precision === 0`),
3315
+ * use `Math.round` instead, as it won't incur the additional library overhead.
3316
+ * @param value The number to round.
3317
+ * @param precision The precision to round to. Must be an integer between -15 and 15.
3318
+ * @signature
3319
+ * P.round(precision)(value);
3320
+ * @example
3321
+ * P.round(3)(123.9876) // => 123.988
3322
+ * P.round(1)(483.22243) // => 483.2
3323
+ * P.round(-1)(8541) // => 8540
3324
+ * P.round(-3)(456789) // => 457000
3325
+ * @dataLast
3326
+ * @category Number
3327
+ */
3328
+ declare function round(precision: number): (value: number) => number;
3329
+
3330
+ /**
3331
+ * Subtracts two numbers.
3332
+ * @param value The number.
3333
+ * @param subtrahend The number to subtract from the value.
3334
+ * @signature
3335
+ * P.subtract(value, subtrahend);
3336
+ * @example
3337
+ * P.subtract(10, 5) // => 5
3338
+ * P.subtract(10, -5) // => 15
3339
+ * R.reduce([1, 2, 3, 4], P.subtract, 20) // => 10
3340
+ * @dataFirst
3341
+ * @category Number
3342
+ */
3343
+ declare function subtract(value: number, subtrahend: number): number;
3344
+ /**
3345
+ * Subtracts two numbers.
3346
+ * @param value The number.
3347
+ * @param subtrahend The number to subtract from the value.
3348
+ * @signature
3349
+ * P.subtract(subtrahend)(value);
3350
+ * @example
3351
+ * P.subtract(5)(10) // => 5
3352
+ * P.subtract(-5)(10) // => 15
3353
+ * P.map([1, 2, 3, 4], P.subtract(1)) // => [0, 1, 2, 3]
3354
+ * @dataLast
3355
+ * @category Number
3356
+ */
3357
+ declare function subtract(subtrahend: number): (value: number) => number;
3358
+
2465
3359
  /**
2466
3360
  * Add a new property to an object.
2467
3361
  * @param obj the target object
@@ -2578,7 +3472,7 @@ type Entry<Key extends PropertyKey = PropertyKey, Value = unknown> = readonly [
2578
3472
  key: Key,
2579
3473
  value: Value
2580
3474
  ];
2581
- type Strict$1 = <Entries extends IterableContainer<Entry>>(entries: Entries) => StrictOut<Entries>;
3475
+ type Strict$2 = <Entries extends IterableContainer<Entry>>(entries: Entries) => StrictOut<Entries>;
2582
3476
  type StrictOut<Entries> = Entries extends readonly [infer First, ...infer Tail] ? FromPairsTuple<First, Tail> : Entries extends readonly [...infer Head, infer Last] ? FromPairsTuple<Last, Head> : Entries extends IterableContainer<Entry> ? FromPairsArray<Entries> : 'ERROR: Entries array-like could not be infered';
2583
3477
  type FromPairsTuple<E, Rest> = E extends Entry ? Record<E[0], E[1]> & StrictOut<Rest> : 'ERROR: Array-like contains a non-entry element';
2584
3478
  type FromPairsArray<Entries extends IterableContainer<Entry>> = string extends AllKeys$1<Entries> ? Record<string, Entries[number][1]> : number extends AllKeys$1<Entries> ? Record<number, Entries[number][1]> : symbol extends AllKeys$1<Entries> ? Record<symbol, Entries[number][1]> : FromPairsArrayWithLiteralKeys<Entries>;
@@ -2607,7 +3501,7 @@ type ValueForKey<Entries extends IterableContainer<Entry>, K extends PropertyKey
2607
3501
  declare function fromPairs<V>(pairs: ReadonlyArray<Entry<number, V>>): Record<number, V>;
2608
3502
  declare function fromPairs<V>(pairs: ReadonlyArray<Entry<string, V>>): Record<string, V>;
2609
3503
  declare namespace fromPairs {
2610
- const strict: Strict$1;
3504
+ const strict: Strict$2;
2611
3505
  }
2612
3506
 
2613
3507
  type Inverted<T extends object> = T[keyof T] extends PropertyKey ? Record<T[keyof T], keyof T> : never;
@@ -2637,6 +3531,14 @@ declare function invert<T extends object>(object: T): Inverted<T>;
2637
3531
  */
2638
3532
  declare function invert<T extends object>(): (object: T) => Inverted<T>;
2639
3533
 
3534
+ type Strict$1 = <T extends object>(source: T) => Keys<T>;
3535
+ type Keys<T> = T extends IterableContainer ? ArrayKeys<T> : ObjectKeys<T>;
3536
+ type ArrayKeys<T extends IterableContainer> = {
3537
+ -readonly [Index in keyof T]: Index extends number | string ? `${IsIndexAfterSpread<T, Index> extends true ? number : Index}` : never;
3538
+ };
3539
+ type IsIndexAfterSpread<T extends IterableContainer, Index extends number | string> = IndicesAfterSpread<T> extends never ? false : Index extends `${IndicesAfterSpread<T>}` ? true : false;
3540
+ type IndicesAfterSpread<T extends [] | ReadonlyArray<unknown>, Iterations extends ReadonlyArray<unknown> = []> = T[number] extends never ? never : T extends readonly [unknown, ...infer Tail] ? IndicesAfterSpread<Tail, [unknown, ...Iterations]> : T extends readonly [...infer Head, unknown] ? IndicesAfterSpread<Head, [unknown, ...Iterations]> | Iterations['length'] : Iterations['length'];
3541
+ type ObjectKeys<T> = T extends Record<PropertyKey, never> ? [] : Array<`${Exclude<keyof T, symbol>}`>;
2640
3542
  /**
2641
3543
  * Returns a new array containing the keys of the array or object.
2642
3544
  * @param source Either an array or an object
@@ -2656,23 +3558,14 @@ declare function invert<T extends object>(): (object: T) => Inverted<T>;
2656
3558
  * @strict
2657
3559
  * @category Object
2658
3560
  */
2659
-
2660
- type Strict = <T extends object>(source: T) => Keys<T>;
2661
- type Keys<T> = T extends IterableContainer ? ArrayKeys<T> : ObjectKeys$1<T>;
2662
- type ArrayKeys<T extends IterableContainer> = {
2663
- -readonly [Index in keyof T]: Index extends string | number ? `${IsIndexAfterSpread<T, Index> extends true ? number : Index}` : never;
2664
- };
2665
- type IsIndexAfterSpread<T extends IterableContainer, Index extends string | number> = IndicesAfterSpread<T> extends never ? false : Index extends `${IndicesAfterSpread<T>}` ? true : false;
2666
- type IndicesAfterSpread<T extends ReadonlyArray<unknown> | [], Iterations extends ReadonlyArray<unknown> = []> = T[number] extends never ? never : T extends readonly [unknown, ...infer Tail] ? IndicesAfterSpread<Tail, [unknown, ...Iterations]> : T extends readonly [...infer Head, unknown] ? IndicesAfterSpread<Head, [unknown, ...Iterations]> | Iterations['length'] : Iterations['length'];
2667
- type ObjectKeys$1<T> = T extends Record<PropertyKey, never> ? [] : Array<`${Exclude<keyof T, symbol>}`>;
2668
- declare function keys(source: Record<PropertyKey, unknown> | ArrayLike<unknown>): Array<string>;
3561
+ declare function keys(source: ArrayLike<unknown> | Record<PropertyKey, unknown>): Array<string>;
2669
3562
  declare namespace keys {
2670
- const strict: Strict;
3563
+ const strict: Strict$1;
2671
3564
  }
2672
3565
 
2673
3566
  /**
2674
3567
  * Maps keys of `object` and keeps the same values.
2675
- * @param object the object to map
3568
+ * @param data the object to map
2676
3569
  * @param fn the mapping function
2677
3570
  * @signature
2678
3571
  * P.mapKeys(object, fn)
@@ -2681,7 +3574,7 @@ declare namespace keys {
2681
3574
  * @dataFirst
2682
3575
  * @category Object
2683
3576
  */
2684
- declare function mapKeys<T, S extends keyof any>(object: T, fn: (key: keyof T, value: T[keyof T]) => S): Record<S, T[keyof T]>;
3577
+ declare function mapKeys<T, S extends PropertyKey>(data: T, fn: (key: keyof T, value: Required<T>[keyof T]) => S): Record<S, T[keyof T]>;
2685
3578
  /**
2686
3579
  * Maps keys of `object` and keeps the same values.
2687
3580
  * @param fn the mapping function
@@ -2692,11 +3585,11 @@ declare function mapKeys<T, S extends keyof any>(object: T, fn: (key: keyof T, v
2692
3585
  * @dataLast
2693
3586
  * @category Object
2694
3587
  */
2695
- declare function mapKeys<T, S extends keyof any>(fn: (key: keyof T, value: T[keyof T]) => S): (object: T) => Record<S, T[keyof T]>;
3588
+ declare function mapKeys<T, S extends PropertyKey>(fn: (key: keyof T, value: Required<T>[keyof T]) => S): (data: T) => Record<S, T[keyof T]>;
2696
3589
 
2697
3590
  /**
2698
3591
  * Maps values of `object` and keeps the same keys.
2699
- * @param object the object to map
3592
+ * @param data the object to map
2700
3593
  * @param fn the mapping function
2701
3594
  * @signature
2702
3595
  * P.mapValues(object, fn)
@@ -2705,7 +3598,7 @@ declare function mapKeys<T, S extends keyof any>(fn: (key: keyof T, value: T[key
2705
3598
  * @dataFirst
2706
3599
  * @category Object
2707
3600
  */
2708
- declare function mapValues<T extends Record<PropertyKey, any>, S>(object: T, fn: (value: T[keyof T], key: keyof T) => S): Record<keyof T, S>;
3601
+ declare function mapValues<T extends Record<PropertyKey, unknown>, S>(data: T, fn: (value: T[ObjectKeys$1<T>], key: ObjectKeys$1<T>) => S): Record<ObjectKeys$1<T>, S>;
2709
3602
  /**
2710
3603
  * Maps values of `object` and keeps the same keys.
2711
3604
  * @param fn the mapping function
@@ -2716,7 +3609,7 @@ declare function mapValues<T extends Record<PropertyKey, any>, S>(object: T, fn:
2716
3609
  * @dataLast
2717
3610
  * @category Object
2718
3611
  */
2719
- declare function mapValues<T extends Record<PropertyKey, any>, S>(fn: (value: T[keyof T], key: keyof T) => S): (object: T) => Record<keyof T, S>;
3612
+ declare function mapValues<T extends Record<PropertyKey, unknown>, S>(fn: (value: T[keyof T], key: keyof T) => S): (data: T) => Record<ObjectKeys$1<T>, S>;
2720
3613
 
2721
3614
  /**
2722
3615
  * Merges two objects. The same as `Object.assign`.
@@ -2743,30 +3636,37 @@ declare function merge<A, B>(a: A, b: B): A & B;
2743
3636
  */
2744
3637
  declare function merge<A, B>(b: B): (a: A) => A & B;
2745
3638
 
2746
- type DeepPartial<T> = {
2747
- [P in keyof T]?: DeepPartial<T[P]>;
2748
- };
2749
3639
  /**
2750
- * Deep merge two objects
3640
+ * Merges the `source` object into the `destination` object. The merge is similar to performing `{ ...destination, ... source }` (where disjoint values from each object would be copied as-is, and for any overlapping props the value from `source` would be used); But for *each prop* (`p`), if **both** `destination` and `source` have a **plain-object** as a value, the value would be taken as the result of recursively deepMerging them (`result.p === deepMerge(destination.p, source.p)`).
3641
+ *
3642
+ * @param destination - The object to merge into. In general, this object would have it's values overridden.
3643
+ * @param source - The object to merge from. In general, shared keys would be taken from this object.
3644
+ * @returns - The merged object.
3645
+ * @signature
3646
+ * P.mergeDeep(destination, source)
3647
+ * @example
3648
+ * P.mergeDeep({ foo: 'bar', x: 1 }, { foo: 'baz', y: 2 }) // => { foo: 'baz', x: 1, y: 2 }
3649
+ * @dataFirst
3650
+ * @category Object
2751
3651
  */
2752
- declare function mergeDeep<T>({ mergeArray, original, patch, }: {
2753
- mergeArray?: boolean;
2754
- original: T;
2755
- patch: DeepPartial<T>;
2756
- }): T;
2757
-
3652
+ declare function mergeDeep<Destination extends Record<string, unknown>, Source extends Record<string, unknown>>(destination: Destination, source: Source): MergeDeep<Destination, Source>;
2758
3653
  /**
2759
- * Returns a partial copy of an object omitting the keys specified.
2760
- * @param data the object
2761
- * @param propNames the property names
3654
+ * Merges the `source` object into the `destination` object. The merge is similar to performing `{ ...destination, ... source }` (where disjoint values from each object would be copied as-is, and for any overlapping props the value from `source` would be used); But for *each prop* (`p`), if **both** `destination` and `source` have a **plain-object** as a value, the value would be taken as the result of recursively deepMerging them (`result.p === deepMerge(destination.p, source.p)`).
3655
+ *
3656
+ * @param source - The object to merge from. In general, shared keys would be taken from this object.
3657
+ * @returns - The merged object.
2762
3658
  * @signature
2763
- * P.omit(obj, names);
3659
+ * P.mergeDeep(source)(destination)
2764
3660
  * @example
2765
- * P.omit({ a: 1, b: 2, c: 3, d: 4 }, ['a', 'd']) // => { b: 2, c: 3 }
2766
- * @dataFirst
3661
+ * P.pipe(
3662
+ * { foo: 'bar', x: 1 },
3663
+ * P.mergeDeep({ foo: 'baz', y: 2 }),
3664
+ * ); // => { foo: 'baz', x: 1, y: 2 }
3665
+ * @dataLast
2767
3666
  * @category Object
2768
3667
  */
2769
- declare function omit<T extends object, K extends keyof T>(data: T, propNames: ReadonlyArray<K>): Omit<T, K>;
3668
+ declare function mergeDeep<Destination extends Record<string, unknown>, Source extends Record<string, unknown>>(source: Source): (target: Destination) => MergeDeep<Destination, Source>;
3669
+
2770
3670
  /**
2771
3671
  * Returns a partial copy of an object omitting the keys specified.
2772
3672
  * @param propNames the property names
@@ -2777,7 +3677,19 @@ declare function omit<T extends object, K extends keyof T>(data: T, propNames: R
2777
3677
  * @dataLast
2778
3678
  * @category Object
2779
3679
  */
2780
- declare function omit<K extends PropertyKey>(propNames: ReadonlyArray<K>): <T extends object>(data: T) => Omit<T, K>;
3680
+ declare function omit<T extends object, K extends keyof T>(propNames: ReadonlyArray<K>): (data: T) => Omit<T, K>;
3681
+ /**
3682
+ * Returns a partial copy of an object omitting the keys specified.
3683
+ * @param data the object
3684
+ * @param propNames the property names
3685
+ * @signature
3686
+ * P.omit(obj, names);
3687
+ * @example
3688
+ * P.omit({ a: 1, b: 2, c: 3, d: 4 }, ['a', 'd']) // => { b: 2, c: 3 }
3689
+ * @dataFirst
3690
+ * @category Object
3691
+ */
3692
+ declare function omit<T extends object, K extends keyof T>(data: T, propNames: ReadonlyArray<K>): Omit<T, K>;
2781
3693
 
2782
3694
  /**
2783
3695
  * Returns a partial copy of an object omitting the keys matching predicate.
@@ -2896,7 +3808,7 @@ declare function pick<T extends object, K extends keyof T>(object: T, names: Rea
2896
3808
  * @dataLast
2897
3809
  * @category Object
2898
3810
  */
2899
- declare function pick<K extends PropertyKey>(names: ReadonlyArray<K>): <T extends Record<PropertyKey, any>>(object: T) => Pick<T, K>;
3811
+ declare function pick<T extends object, K extends keyof T>(names: ReadonlyArray<K>): (object: T) => Pick<T, K>;
2900
3812
 
2901
3813
  /**
2902
3814
  * Creates an object composed of the picked `object` properties.
@@ -2957,14 +3869,6 @@ declare function set<T, K extends keyof T>(obj: T, prop: K, value: T[K]): T;
2957
3869
  */
2958
3870
  declare function set<T, K extends keyof T>(prop: K, value: T[K]): (obj: T) => T;
2959
3871
 
2960
- type Path<Obj, Prefix extends Array<PropertyKey> = []> = Obj extends Primitive ? Prefix : Obj extends Array<infer Item> ? Prefix | Path<Item, [...Prefix, number]> : Prefix | PathsOfObject<Obj, Prefix>;
2961
- type PathsOfObject<Obj, Prefix extends Array<PropertyKey>> = {
2962
- [K in keyof Obj]: Path<Obj[K], [...Prefix, K]>;
2963
- }[keyof Obj];
2964
- type ValueAtPath<Obj, ObjPath extends Array<PropertyKey> = []> = ObjPath extends [] ? Obj : ObjPath extends [infer Head, ...infer Tail] ? Tail extends Array<PropertyKey> ? Head extends keyof Obj ? ValueAtPath<Obj[Head], Tail> : never : never : never;
2965
- type SupportsValueAtPath<Obj, Path extends Array<PropertyKey>, Value> = Value extends ValueAtPath<Obj, Path> ? Obj : never;
2966
- type Primitive = string | number | boolean | null | undefined | symbol;
2967
-
2968
3872
  /**
2969
3873
  * Copied from ts-toolbelt
2970
3874
  * https://github.com/millsp/ts-toolbelt/blob/master/sources/Function/Narrow.ts
@@ -2989,13 +3893,13 @@ type Try<A1, A2, Catch = never> = A1 extends A2 ? A1 : Catch;
2989
3893
  /**
2990
3894
  * Describes types that can be narrowed
2991
3895
  */
2992
- type Narrowable = string | number | bigint | boolean;
3896
+ type Narrowable = bigint | boolean | number | string;
2993
3897
  /**
2994
3898
  * @hidden
2995
3899
  */
2996
- type NarrowRaw<A> = (A extends [] ? [] : never) | (A extends Narrowable ? A : never) | {
3900
+ type NarrowRaw<A> = {
2997
3901
  [K in keyof A]: A[K] extends (...args: Array<any>) => any ? A[K] : NarrowRaw<A[K]>;
2998
- };
3902
+ } | (A extends [] ? [] : never) | (A extends Narrowable ? A : never);
2999
3903
  /**
3000
3904
  * Prevent type widening on generic function parameters
3001
3905
  * @param A to narrow
@@ -3016,6 +3920,14 @@ type NarrowRaw<A> = (A extends [] ? [] : never) | (A extends Narrowable ? A : ne
3016
3920
  */
3017
3921
  type Narrow<A> = Try<A, [], NarrowRaw<A>>;
3018
3922
 
3923
+ type Path<Obj, Prefix extends Array<PropertyKey> = []> = Obj extends Primitive ? Prefix : Obj extends Array<infer Item> ? Path<Item, [...Prefix, number]> | Prefix : PathsOfObject<Obj, Prefix> | Prefix;
3924
+ type PathsOfObject<Obj, Prefix extends Array<PropertyKey>> = {
3925
+ [K in keyof Obj]: Path<Obj[K], [...Prefix, K]>;
3926
+ }[keyof Obj];
3927
+ type ValueAtPath<Obj, ObjPath extends Array<PropertyKey> = []> = ObjPath extends [] ? Obj : ObjPath extends [infer Head, ...infer Tail] ? Tail extends Array<PropertyKey> ? Head extends keyof Obj ? ValueAtPath<Obj[Head], Tail> : never : never : never;
3928
+ type SupportsValueAtPath<Obj, Path extends Array<PropertyKey>, Value> = Value extends ValueAtPath<Obj, Path> ? Obj : never;
3929
+ type Primitive = boolean | null | number | string | symbol | undefined;
3930
+
3019
3931
  /**
3020
3932
  * Sets the value at `path` of `object`. `path` can be an array or a path string.
3021
3933
  * @param object the target method
@@ -3086,13 +3998,12 @@ declare function swapProps<T extends object, K1 extends keyof T, K2 extends keyo
3086
3998
  */
3087
3999
  declare function swapProps<T extends object, K1 extends keyof T, K2 extends keyof T>(key1: K1, key2: K2): (data: T) => SwappedProps<T, K1, K2>;
3088
4000
 
3089
- type ObjectKeys<T extends object> = `${Exclude<keyof T, symbol>}`;
3090
- type ObjectValues<T extends Record<PropertyKey, unknown>> = Required<T>[ObjectKeys<T>];
3091
- type ObjectEntry<T extends Record<PropertyKey, unknown>> = [
3092
- ObjectKeys<T>,
3093
- ObjectValues<T>
3094
- ];
3095
- type ObjectEntries<T extends Record<PropertyKey, unknown>> = Array<ObjectEntry<T>>;
4001
+ type Pairs<T> = Array<{
4002
+ [K in keyof T]-?: [key: K, value: Required<T>[K]];
4003
+ }[keyof T]>;
4004
+ interface Strict {
4005
+ <T extends NonNullable<unknown>>(object: T): Pairs<T>;
4006
+ }
3096
4007
  /**
3097
4008
  * Returns an array of key/values of the enumerable properties of an object.
3098
4009
  * @param object
@@ -3102,12 +4013,21 @@ type ObjectEntries<T extends Record<PropertyKey, unknown>> = Array<ObjectEntry<T
3102
4013
  * @example
3103
4014
  * P.toPairs({ a: 1, b: 2, c: 3 }) // => [['a', 1], ['b', 2], ['c', 3]]
3104
4015
  * P.toPairs.strict({ a: 1 } as const) // => [['a', 1]] typed Array<['a', 1]>
4016
+ * P.pipe(
4017
+ * { a: 1, b: 2, c: 3 },
4018
+ * toPairs,
4019
+ * ); // => [['a', 1], ['b', 2], ['c', 3]]
4020
+ * P.pipe(
4021
+ * { a: 1 } as const,
4022
+ * toPairs.strict,
4023
+ * ); // => [['a', 1]] typed Array<['a', 1]>
3105
4024
  * @strict
3106
4025
  * @category Object
4026
+ * @dataFirst
3107
4027
  */
3108
4028
  declare function toPairs<T>(object: Record<string, T>): Array<[string, T]>;
3109
4029
  declare namespace toPairs {
3110
- function strict<T extends Record<PropertyKey, unknown>>(object: T): ObjectEntries<T>;
4030
+ const strict: Strict;
3111
4031
  }
3112
4032
 
3113
4033
  /**
@@ -3126,17 +4046,22 @@ declare namespace toPairs {
3126
4046
  * @pipeable
3127
4047
  * @category Object
3128
4048
  */
3129
- type Values<T extends object> = T extends ReadonlyArray<unknown> | [] ? Array<T[number]> : Array<T[keyof T]>;
4049
+ type Values<T extends object> = T extends [] | ReadonlyArray<unknown> ? Array<T[number]> : Array<T[keyof T]>;
3130
4050
  declare function values<T extends object>(source: T): Values<T>;
3131
4051
 
3132
- type Splitter = '-' | '_' | '/' | '.';
3133
- type LastOfArray<T extends any[]> = T extends [...any, infer R] ? R : never;
3134
- type RemoveLastOfArray<T extends any[]> = T extends [...infer F, any] ? F : never;
4052
+ type Splitter = '.' | '/' | '_' | '-';
4053
+ type FirstOfString<S extends string> = S extends `${infer F}${string}` ? F : never;
4054
+ type RemoveFirstOfString<S extends string> = S extends `${string}${infer R}` ? R : never;
3135
4055
  type IsUpper<S extends string> = S extends Uppercase<S> ? true : false;
3136
4056
  type IsLower<S extends string> = S extends Lowercase<S> ? true : false;
3137
4057
  type SameLetterCase<X extends string, Y extends string> = IsUpper<X> extends IsUpper<Y> ? true : IsLower<X> extends IsLower<Y> ? true : false;
3138
- type FirstOfString<S extends string> = S extends `${infer F}${string}` ? F : never;
3139
- type RemoveFirstOfString<S extends string> = S extends `${string}${infer R}` ? R : never;
4058
+ type CapitalizedWords<T extends readonly string[], Accumulator extends string = '', Normalize extends boolean | undefined = false> = T extends readonly [infer F extends string, ...infer R extends string[]] ? CapitalizedWords<R, `${Accumulator}${Capitalize<Normalize extends true ? Lowercase<F> : F>}`, Normalize> : Accumulator;
4059
+ type JoinLowercaseWords<T extends readonly string[], Joiner extends string, Accumulator extends string = ''> = T extends readonly [infer F extends string, ...infer R extends string[]] ? Accumulator extends '' ? JoinLowercaseWords<R, Joiner, `${Accumulator}${Lowercase<F>}`> : JoinLowercaseWords<R, Joiner, `${Accumulator}${Joiner}${Lowercase<F>}`> : Accumulator;
4060
+ type LastOfArray<T extends any[]> = T extends [...any, infer R] ? R : never;
4061
+ type RemoveLastOfArray<T extends any[]> = T extends [...infer F, any] ? F : never;
4062
+ interface CaseOptions {
4063
+ normalize?: boolean;
4064
+ }
3140
4065
  type SplitByCase<T, Separator extends string = Splitter, Accumulator extends unknown[] = []> = string extends Separator ? string[] : T extends `${infer F}${infer R}` ? [LastOfArray<Accumulator>] extends [never] ? SplitByCase<R, Separator, [F]> : LastOfArray<Accumulator> extends string ? R extends '' ? SplitByCase<R, Separator, [
3141
4066
  ...RemoveLastOfArray<Accumulator>,
3142
4067
  `${LastOfArray<Accumulator>}${F}`
@@ -3151,26 +4076,34 @@ type SplitByCase<T, Separator extends string = Splitter, Accumulator extends unk
3151
4076
  `${LastOfArray<Accumulator>}${F}`,
3152
4077
  FirstOfString<R>
3153
4078
  ]> : SplitByCase<R, Separator, [...Accumulator, F]> : never : Accumulator extends [] ? T extends '' ? [] : string[] : Accumulator;
3154
- type CapitalizedWords<T extends readonly string[], Accumulator extends string = ''> = T extends readonly [infer F extends string, ...infer R extends string[]] ? CapitalizedWords<R, `${Accumulator}${Capitalize<F>}`> : Accumulator;
3155
- type JoinLowercaseWords<T extends readonly string[], Joiner extends string, Accumulator extends string = ''> = T extends readonly [infer F extends string, ...infer R extends string[]] ? Accumulator extends '' ? JoinLowercaseWords<R, Joiner, `${Accumulator}${Lowercase<F>}`> : JoinLowercaseWords<R, Joiner, `${Accumulator}${Joiner}${Lowercase<F>}`> : Accumulator;
3156
- type PascalCase<T> = string extends T ? string : string[] extends T ? string : T extends string ? SplitByCase<T> extends readonly string[] ? CapitalizedWords<SplitByCase<T>> : never : T extends readonly string[] ? CapitalizedWords<T> : never;
3157
- type CamelCase<T> = string extends T ? string : string[] extends T ? string : Uncapitalize<PascalCase<T>>;
3158
4079
  type JoinByCase<T, Joiner extends string> = string extends T ? string : string[] extends T ? string : T extends string ? SplitByCase<T> extends readonly string[] ? JoinLowercaseWords<SplitByCase<T>, Joiner> : never : T extends readonly string[] ? JoinLowercaseWords<T, Joiner> : never;
4080
+ type PascalCase<T, Normalize extends boolean | undefined = false> = string extends T ? string : string[] extends T ? string : T extends string ? SplitByCase<T> extends readonly string[] ? CapitalizedWords<SplitByCase<T>, '', Normalize> : never : T extends readonly string[] ? CapitalizedWords<T, '', Normalize> : never;
4081
+ type CamelCase<T, Normalize extends boolean | undefined = false> = string extends T ? string : string[] extends T ? string : Uncapitalize<PascalCase<T, Normalize>>;
4082
+ type KebabCase<T extends readonly string[] | string, Joiner extends string = '-'> = JoinByCase<T, Joiner>;
4083
+ type SnakeCase<T extends readonly string[] | string> = JoinByCase<T, '_'>;
4084
+ type TrainCase<T, Normalize extends boolean | undefined = false, Joiner extends string = '-'> = string extends T ? string : string[] extends T ? string : T extends string ? SplitByCase<T> extends readonly string[] ? CapitalizedWords<SplitByCase<T>, Joiner> : never : T extends readonly string[] ? CapitalizedWords<T, Joiner, Normalize> : never;
4085
+ type FlatCase<T extends readonly string[] | string, Joiner extends string = ''> = JoinByCase<T, Joiner>;
3159
4086
 
3160
4087
  declare function isUppercase(char?: string): boolean | undefined;
3161
- declare function splitByCase<T extends string>(string_: T): SplitByCase<T>;
3162
- declare function splitByCase<T extends string, Separator extends readonly string[]>(string_: T, separators: Separator): SplitByCase<T, Separator[number]>;
3163
- declare function toUpperFirst<S extends string>(string_: S): Capitalize<S>;
3164
- declare function toLowerFirst<S extends string>(string_: S): Uncapitalize<S>;
4088
+ declare function splitByCase<T extends string>(str: T): SplitByCase<T>;
4089
+ declare function splitByCase<T extends string, Separator extends readonly string[]>(str: T, separators: Separator): SplitByCase<T, Separator[number]>;
4090
+ declare function toUpperFirst<S extends string>(str: S): Capitalize<S>;
4091
+ declare function toLowerFirst<S extends string>(str: S): Uncapitalize<S>;
3165
4092
  declare function toPascalCase(): '';
3166
- declare function toPascalCase<T extends string | readonly string[]>(string_?: T): PascalCase<T>;
4093
+ declare function toPascalCase<T extends readonly string[] | string, UserCaseOptions extends CaseOptions = CaseOptions>(str: T, opts?: CaseOptions): PascalCase<T, UserCaseOptions['normalize']>;
3167
4094
  declare function toCamelCase(): '';
3168
- declare function toCamelCase<T extends string | readonly string[]>(string_?: T): CamelCase<T>;
4095
+ declare function toCamelCase<T extends readonly string[] | string, UserCaseOptions extends CaseOptions = CaseOptions>(str: T, opts?: UserCaseOptions): CamelCase<T, UserCaseOptions['normalize']>;
3169
4096
  declare function toKebabCase(): '';
3170
- declare function toKebabCase<T extends string | readonly string[]>(string_?: T): JoinByCase<T, '-'>;
3171
- declare function toKebabCase<T extends string | readonly string[], Joiner extends string>(string_: T, joiner: Joiner): JoinByCase<T, Joiner>;
4097
+ declare function toKebabCase<T extends readonly string[] | string>(str: T): KebabCase<T>;
4098
+ declare function toKebabCase<T extends readonly string[] | string, Joiner extends string>(str: T, joiner: Joiner): KebabCase<T, Joiner>;
3172
4099
  declare function toSnakeCase(): '';
3173
- declare function toSnakeCase<T extends string | readonly string[]>(string_?: T): JoinByCase<T, '_'>;
4100
+ declare function toSnakeCase<T extends readonly string[] | string>(str: T): SnakeCase<T>;
4101
+ declare function toFlatCase(): '';
4102
+ declare function toFlatCase<T extends readonly string[] | string>(str: T): FlatCase<T>;
4103
+ declare function toTrainCase(): '';
4104
+ declare function toTrainCase<T extends readonly string[] | string, UserCaseOptions extends CaseOptions = CaseOptions>(str: T, opts?: UserCaseOptions): TrainCase<T, UserCaseOptions['normalize']>;
4105
+ declare function titleCase(): '';
4106
+ declare function titleCase<T extends readonly string[] | string, UserCaseOptions extends CaseOptions = CaseOptions>(str: T, opts?: UserCaseOptions): TrainCase<T, UserCaseOptions['normalize'], ' '>;
3174
4107
 
3175
4108
  /**
3176
4109
  * Returns human readable file size.
@@ -3235,8 +4168,8 @@ type StringToPath<T extends string> = T extends '' ? [] : T extends `[${infer He
3235
4168
  * P.type(undefined); //=> "Undefined"
3236
4169
  * @category Type
3237
4170
  */
3238
- declare function type(val: any): string;
4171
+ declare function type(val: unknown): string;
3239
4172
 
3240
4173
  declare const isBrowser: boolean;
3241
4174
 
3242
- export { DeepPartial, Joined, KEY_CODES, StringToPath, _setPath, addProp, allPass, anyPass, chunk, clamp, clone, compact, concat, countBy, createPipe, difference, differenceWith, drop, dropLast, equals, filter, find, findIndex, findLast, findLastIndex, first, flatMap, flatMapToObj, flatten, flattenDeep, forEach, forEachObj, fromPairs, groupBy, humanReadableFileSize, identity, indexBy, intersection, intersectionWith, invert, isArray, isBoolean, isBrowser, isDate, isDefined, isEmpty, isError, isFunction, isNil, isNonNull, isNot, isNumber, isObject, isPromise, isString, isTruthy, isUppercase, join, keys, last, length, map, mapKeys, mapToObj, mapValues, maxBy, meanBy, merge, mergeAll, mergeDeep, minBy, noop, omit, omitBy, once, partition, pathOr, pick, pickBy, pipe, prop, purry, randomString, range, reduce, reject, reverse, sample, set, setPath, shuffle, sleep, slugify, sort, sortBy, splitAt, splitByCase, splitWhen, stringToPath, sumBy, swapIndices, swapProps, take, takeWhile, toCamelCase, toKebabCase, toLowerFirst, toPairs, toPascalCase, toSnakeCase, toUpperFirst, type, uniq, uniqBy, uniqWith, values, zip, zipObj, zipWith };
4175
+ export { type Joined, KEY_CODES, type StringToPath, _setPath, add, addProp, allPass, anyPass, ceil, chunk, clamp, clone, compact, concat, conditional, countBy, createPipe, debounce, difference, differenceWith, divide, drop, dropFirstBy, dropLast, dropLastWhile, dropWhile, equals, filter, find, findIndex, findLast, findLastIndex, first, firstBy, flatMap, flatMapToObj, flatten, flattenDeep, floor, forEach, forEachObj, fromPairs, groupBy, hasAtLeast, humanReadableFileSize, identity, indexBy, intersection, intersectionWith, invert, isArray, isBoolean, isBrowser, isDate, isDefined, isEmpty, isError, isFunction, isNil, isNonNull, isNot, isNumber, isObject, isPromise, isString, isSymbol, isTruthy, isUppercase, join, keys, last, length, map, mapKeys, mapToObj, mapValues, maxBy, meanBy, merge, mergeAll, mergeDeep, minBy, multiply, noop, nthBy, omit, omitBy, once, only, partition, pathOr, pick, pickBy, pipe, prop, purry, randomString, range, rankBy, reduce, reject, reverse, round, sample, set, setPath, shuffle, sleep, slugify, sort, sortBy, splice, splitAt, splitByCase, splitWhen, stringToPath, subtract, sumBy, swapIndices, swapProps, take, takeFirstBy, takeWhile, titleCase, toCamelCase, toFlatCase, toKebabCase, toLowerFirst, toPairs, toPascalCase, toSnakeCase, toTrainCase, toUpperFirst, type, uniq, uniqBy, uniqWith, values, zip, zipObj, zipWith };