@oscarpalmer/atoms 0.77.0 → 0.77.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/js/array/chunk.cjs +1 -1
  2. package/dist/js/array/chunk.js +1 -1
  3. package/dist/js/value/equal.cjs +4 -1
  4. package/dist/js/value/equal.js +4 -1
  5. package/package.json +1 -1
  6. package/src/js/array/chunk.ts +1 -1
  7. package/src/js/array/count.ts +6 -6
  8. package/src/js/array/exists.ts +6 -6
  9. package/src/js/array/filter.ts +6 -6
  10. package/src/js/array/find.ts +6 -6
  11. package/src/js/array/group-by.ts +67 -55
  12. package/src/js/array/index-of.ts +6 -6
  13. package/src/js/array/sort.ts +20 -0
  14. package/src/js/array/to-map.ts +55 -47
  15. package/src/js/array/to-record.ts +61 -57
  16. package/src/js/array/unique.ts +6 -6
  17. package/src/js/internal/value/handle.ts +5 -5
  18. package/src/js/value/clone.ts +3 -1
  19. package/src/js/value/equal.ts +4 -1
  20. package/src/js/value/get.ts +9 -9
  21. package/src/js/value/set.ts +10 -11
  22. package/types/array/count.d.cts +34 -2
  23. package/types/array/count.d.ts +3 -3
  24. package/types/array/exists.d.cts +34 -2
  25. package/types/array/exists.d.ts +3 -3
  26. package/types/array/filter.d.cts +34 -2
  27. package/types/array/filter.d.ts +3 -3
  28. package/types/array/find.d.cts +34 -2
  29. package/types/array/find.d.ts +3 -3
  30. package/types/array/group-by.d.cts +44 -12
  31. package/types/array/group-by.d.ts +14 -14
  32. package/types/array/index-of.d.cts +34 -2
  33. package/types/array/index-of.d.ts +3 -3
  34. package/types/array/index.d.cts +88 -46
  35. package/types/array/sort.d.cts +42 -0
  36. package/types/array/sort.d.ts +11 -1
  37. package/types/array/to-map.d.cts +42 -10
  38. package/types/array/to-map.d.ts +13 -13
  39. package/types/array/to-record.d.cts +44 -12
  40. package/types/array/to-record.d.ts +13 -13
  41. package/types/array/unique.d.cts +34 -2
  42. package/types/array/unique.d.ts +3 -3
  43. package/types/index.d.cts +1034 -317
  44. package/types/internal/value/handle.d.cts +27 -2
  45. package/types/internal/value/handle.d.ts +2 -2
  46. package/types/models.d.cts +467 -210
  47. package/types/value/clone.d.cts +1 -1
  48. package/types/value/clone.d.ts +1 -1
  49. package/types/value/get.d.cts +470 -211
  50. package/types/value/get.d.ts +3 -3
  51. package/types/value/index.d.cts +515 -224
  52. package/types/value/set.d.cts +357 -170
  53. package/types/value/set.d.ts +3 -3
  54. package/types/value/smush.d.cts +463 -209
@@ -5,7 +5,14 @@ Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/
5
5
 
6
6
  @category Type
7
7
  */
8
- export type Primitive = null | undefined | string | number | boolean | symbol | bigint;
8
+ export type Primitive =
9
+ | null
10
+ | undefined
11
+ | string
12
+ | number
13
+ | boolean
14
+ | symbol
15
+ | bigint;
9
16
  /**
10
17
  Create a union of all keys from a given type, even those exclusive to specific union members.
11
18
 
@@ -43,7 +50,9 @@ type AllKeys = KeysOfUnion<Union>;
43
50
 
44
51
  @category Object
45
52
  */
46
- export type KeysOfUnion<ObjectType> = ObjectType extends unknown ? keyof ObjectType : never;
53
+ export type KeysOfUnion<ObjectType> = ObjectType extends unknown
54
+ ? keyof ObjectType
55
+ : never;
47
56
  declare const emptyObjectSymbol: unique symbol;
48
57
  /**
49
58
  Represents a strictly empty plain object, the `{}` value.
@@ -100,7 +109,11 @@ type Includes<Value extends readonly any[], Item> =
100
109
  @category Type Guard
101
110
  @category Utilities
102
111
  */
103
- export type IsEqual<A, B> = (<G>() => G extends A ? 1 : 2) extends (<G>() => G extends B ? 1 : 2) ? true : false;
112
+ export type IsEqual<A, B> = (<G>() => G extends A ? 1 : 2) extends <
113
+ G,
114
+ >() => G extends B ? 1 : 2
115
+ ? true
116
+ : false;
104
117
  /**
105
118
  Represents an object with `unknown` value. You probably want this instead of `{}`.
106
119
 
@@ -227,14 +240,16 @@ type B = StaticPartOfArray<A>;
227
240
  //=> [string, number, boolean]
228
241
  ```
229
242
  */
230
- export type StaticPartOfArray<T extends UnknownArray, Result extends UnknownArray = [
231
- ]> = T extends unknown ? number extends T["length"] ? T extends readonly [
232
- infer U,
233
- ...infer V
234
- ] ? StaticPartOfArray<V, [
235
- ...Result,
236
- U
237
- ]> : Result : T : never; // Should never happen
243
+ export type StaticPartOfArray<
244
+ T extends UnknownArray,
245
+ Result extends UnknownArray = [],
246
+ > = T extends unknown
247
+ ? number extends T['length']
248
+ ? T extends readonly [infer U, ...infer V]
249
+ ? StaticPartOfArray<V, [...Result, U]>
250
+ : Result
251
+ : T
252
+ : never; // Should never happen
238
253
  /**
239
254
  Returns the variable, non-fixed-length portion of the given array, excluding static-length parts.
240
255
 
@@ -245,12 +260,22 @@ type B = VariablePartOfArray<A>;
245
260
  //=> string[]
246
261
  ```
247
262
  */
248
- export type VariablePartOfArray<T extends UnknownArray> = T extends unknown ? T extends readonly [
249
- ...StaticPartOfArray<T>,
250
- ...infer U
251
- ] ? U : [
252
- ] : never; // Should never happen
253
- export type StringDigit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
263
+ export type VariablePartOfArray<T extends UnknownArray> = T extends unknown
264
+ ? T extends readonly [...StaticPartOfArray<T>, ...infer U]
265
+ ? U
266
+ : []
267
+ : never; // Should never happen
268
+ export type StringDigit =
269
+ | '0'
270
+ | '1'
271
+ | '2'
272
+ | '3'
273
+ | '4'
274
+ | '5'
275
+ | '6'
276
+ | '7'
277
+ | '8'
278
+ | '9';
254
279
  /**
255
280
  Returns a boolean for whether the given type is `any`.
256
281
 
@@ -293,7 +318,7 @@ Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277)
293
318
  */
294
319
  // See https://github.com/microsoft/TypeScript/issues/31752
295
320
  // eslint-disable-next-line @typescript-eslint/no-loss-of-precision
296
- export type PositiveInfinity = Infinity;
321
+ export type PositiveInfinity = 1e999;
297
322
  /**
298
323
  Matches the hidden `-Infinity` type.
299
324
 
@@ -305,7 +330,7 @@ Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277)
305
330
  */
306
331
  // See https://github.com/microsoft/TypeScript/issues/31752
307
332
  // eslint-disable-next-line @typescript-eslint/no-loss-of-precision
308
- export type NegativeInfinity = -Infinity;
333
+ export type NegativeInfinity = -1e999;
309
334
  /**
310
335
  A negative `number`/`bigint` (`-∞ < x < 0`)
311
336
 
@@ -316,7 +341,11 @@ Use-case: Validating and documenting parameters.
316
341
 
317
342
  @category Numeric
318
343
  */
319
- export type Negative<T extends Numeric> = T extends Zero ? never : `${T}` extends `-${string}` ? T : never;
344
+ export type Negative<T extends Numeric> = T extends Zero
345
+ ? never
346
+ : `${T}` extends `-${string}`
347
+ ? T
348
+ : never;
320
349
  /**
321
350
  Returns a boolean for whether the given number is a negative number.
322
351
 
@@ -332,7 +361,9 @@ type ShouldBeTrue = IsNegative<-1>;
332
361
 
333
362
  @category Numeric
334
363
  */
335
- export type IsNegative<T extends Numeric> = T extends Negative<T> ? true : false;
364
+ export type IsNegative<T extends Numeric> = T extends Negative<T>
365
+ ? true
366
+ : false;
336
367
  /**
337
368
  Returns a boolean for whether two given types are both true.
338
369
 
@@ -353,11 +384,12 @@ And<true, false>;
353
384
  */
354
385
  export type And<A extends boolean, B extends boolean> = [
355
386
  A,
356
- B
357
- ][number] extends true ? true : true extends [
358
- IsEqual<A, false>,
359
- IsEqual<B, false>
360
- ][number] ? false : never;
387
+ B,
388
+ ][number] extends true
389
+ ? true
390
+ : true extends [IsEqual<A, false>, IsEqual<B, false>][number]
391
+ ? false
392
+ : never;
361
393
  /**
362
394
  Returns a boolean for whether either of two given types are true.
363
395
 
@@ -378,11 +410,12 @@ Or<false, false>;
378
410
  */
379
411
  export type Or<A extends boolean, B extends boolean> = [
380
412
  A,
381
- B
382
- ][number] extends false ? false : true extends [
383
- IsEqual<A, true>,
384
- IsEqual<B, true>
385
- ][number] ? true : never;
413
+ B,
414
+ ][number] extends false
415
+ ? false
416
+ : true extends [IsEqual<A, true>, IsEqual<B, true>][number]
417
+ ? true
418
+ : never;
386
419
  /**
387
420
  Returns a boolean for whether a given number is greater than another number.
388
421
 
@@ -400,32 +433,44 @@ GreaterThan<1, 5>;
400
433
  //=> false
401
434
  ```
402
435
  */
403
- export type GreaterThan<A extends number, B extends number> = number extends A | B ? never : [
404
- IsEqual<A, PositiveInfinity>,
405
- IsEqual<A, NegativeInfinity>,
406
- IsEqual<B, PositiveInfinity>,
407
- IsEqual<B, NegativeInfinity>
408
- ] extends infer R extends [
409
- boolean,
410
- boolean,
411
- boolean,
412
- boolean
413
- ] ? Or<And<IsEqual<R[0], true>, IsEqual<R[2], false>>, And<IsEqual<R[3], true>, IsEqual<R[1], false>>> extends true ? true : Or<And<IsEqual<R[1], true>, IsEqual<R[3], false>>, And<IsEqual<R[2], true>, IsEqual<R[0], false>>> extends true ? false : true extends R[number] ? false : [
414
- IsNegative<A>,
415
- IsNegative<B>
416
- ] extends infer R extends [
417
- boolean,
418
- boolean
419
- ] ? [
420
- true,
421
- false
422
- ] extends R ? false : [
423
- false,
424
- true
425
- ] extends R ? true : [
426
- false,
427
- false
428
- ] extends R ? PositiveNumericStringGt<`${A}`, `${B}`> : PositiveNumericStringGt<`${NumberAbsolute<B>}`, `${NumberAbsolute<A>}`> : never : never;
436
+ export type GreaterThan<A extends number, B extends number> = number extends
437
+ | A
438
+ | B
439
+ ? never
440
+ : [
441
+ IsEqual<A, PositiveInfinity>,
442
+ IsEqual<A, NegativeInfinity>,
443
+ IsEqual<B, PositiveInfinity>,
444
+ IsEqual<B, NegativeInfinity>,
445
+ ] extends infer R extends [boolean, boolean, boolean, boolean]
446
+ ? Or<
447
+ And<IsEqual<R[0], true>, IsEqual<R[2], false>>,
448
+ And<IsEqual<R[3], true>, IsEqual<R[1], false>>
449
+ > extends true
450
+ ? true
451
+ : Or<
452
+ And<IsEqual<R[1], true>, IsEqual<R[3], false>>,
453
+ And<IsEqual<R[2], true>, IsEqual<R[0], false>>
454
+ > extends true
455
+ ? false
456
+ : true extends R[number]
457
+ ? false
458
+ : [IsNegative<A>, IsNegative<B>] extends infer R extends [
459
+ boolean,
460
+ boolean,
461
+ ]
462
+ ? [true, false] extends R
463
+ ? false
464
+ : [false, true] extends R
465
+ ? true
466
+ : [false, false] extends R
467
+ ? PositiveNumericStringGt<`${A}`, `${B}`>
468
+ : PositiveNumericStringGt<
469
+ `${NumberAbsolute<B>}`,
470
+ `${NumberAbsolute<A>}`
471
+ >
472
+ : never
473
+ : never;
429
474
  /**
430
475
  Returns a boolean for whether a given number is greater than or equal to another number.
431
476
 
@@ -443,7 +488,10 @@ GreaterThanOrEqual<1, 5>;
443
488
  //=> false
444
489
  ```
445
490
  */
446
- export type GreaterThanOrEqual<A extends number, B extends number> = number extends A | B ? never : A extends B ? true : GreaterThan<A, B>;
491
+ export type GreaterThanOrEqual<
492
+ A extends number,
493
+ B extends number,
494
+ > = number extends A | B ? never : A extends B ? true : GreaterThan<A, B>;
447
495
  /**
448
496
  Returns a boolean for whether a given number is less than another number.
449
497
 
@@ -461,7 +509,11 @@ LessThan<1, 5>;
461
509
  //=> true
462
510
  ```
463
511
  */
464
- export type LessThan<A extends number, B extends number> = number extends A | B ? never : GreaterThanOrEqual<A, B> extends true ? false : true;
512
+ export type LessThan<A extends number, B extends number> = number extends A | B
513
+ ? never
514
+ : GreaterThanOrEqual<A, B> extends true
515
+ ? false
516
+ : true;
465
517
  /**
466
518
  Create a tuple type of the given length `<L>` and fill it with the given type `<Fill>`.
467
519
 
@@ -469,11 +521,11 @@ If `<Fill>` is not provided, it will default to `unknown`.
469
521
 
470
522
  @link https://itnext.io/implementing-arithmetic-within-typescripts-type-system-a1ef140a6f6f
471
523
  */
472
- export type BuildTuple<L extends number, Fill = unknown, T extends readonly unknown[] = [
473
- ]> = T["length"] extends L ? T : BuildTuple<L, Fill, [
474
- ...T,
475
- Fill
476
- ]>;
524
+ export type BuildTuple<
525
+ L extends number,
526
+ Fill = unknown,
527
+ T extends readonly unknown[] = [],
528
+ > = T['length'] extends L ? T : BuildTuple<L, Fill, [...T, Fill]>;
477
529
  /**
478
530
  Returns the maximum value from a tuple of integers.
479
531
 
@@ -489,10 +541,16 @@ ArrayMax<[1, 2, 5, 3, 99, -1]>;
489
541
  //=> 99
490
542
  ```
491
543
  */
492
- export type TupleMax<A extends number[], Result extends number = NegativeInfinity> = number extends A[number] ? never : A extends [
493
- infer F extends number,
494
- ...infer R extends number[]
495
- ] ? GreaterThan<F, Result> extends true ? TupleMax<R, F> : TupleMax<R, Result> : Result;
544
+ export type TupleMax<
545
+ A extends number[],
546
+ Result extends number = NegativeInfinity,
547
+ > = number extends A[number]
548
+ ? never
549
+ : A extends [infer F extends number, ...infer R extends number[]]
550
+ ? GreaterThan<F, Result> extends true
551
+ ? TupleMax<R, F>
552
+ : TupleMax<R, Result>
553
+ : Result;
496
554
  /**
497
555
  Returns the minimum value from a tuple of integers.
498
556
 
@@ -508,10 +566,16 @@ ArrayMin<[1, 2, 5, 3, -5]>;
508
566
  //=> -5
509
567
  ```
510
568
  */
511
- export type TupleMin<A extends number[], Result extends number = PositiveInfinity> = number extends A[number] ? never : A extends [
512
- infer F extends number,
513
- ...infer R extends number[]
514
- ] ? LessThan<F, Result> extends true ? TupleMin<R, F> : TupleMin<R, Result> : Result;
569
+ export type TupleMin<
570
+ A extends number[],
571
+ Result extends number = PositiveInfinity,
572
+ > = number extends A[number]
573
+ ? never
574
+ : A extends [infer F extends number, ...infer R extends number[]]
575
+ ? LessThan<F, Result> extends true
576
+ ? TupleMin<R, F>
577
+ : TupleMin<R, Result>
578
+ : Result;
515
579
  /**
516
580
  Return a string representation of the given string or number.
517
581
 
@@ -546,7 +610,14 @@ type NegativeInfinity = StringToNumber<'-Infinity'>;
546
610
  @category Numeric
547
611
  @category Template literal
548
612
  */
549
- export type StringToNumber<S extends string> = S extends `${infer N extends number}` ? N : S extends "Infinity" ? PositiveInfinity : S extends "-Infinity" ? NegativeInfinity : never;
613
+ export type StringToNumber<S extends string> =
614
+ S extends `${infer N extends number}`
615
+ ? N
616
+ : S extends 'Infinity'
617
+ ? PositiveInfinity
618
+ : S extends '-Infinity'
619
+ ? NegativeInfinity
620
+ : never;
550
621
  /**
551
622
  Returns an array of the characters of the string.
552
623
 
@@ -561,11 +632,14 @@ StringToArray<string>;
561
632
 
562
633
  @category String
563
634
  */
564
- export type StringToArray<S extends string, Result extends string[] = [
565
- ]> = string extends S ? never : S extends `${infer F}${infer R}` ? StringToArray<R, [
566
- ...Result,
567
- F
568
- ]> : Result;
635
+ export type StringToArray<
636
+ S extends string,
637
+ Result extends string[] = [],
638
+ > = string extends S
639
+ ? never
640
+ : S extends `${infer F}${infer R}`
641
+ ? StringToArray<R, [...Result, F]>
642
+ : Result;
569
643
  /**
570
644
  Returns the length of the given string.
571
645
 
@@ -581,7 +655,9 @@ StringLength<string>;
581
655
  @category String
582
656
  @category Template literal
583
657
  */
584
- export type StringLength<S extends string> = string extends S ? never : StringToArray<S>["length"];
658
+ export type StringLength<S extends string> = string extends S
659
+ ? never
660
+ : StringToArray<S>['length'];
585
661
  /**
586
662
  Returns a boolean for whether `A` represents a number greater than `B`, where `A` and `B` are both numeric strings and have the same length.
587
663
 
@@ -594,8 +670,17 @@ SameLengthPositiveNumericStringGt<'10', '10'>;
594
670
  //=> false
595
671
  ```
596
672
  */
597
- export type SameLengthPositiveNumericStringGt<A extends string, B extends string> = A extends `${infer FirstA}${infer RestA}` ? B extends `${infer FirstB}${infer RestB}` ? FirstA extends FirstB ? SameLengthPositiveNumericStringGt<RestA, RestB> : PositiveNumericCharacterGt<FirstA, FirstB> : never : false;
598
- export type NumericString = "0123456789";
673
+ export type SameLengthPositiveNumericStringGt<
674
+ A extends string,
675
+ B extends string,
676
+ > = A extends `${infer FirstA}${infer RestA}`
677
+ ? B extends `${infer FirstB}${infer RestB}`
678
+ ? FirstA extends FirstB
679
+ ? SameLengthPositiveNumericStringGt<RestA, RestB>
680
+ : PositiveNumericCharacterGt<FirstA, FirstB>
681
+ : never
682
+ : false;
683
+ export type NumericString = '0123456789';
599
684
  /**
600
685
  Returns a boolean for whether `A` is greater than `B`, where `A` and `B` are both positive numeric strings.
601
686
 
@@ -611,16 +696,21 @@ PositiveNumericStringGt<'1', '500'>;
611
696
  //=> false
612
697
  ```
613
698
  */
614
- export type PositiveNumericStringGt<A extends string, B extends string> = A extends B ? false : [
615
- BuildTuple<StringLength<A>, 0>,
616
- BuildTuple<StringLength<B>, 0>
617
- ] extends infer R extends [
618
- readonly unknown[],
619
- readonly unknown[]
620
- ] ? R[0] extends [
621
- ...R[1],
622
- ...infer Remain extends readonly unknown[]
623
- ] ? 0 extends Remain["length"] ? SameLengthPositiveNumericStringGt<A, B> : true : false : never;
699
+ export type PositiveNumericStringGt<
700
+ A extends string,
701
+ B extends string,
702
+ > = A extends B
703
+ ? false
704
+ : [
705
+ BuildTuple<StringLength<A>, 0>,
706
+ BuildTuple<StringLength<B>, 0>,
707
+ ] extends infer R extends [readonly unknown[], readonly unknown[]]
708
+ ? R[0] extends [...R[1], ...infer Remain extends readonly unknown[]]
709
+ ? 0 extends Remain['length']
710
+ ? SameLengthPositiveNumericStringGt<A, B>
711
+ : true
712
+ : false
713
+ : never;
624
714
  /**
625
715
  Returns a boolean for whether `A` represents a number greater than `B`, where `A` and `B` are both positive numeric characters.
626
716
 
@@ -633,7 +723,16 @@ PositiveNumericCharacterGt<'1', '1'>;
633
723
  //=> false
634
724
  ```
635
725
  */
636
- export type PositiveNumericCharacterGt<A extends string, B extends string> = NumericString extends `${infer HeadA}${A}${infer TailA}` ? NumericString extends `${infer HeadB}${B}${infer TailB}` ? HeadA extends `${HeadB}${infer _}${infer __}` ? true : false : never : never;
726
+ export type PositiveNumericCharacterGt<
727
+ A extends string,
728
+ B extends string,
729
+ > = NumericString extends `${infer HeadA}${A}${infer TailA}`
730
+ ? NumericString extends `${infer HeadB}${B}${infer TailB}`
731
+ ? HeadA extends `${HeadB}${infer _}${infer __}`
732
+ ? true
733
+ : false
734
+ : never
735
+ : never;
637
736
  /**
638
737
  Returns the absolute value of a given value.
639
738
 
@@ -649,7 +748,10 @@ NumberAbsolute<NegativeInfinity>
649
748
  //=> PositiveInfinity
650
749
  ```
651
750
  */
652
- export type NumberAbsolute<N extends number> = `${N}` extends `-${infer StringPositiveN}` ? StringToNumber<StringPositiveN> : N;
751
+ export type NumberAbsolute<N extends number> =
752
+ `${N}` extends `-${infer StringPositiveN}`
753
+ ? StringToNumber<StringPositiveN>
754
+ : N;
653
755
  /**
654
756
  Check whether the given type is a number or a number string.
655
757
 
@@ -669,7 +771,13 @@ type C = IsNumberLike<1>;
669
771
  type D = IsNumberLike<'a'>;
670
772
  //=> false
671
773
  */
672
- export type IsNumberLike<N> = N extends number ? true : N extends `${number}` ? true : N extends `${number}.${number}` ? true : false;
774
+ export type IsNumberLike<N> = N extends number
775
+ ? true
776
+ : N extends `${number}`
777
+ ? true
778
+ : N extends `${number}.${number}`
779
+ ? true
780
+ : false;
673
781
  /**
674
782
  Matches any primitive, `void`, `Date`, or `RegExp` value.
675
783
  */
@@ -677,7 +785,12 @@ export type BuiltIns = Primitive | void | Date | RegExp;
677
785
  /**
678
786
  Matches non-recursive types.
679
787
  */
680
- export type NonRecursiveType = BuiltIns | Function | (new (...arguments_: any[]) => unknown);
788
+ export type NonRecursiveType =
789
+ | BuiltIns
790
+ | Function
791
+ | (new (
792
+ ...arguments_: any[]
793
+ ) => unknown);
681
794
  /**
682
795
  Returns the sum of two numbers.
683
796
 
@@ -709,35 +822,45 @@ Sum<PositiveInfinity, NegativeInfinity>;
709
822
  @category Numeric
710
823
  */
711
824
  // TODO: Support big integer and negative number.
712
- export type Sum<A extends number, B extends number> = number extends A | B ? number : [
713
- IsEqual<A, PositiveInfinity>,
714
- IsEqual<A, NegativeInfinity>,
715
- IsEqual<B, PositiveInfinity>,
716
- IsEqual<B, NegativeInfinity>
717
- ] extends infer R extends [
718
- boolean,
719
- boolean,
720
- boolean,
721
- boolean
722
- ] ? Or<And<IsEqual<R[0], true>, IsEqual<R[3], false>>, And<IsEqual<R[2], true>, IsEqual<R[1], false>>> extends true ? PositiveInfinity : Or<And<IsEqual<R[1], true>, IsEqual<R[2], false>>, And<IsEqual<R[3], true>, IsEqual<R[0], false>>> extends true ? NegativeInfinity : true extends R[number] ? number : ([
723
- IsNegative<A>,
724
- IsNegative<B>
725
- ] extends infer R ? [
726
- false,
727
- false
728
- ] extends R ? [
729
- ...BuildTuple<A>,
730
- ...BuildTuple<B>
731
- ]["length"] : [
732
- true,
733
- true
734
- ] extends R ? number : TupleMax<[
735
- NumberAbsolute<A>,
736
- NumberAbsolute<B>
737
- ]> extends infer Max_ ? TupleMin<[
738
- NumberAbsolute<A>,
739
- NumberAbsolute<B>
740
- ]> extends infer Min_ extends number ? Max_ extends A | B ? Subtract<Max_, Min_> : number : never : never : never) & number : never;
825
+ export type Sum<A extends number, B extends number> = number extends A | B
826
+ ? number
827
+ : [
828
+ IsEqual<A, PositiveInfinity>,
829
+ IsEqual<A, NegativeInfinity>,
830
+ IsEqual<B, PositiveInfinity>,
831
+ IsEqual<B, NegativeInfinity>,
832
+ ] extends infer R extends [boolean, boolean, boolean, boolean]
833
+ ? Or<
834
+ And<IsEqual<R[0], true>, IsEqual<R[3], false>>,
835
+ And<IsEqual<R[2], true>, IsEqual<R[1], false>>
836
+ > extends true
837
+ ? PositiveInfinity
838
+ : Or<
839
+ And<IsEqual<R[1], true>, IsEqual<R[2], false>>,
840
+ And<IsEqual<R[3], true>, IsEqual<R[0], false>>
841
+ > extends true
842
+ ? NegativeInfinity
843
+ : true extends R[number]
844
+ ? number
845
+ : ([IsNegative<A>, IsNegative<B>] extends infer R
846
+ ? [false, false] extends R
847
+ ? [...BuildTuple<A>, ...BuildTuple<B>]['length']
848
+ : [true, true] extends R
849
+ ? number
850
+ : TupleMax<
851
+ [NumberAbsolute<A>, NumberAbsolute<B>]
852
+ > extends infer Max_
853
+ ? TupleMin<
854
+ [NumberAbsolute<A>, NumberAbsolute<B>]
855
+ > extends infer Min_ extends number
856
+ ? Max_ extends A | B
857
+ ? Subtract<Max_, Min_>
858
+ : number
859
+ : never
860
+ : never
861
+ : never) &
862
+ number
863
+ : never;
741
864
  /**
742
865
  Returns the difference between two numbers.
743
866
 
@@ -768,29 +891,40 @@ Subtract<PositiveInfinity, PositiveInfinity>;
768
891
  @category Numeric
769
892
  */
770
893
  // TODO: Support big integer and negative number.
771
- export type Subtract<A extends number, B extends number> = number extends A | B ? number : [
772
- IsEqual<A, PositiveInfinity>,
773
- IsEqual<A, NegativeInfinity>,
774
- IsEqual<B, PositiveInfinity>,
775
- IsEqual<B, NegativeInfinity>
776
- ] extends infer R extends [
777
- boolean,
778
- boolean,
779
- boolean,
780
- boolean
781
- ] ? Or<And<IsEqual<R[0], true>, IsEqual<R[2], false>>, And<IsEqual<R[3], true>, IsEqual<R[1], false>>> extends true ? PositiveInfinity : Or<And<IsEqual<R[1], true>, IsEqual<R[3], false>>, And<IsEqual<R[2], true>, IsEqual<R[0], false>>> extends true ? NegativeInfinity : true extends R[number] ? number : [
782
- IsNegative<A>,
783
- IsNegative<B>
784
- ] extends infer R ? [
785
- false,
786
- false
787
- ] extends R ? BuildTuple<A> extends infer R ? R extends [
788
- ...BuildTuple<B>,
789
- ...infer R
790
- ] ? R["length"] : number : never : LessThan<A, B> extends true ? number : [
791
- false,
792
- true
793
- ] extends R ? Sum<A, NumberAbsolute<B>> : Subtract<NumberAbsolute<B>, NumberAbsolute<A>> : never : never;
894
+ export type Subtract<A extends number, B extends number> = number extends A | B
895
+ ? number
896
+ : [
897
+ IsEqual<A, PositiveInfinity>,
898
+ IsEqual<A, NegativeInfinity>,
899
+ IsEqual<B, PositiveInfinity>,
900
+ IsEqual<B, NegativeInfinity>,
901
+ ] extends infer R extends [boolean, boolean, boolean, boolean]
902
+ ? Or<
903
+ And<IsEqual<R[0], true>, IsEqual<R[2], false>>,
904
+ And<IsEqual<R[3], true>, IsEqual<R[1], false>>
905
+ > extends true
906
+ ? PositiveInfinity
907
+ : Or<
908
+ And<IsEqual<R[1], true>, IsEqual<R[3], false>>,
909
+ And<IsEqual<R[2], true>, IsEqual<R[0], false>>
910
+ > extends true
911
+ ? NegativeInfinity
912
+ : true extends R[number]
913
+ ? number
914
+ : [IsNegative<A>, IsNegative<B>] extends infer R
915
+ ? [false, false] extends R
916
+ ? BuildTuple<A> extends infer R
917
+ ? R extends [...BuildTuple<B>, ...infer R]
918
+ ? R['length']
919
+ : number
920
+ : never
921
+ : LessThan<A, B> extends true
922
+ ? number
923
+ : [false, true] extends R
924
+ ? Sum<A, NumberAbsolute<B>>
925
+ : Subtract<NumberAbsolute<B>, NumberAbsolute<A>>
926
+ : never
927
+ : never;
794
928
  /**
795
929
  Paths options.
796
930
 
@@ -881,28 +1015,85 @@ open('listB.1'); // TypeError. Because listB only has one element.
881
1015
  @category Object
882
1016
  @category Array
883
1017
  */
884
- export type Paths<T, Options extends PathsOptions = {}> = _Paths<T, {
885
- // Set default maxRecursionDepth to 10
886
- maxRecursionDepth: Options["maxRecursionDepth"] extends number ? Options["maxRecursionDepth"] : DefaultPathsOptions["maxRecursionDepth"];
887
- // Set default bracketNotation to false
888
- bracketNotation: Options["bracketNotation"] extends boolean ? Options["bracketNotation"] : DefaultPathsOptions["bracketNotation"];
889
- }>;
890
- export type _Paths<T, Options extends Required<PathsOptions>> = T extends NonRecursiveType | ReadonlyMap<unknown, unknown> | ReadonlySet<unknown> ? never : IsAny<T> extends true ? never : T extends UnknownArray ? number extends T["length"] ? InternalPaths<StaticPartOfArray<T>, Options> | InternalPaths<Array<VariablePartOfArray<T>[number]>, Options> : InternalPaths<T, Options> : T extends object ? InternalPaths<T, Options> : never;
891
- export type InternalPaths<T, Options extends Required<PathsOptions>> = Options["maxRecursionDepth"] extends infer MaxDepth extends number ? Required<T> extends infer T ? T extends EmptyObject | readonly [
892
- ] ? never : {
893
- [Key in keyof T]: Key extends string | number // Limit `Key` to string or number.
894
- ? (Options["bracketNotation"] extends true ? IsNumberLike<Key> extends true ? `[${Key}]` : (Key | ToString<Key>) : never | Options["bracketNotation"] extends false ? (Key | ToString<Key>) : never) extends infer TranformedKey extends string | number ?
895
- // 1. If style is 'a[0].b' and 'Key' is a numberlike value like 3 or '3', transform 'Key' to `[${Key}]`, else to `${Key}` | Key
896
- // 2. If style is 'a.0.b', transform 'Key' to `${Key}` | Key
897
- TranformedKey | (
898
- // Recursively generate paths for the current key
899
- GreaterThan<MaxDepth, 0> extends true // Limit the depth to prevent infinite recursion
900
- ? _Paths<T[Key], {
901
- bracketNotation: Options["bracketNotation"];
902
- maxRecursionDepth: Subtract<MaxDepth, 1>;
903
- }> extends infer SubPath ? SubPath extends string | number ? (Options["bracketNotation"] extends true ? SubPath extends `[${any}]` | `[${any}]${string}` ? `${TranformedKey}${SubPath}` // If next node is number key like `[3]`, no need to add `.` before it.
904
- : `${TranformedKey}.${SubPath}` : never) | (Options["bracketNotation"] extends false ? `${TranformedKey}.${SubPath}` : never) : never : never : never) : never : never;
905
- }[keyof T & (T extends UnknownArray ? number : unknown)] : never : never;
1018
+ export type Paths<T, Options extends PathsOptions = {}> = _Paths<
1019
+ T,
1020
+ {
1021
+ // Set default maxRecursionDepth to 10
1022
+ maxRecursionDepth: Options['maxRecursionDepth'] extends number
1023
+ ? Options['maxRecursionDepth']
1024
+ : DefaultPathsOptions['maxRecursionDepth'];
1025
+ // Set default bracketNotation to false
1026
+ bracketNotation: Options['bracketNotation'] extends boolean
1027
+ ? Options['bracketNotation']
1028
+ : DefaultPathsOptions['bracketNotation'];
1029
+ }
1030
+ >;
1031
+ export type _Paths<T, Options extends Required<PathsOptions>> = T extends
1032
+ | NonRecursiveType
1033
+ | ReadonlyMap<unknown, unknown>
1034
+ | ReadonlySet<unknown>
1035
+ ? never
1036
+ : IsAny<T> extends true
1037
+ ? never
1038
+ : T extends UnknownArray
1039
+ ? number extends T['length']
1040
+ ?
1041
+ | InternalPaths<StaticPartOfArray<T>, Options>
1042
+ | InternalPaths<Array<VariablePartOfArray<T>[number]>, Options>
1043
+ : InternalPaths<T, Options>
1044
+ : T extends object
1045
+ ? InternalPaths<T, Options>
1046
+ : never;
1047
+ export type InternalPaths<
1048
+ T,
1049
+ Options extends Required<PathsOptions>,
1050
+ > = Options['maxRecursionDepth'] extends infer MaxDepth extends number
1051
+ ? Required<T> extends infer T
1052
+ ? T extends EmptyObject | readonly []
1053
+ ? never
1054
+ : {
1055
+ [Key in keyof T]: Key extends string | number // Limit `Key` to string or number.
1056
+ ? (
1057
+ Options['bracketNotation'] extends true
1058
+ ? IsNumberLike<Key> extends true
1059
+ ? `[${Key}]`
1060
+ : Key | ToString<Key>
1061
+ : never | Options['bracketNotation'] extends false
1062
+ ? Key | ToString<Key>
1063
+ : never
1064
+ ) extends infer TranformedKey extends string | number
1065
+ ? // 1. If style is 'a[0].b' and 'Key' is a numberlike value like 3 or '3', transform 'Key' to `[${Key}]`, else to `${Key}` | Key
1066
+ // 2. If style is 'a.0.b', transform 'Key' to `${Key}` | Key
1067
+ | TranformedKey
1068
+ // Recursively generate paths for the current key
1069
+ | (GreaterThan<MaxDepth, 0> extends true // Limit the depth to prevent infinite recursion
1070
+ ? _Paths<
1071
+ T[Key],
1072
+ {
1073
+ bracketNotation: Options['bracketNotation'];
1074
+ maxRecursionDepth: Subtract<MaxDepth, 1>;
1075
+ }
1076
+ > extends infer SubPath
1077
+ ? SubPath extends string | number
1078
+ ?
1079
+ | (Options['bracketNotation'] extends true
1080
+ ? SubPath extends
1081
+ | `[${any}]`
1082
+ | `[${any}]${string}`
1083
+ ? `${TranformedKey}${SubPath}` // If next node is number key like `[3]`, no need to add `.` before it.
1084
+ : `${TranformedKey}.${SubPath}`
1085
+ : never)
1086
+ | (Options['bracketNotation'] extends false
1087
+ ? `${TranformedKey}.${SubPath}`
1088
+ : never)
1089
+ : never
1090
+ : never
1091
+ : never)
1092
+ : never
1093
+ : never;
1094
+ }[keyof T & (T extends UnknownArray ? number : unknown)]
1095
+ : never
1096
+ : never;
906
1097
  export type LiteralStringUnion<T> = LiteralUnion<T, string>;
907
1098
  /**
908
1099
  Allows creating a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
@@ -933,7 +1124,9 @@ const pet: Pet2 = '';
933
1124
 
934
1125
  @category Type
935
1126
  */
936
- export type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
1127
+ export type LiteralUnion<LiteralType, BaseType extends Primitive> =
1128
+ | LiteralType
1129
+ | (BaseType & Record<never, never>);
937
1130
  /**
938
1131
  Get keys of the given type as strings.
939
1132
 
@@ -958,7 +1151,8 @@ type StringKeysOfFoo = StringKeyOf<Foo>;
958
1151
 
959
1152
  @category Object
960
1153
  */
961
- export type StringKeyOf<BaseType> = `${Extract<keyof BaseType, string | number>}`;
1154
+ export type StringKeyOf<BaseType> =
1155
+ `${Extract<keyof BaseType, string | number>}`;
962
1156
  /**
963
1157
  Represents an array of strings split using a given character or character set.
964
1158
 
@@ -980,13 +1174,14 @@ array = split(items, ',');
980
1174
  @category String
981
1175
  @category Template literal
982
1176
  */
983
- export type Split<S extends string, Delimiter extends string> = S extends `${infer Head}${Delimiter}${infer Tail}` ? [
984
- Head,
985
- ...Split<Tail, Delimiter>
986
- ] : S extends Delimiter ? [
987
- ] : [
988
- S
989
- ];
1177
+ export type Split<
1178
+ S extends string,
1179
+ Delimiter extends string,
1180
+ > = S extends `${infer Head}${Delimiter}${infer Tail}`
1181
+ ? [Head, ...Split<Tail, Delimiter>]
1182
+ : S extends Delimiter
1183
+ ? []
1184
+ : [S];
990
1185
  export type GetOptions = {
991
1186
  /**
992
1187
  Include `undefined` in the return type when accessing properties.
@@ -1000,24 +1195,41 @@ export type GetOptions = {
1000
1195
  /**
1001
1196
  Like the `Get` type but receives an array of strings as a path parameter.
1002
1197
  */
1003
- export type GetWithPath<BaseType, Keys, Options extends GetOptions = {}> = Keys extends readonly [
1004
- ] ? BaseType : Keys extends readonly [
1005
- infer Head,
1006
- ...infer Tail
1007
- ] ? GetWithPath<PropertyOf<BaseType, Extract<Head, string>, Options>, Extract<Tail, string[]>, Options> : never;
1198
+ export type GetWithPath<
1199
+ BaseType,
1200
+ Keys,
1201
+ Options extends GetOptions = {},
1202
+ > = Keys extends readonly []
1203
+ ? BaseType
1204
+ : Keys extends readonly [infer Head, ...infer Tail]
1205
+ ? GetWithPath<
1206
+ PropertyOf<BaseType, Extract<Head, string>, Options>,
1207
+ Extract<Tail, string[]>,
1208
+ Options
1209
+ >
1210
+ : never;
1008
1211
  /**
1009
1212
  Adds `undefined` to `Type` if `strict` is enabled.
1010
1213
  */
1011
- export type Strictify<Type, Options extends GetOptions> = Options["strict"] extends false ? Type : (Type | undefined);
1214
+ export type Strictify<
1215
+ Type,
1216
+ Options extends GetOptions,
1217
+ > = Options['strict'] extends false ? Type : Type | undefined;
1012
1218
  /**
1013
1219
  If `Options['strict']` is `true`, includes `undefined` in the returned type when accessing properties on `Record<string, any>`.
1014
1220
 
1015
1221
  Known limitations:
1016
1222
  - Does not include `undefined` in the type on object types with an index signature (for example, `{a: string; [key: string]: string}`).
1017
1223
  */
1018
- export type StrictPropertyOf<BaseType, Key extends keyof BaseType, Options extends GetOptions> = Record<string, any> extends BaseType ? string extends keyof BaseType ? Strictify<BaseType[Key], Options> // Record<string, any>
1019
- : BaseType[Key] // Record<'a' | 'b', any> (Records with a string union as keys have required properties)
1020
- : BaseType[Key];
1224
+ export type StrictPropertyOf<
1225
+ BaseType,
1226
+ Key extends keyof BaseType,
1227
+ Options extends GetOptions,
1228
+ > = Record<string, any> extends BaseType
1229
+ ? string extends keyof BaseType
1230
+ ? Strictify<BaseType[Key], Options> // Record<string, any>
1231
+ : BaseType[Key] // Record<'a' | 'b', any> (Records with a string union as keys have required properties)
1232
+ : BaseType[Key];
1021
1233
  /**
1022
1234
  Splits a dot-prop style path into a tuple comprised of the properties in the path. Handles square-bracket notation.
1023
1235
 
@@ -1030,11 +1242,18 @@ ToPath<'foo[0].bar.baz'>
1030
1242
  //=> ['foo', '0', 'bar', 'baz']
1031
1243
  ```
1032
1244
  */
1033
- export type ToPath<S extends string> = Split<FixPathSquareBrackets<S>, ".">;
1245
+ export type ToPath<S extends string> = Split<FixPathSquareBrackets<S>, '.'>;
1034
1246
  /**
1035
1247
  Replaces square-bracketed dot notation with dots, for example, `foo[0].bar` -> `foo.0.bar`.
1036
1248
  */
1037
- export type FixPathSquareBrackets<Path extends string> = Path extends `[${infer Head}]${infer Tail}` ? Tail extends `[${string}` ? `${Head}.${FixPathSquareBrackets<Tail>}` : `${Head}${FixPathSquareBrackets<Tail>}` : Path extends `${infer Head}[${infer Middle}]${infer Tail}` ? `${Head}.${FixPathSquareBrackets<`[${Middle}]${Tail}`>}` : Path;
1249
+ export type FixPathSquareBrackets<Path extends string> =
1250
+ Path extends `[${infer Head}]${infer Tail}`
1251
+ ? Tail extends `[${string}`
1252
+ ? `${Head}.${FixPathSquareBrackets<Tail>}`
1253
+ : `${Head}${FixPathSquareBrackets<Tail>}`
1254
+ : Path extends `${infer Head}[${infer Middle}]${infer Tail}`
1255
+ ? `${Head}.${FixPathSquareBrackets<`[${Middle}]${Tail}`>}`
1256
+ : Path;
1038
1257
  /**
1039
1258
  Returns true if `LongString` is made up out of `Substring` repeated 0 or more times.
1040
1259
 
@@ -1046,7 +1265,14 @@ ConsistsOnlyOf<'aBa', 'a'> //=> false
1046
1265
  ConsistsOnlyOf<'', 'a'> //=> true
1047
1266
  ```
1048
1267
  */
1049
- export type ConsistsOnlyOf<LongString extends string, Substring extends string> = LongString extends "" ? true : LongString extends `${Substring}${infer Tail}` ? ConsistsOnlyOf<Tail, Substring> : false;
1268
+ export type ConsistsOnlyOf<
1269
+ LongString extends string,
1270
+ Substring extends string,
1271
+ > = LongString extends ''
1272
+ ? true
1273
+ : LongString extends `${Substring}${infer Tail}`
1274
+ ? ConsistsOnlyOf<Tail, Substring>
1275
+ : false;
1050
1276
  /**
1051
1277
  Convert a type which may have number keys to one with string keys, making it possible to index using strings retrieved from template types.
1052
1278
 
@@ -1067,11 +1293,11 @@ export type WithStringKeys<BaseType> = {
1067
1293
  /**
1068
1294
  Perform a `T[U]` operation if `T` supports indexing.
1069
1295
  */
1070
- export type UncheckedIndex<T, U extends string | number> = [
1071
- T
1072
- ] extends [
1073
- Record<string | number, any>
1074
- ] ? T[U] : never;
1296
+ export type UncheckedIndex<T, U extends string | number> = [T] extends [
1297
+ Record<string | number, any>,
1298
+ ]
1299
+ ? T[U]
1300
+ : never;
1075
1301
  /**
1076
1302
  Get a property of an object or array. Works when indexing arrays using number-literal-strings, for example, `PropertyOf<number[], '0'> = number`, and when indexing objects with number keys.
1077
1303
 
@@ -1079,15 +1305,26 @@ Note:
1079
1305
  - Returns `unknown` if `Key` is not a property of `BaseType`, since TypeScript uses structural typing, and it cannot be guaranteed that extra properties unknown to the type system will exist at runtime.
1080
1306
  - Returns `undefined` from nullish values, to match the behaviour of most deep-key libraries like `lodash`, `dot-prop`, etc.
1081
1307
  */
1082
- export type PropertyOf<BaseType, Key extends string, Options extends GetOptions = {}> = BaseType extends null | undefined ? undefined : Key extends keyof BaseType ? StrictPropertyOf<BaseType, Key, Options> : BaseType extends readonly [
1083
- ] | readonly [
1084
- unknown,
1085
- ...unknown[]
1086
- ] ? unknown // It's a tuple, but `Key` did not extend `keyof BaseType`. So the index is out of bounds.
1087
- : BaseType extends {
1088
- [n: number]: infer Item;
1089
- length: number; // Note: This is needed to avoid being too lax with records types using number keys like `{0: string; 1: boolean}`.
1090
- } ? (ConsistsOnlyOf<Key, StringDigit> extends true ? Strictify<Item, Options> : unknown) : Key extends keyof WithStringKeys<BaseType> ? StrictPropertyOf<WithStringKeys<BaseType>, Key, Options> : unknown;
1308
+ export type PropertyOf<
1309
+ BaseType,
1310
+ Key extends string,
1311
+ Options extends GetOptions = {},
1312
+ > = BaseType extends null | undefined
1313
+ ? undefined
1314
+ : Key extends keyof BaseType
1315
+ ? StrictPropertyOf<BaseType, Key, Options>
1316
+ : BaseType extends readonly [] | readonly [unknown, ...unknown[]]
1317
+ ? unknown // It's a tuple, but `Key` did not extend `keyof BaseType`. So the index is out of bounds.
1318
+ : BaseType extends {
1319
+ [n: number]: infer Item;
1320
+ length: number; // Note: This is needed to avoid being too lax with records types using number keys like `{0: string; 1: boolean}`.
1321
+ }
1322
+ ? ConsistsOnlyOf<Key, StringDigit> extends true
1323
+ ? Strictify<Item, Options>
1324
+ : unknown
1325
+ : Key extends keyof WithStringKeys<BaseType>
1326
+ ? StrictPropertyOf<WithStringKeys<BaseType>, Key, Options>
1327
+ : unknown;
1091
1328
  // This works by first splitting the path based on `.` and `[...]` characters into a tuple of string keys. Then it recursively uses the head key to get the next property of the current object, until there are no keys left. Number keys extract the item type from arrays, or are converted to strings to extract types from tuples and dictionaries with number keys.
1092
1329
  /**
1093
1330
  Get a deeply-nested property from an object using a key path, like Lodash's `.get()` function.
@@ -1135,22 +1372,39 @@ Get<Record<string, string>, 'foo', {strict: true}> // => string
1135
1372
  @category Array
1136
1373
  @category Template literal
1137
1374
  */
1138
- export type Get<BaseType, Path extends readonly string[] | LiteralStringUnion<ToString<Paths<BaseType, {
1139
- bracketNotation: false;
1140
- }> | Paths<BaseType, {
1141
- bracketNotation: true;
1142
- }>>>, Options extends GetOptions = {}> = GetWithPath<BaseType, Path extends string ? ToPath<Path> : Path, Options>;
1375
+ export type Get<
1376
+ BaseType,
1377
+ Path extends
1378
+ | readonly string[]
1379
+ | LiteralStringUnion<
1380
+ ToString<
1381
+ | Paths<
1382
+ BaseType,
1383
+ {
1384
+ bracketNotation: false;
1385
+ }
1386
+ >
1387
+ | Paths<
1388
+ BaseType,
1389
+ {
1390
+ bracketNotation: true;
1391
+ }
1392
+ >
1393
+ >
1394
+ >,
1395
+ Options extends GetOptions = {},
1396
+ > = GetWithPath<BaseType, Path extends string ? ToPath<Path> : Path, Options>;
1143
1397
  export type ArrayOrPlainObject = UnknownArray | UnknownRecord;
1144
1398
  export type PlainObject = UnknownRecord;
1145
1399
  /**
1146
1400
  * Clone any kind of value _(deeply, if needed)_
1147
1401
  */
1148
- export declare function clone(value: unknown): {} | null | undefined;
1402
+ export declare function clone<Value>(value: Value): Value;
1149
1403
  /**
1150
1404
  * Compare two values _(for sorting purposes)_
1151
1405
  */
1152
1406
  export declare function compare(first: unknown, second: unknown): number;
1153
- export type DiffType = "full" | "none" | "partial";
1407
+ export type DiffType = 'full' | 'none' | 'partial';
1154
1408
  export type DiffResult<First, Second = First> = {
1155
1409
  original: DiffValue<First, Second>;
1156
1410
  type: DiffType;
@@ -1170,11 +1424,18 @@ export type DiffValue<First = unknown, Second = First> = {
1170
1424
  * - `partial` if the values are partially different
1171
1425
  * - `values` holds the differences with dot notation keys
1172
1426
  */
1173
- export declare function diff<First, Second = First>(first: First, second: Second): DiffResult<First, Second>;
1427
+ export declare function diff<First, Second = First>(
1428
+ first: First,
1429
+ second: Second,
1430
+ ): DiffResult<First, Second>;
1174
1431
  /**
1175
1432
  * Are two strings equal? _(Case-sensitive by default)_
1176
1433
  */
1177
- export declare function equal(first: string, second: string, ignoreCase?: boolean): boolean;
1434
+ export declare function equal(
1435
+ first: string,
1436
+ second: string,
1437
+ ignoreCase?: boolean,
1438
+ ): boolean;
1178
1439
  /**
1179
1440
  * Are two values equal? _(Does a deep comparison, if needed)_
1180
1441
  */
@@ -1184,14 +1445,21 @@ export declare function equal(first: unknown, second: unknown): boolean;
1184
1445
  * - You can retrieve a nested value by using dot notation, e.g., `foo.bar.baz`
1185
1446
  * - Returns `undefined` if the value is not found
1186
1447
  */
1187
- export declare function getValue<Data extends PlainObject, Path extends Paths<Data>>(data: Data, path: Path): Get<Data, ToString<Path>>;
1448
+ export declare function getValue<
1449
+ Data extends ArrayOrPlainObject,
1450
+ Path extends Paths<Data>,
1451
+ >(data: Data, path: Path): Get<Data, ToString<Path>>;
1188
1452
  /**
1189
1453
  * - Get the value from an object using an unknown path
1190
1454
  * - You can retrieve a nested value by using dot notation, e.g., `foo.bar.baz`
1191
1455
  * - If `ignoreCase` is `true`, path matching will be case-insensitive
1192
1456
  * - Returns `undefined` if the value is not found
1193
1457
  */
1194
- export declare function getValue<Data extends PlainObject>(data: Data, path: string, ignoreCase?: boolean): unknown;
1458
+ export declare function getValue<Data extends ArrayOrPlainObject>(
1459
+ data: Data,
1460
+ path: string,
1461
+ ignoreCase?: boolean,
1462
+ ): unknown;
1195
1463
  export type MergeOptions = {
1196
1464
  /**
1197
1465
  * - Skip nullable values when merging arrays?
@@ -1202,14 +1470,20 @@ export type MergeOptions = {
1202
1470
  /**
1203
1471
  * Merge multiple arrays or objects into a single one
1204
1472
  */
1205
- export declare function merge<Model extends ArrayOrPlainObject>(values: Model[], options?: Partial<MergeOptions>): Model;
1473
+ export declare function merge<Model extends ArrayOrPlainObject>(
1474
+ values: Model[],
1475
+ options?: Partial<MergeOptions>,
1476
+ ): Model;
1206
1477
  /**
1207
1478
  * - Set the value in an object using a known path
1208
1479
  * - You can set a nested value by using dot notation, e.g., `foo.bar.baz`
1209
1480
  * - If a part of the path does not exist, it will be created, either as an array or a generic object, depending on the path
1210
1481
  * - Returns the original object
1211
1482
  */
1212
- export declare function setValue<Data extends PlainObject, Path extends Paths<Data>>(data: Data, path: Path, value: unknown): Data;
1483
+ export declare function setValue<
1484
+ Data extends ArrayOrPlainObject,
1485
+ Path extends Paths<Data>,
1486
+ >(data: Data, path: Path, value: unknown): Data;
1213
1487
  /**
1214
1488
  * - Set the value in an object using an unknown path
1215
1489
  * - You can set a nested value by using dot notation, e.g., `foo.bar.baz`
@@ -1217,24 +1491,41 @@ export declare function setValue<Data extends PlainObject, Path extends Paths<Da
1217
1491
  * - If `ignoreCase` is `true`, path matching will be case-insensitive
1218
1492
  * - Returns the original object
1219
1493
  */
1220
- export declare function setValue<Data extends PlainObject>(data: Data, path: string, value: unknown, ignoreCase?: boolean): Data;
1494
+ export declare function setValue<Data extends ArrayOrPlainObject>(
1495
+ data: Data,
1496
+ path: string,
1497
+ value: unknown,
1498
+ ignoreCase?: boolean,
1499
+ ): Data;
1221
1500
  export type Smushed<Value> = Simplify<{
1222
1501
  [Key in Paths<Value>]: Get<Value, ToString<Key>>;
1223
1502
  }>;
1224
1503
  /**
1225
1504
  * Smush an object into a flat object that uses dot notation keys
1226
1505
  */
1227
- export declare function smush<Value extends PlainObject>(value: Value): Smushed<Value>;
1228
- export type Unsmushed<Value extends PlainObject> = Simplify<Omit<{
1229
- [Key in KeysOfUnion<Value>]: Value[Key];
1230
- }, `${string}.${string}`>>;
1506
+ export declare function smush<Value extends PlainObject>(
1507
+ value: Value,
1508
+ ): Smushed<Value>;
1509
+ export type Unsmushed<Value extends PlainObject> = Simplify<
1510
+ Omit<
1511
+ {
1512
+ [Key in KeysOfUnion<Value>]: Value[Key];
1513
+ },
1514
+ `${string}.${string}`
1515
+ >
1516
+ >;
1231
1517
  /**
1232
1518
  * Unsmush a smushed object _(turning dot notation keys into nested keys)_
1233
1519
  */
1234
- export declare function unsmush<Value extends PlainObject>(value: Value): Unsmushed<Value>;
1520
+ export declare function unsmush<Value extends PlainObject>(
1521
+ value: Value,
1522
+ ): Unsmushed<Value>;
1235
1523
  /**
1236
1524
  * Create a new object with only the specified keys
1237
1525
  */
1238
- export declare function partial<Value extends PlainObject, Key extends keyof Value>(value: Value, keys: Key[]): Pick<Value, Key>;
1526
+ export declare function partial<
1527
+ Value extends PlainObject,
1528
+ Key extends keyof Value,
1529
+ >(value: Value, keys: Key[]): Pick<Value, Key>;
1239
1530
 
1240
1531
  export {};