@oscarpalmer/atoms 0.76.0 → 0.77.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/js/array/count.cjs +1 -8
  2. package/dist/js/array/count.js +1 -8
  3. package/dist/js/array/exists.cjs +1 -8
  4. package/dist/js/array/exists.js +1 -8
  5. package/dist/js/array/filter.cjs +1 -8
  6. package/dist/js/array/filter.js +1 -8
  7. package/dist/js/array/find.cjs +1 -8
  8. package/dist/js/array/find.js +1 -8
  9. package/dist/js/array/index-of.cjs +1 -8
  10. package/dist/js/array/index-of.js +1 -8
  11. package/dist/js/array/unique.cjs +1 -1
  12. package/dist/js/array/unique.js +1 -1
  13. package/dist/js/internal/array/find.cjs +12 -2
  14. package/dist/js/internal/array/find.js +12 -2
  15. package/package.json +11 -4
  16. package/src/js/array/count.ts +7 -20
  17. package/src/js/array/exists.ts +7 -22
  18. package/src/js/array/filter.ts +7 -20
  19. package/src/js/array/find.ts +7 -20
  20. package/src/js/array/group-by.ts +19 -21
  21. package/src/js/array/index-of.ts +7 -20
  22. package/src/js/array/models.ts +2 -16
  23. package/src/js/array/sort.ts +3 -7
  24. package/src/js/array/to-map.ts +19 -21
  25. package/src/js/array/to-record.ts +17 -19
  26. package/src/js/array/unique.ts +8 -8
  27. package/src/js/internal/array/callbacks.ts +4 -4
  28. package/src/js/internal/array/find.ts +29 -6
  29. package/types/array/count.d.cts +2 -5
  30. package/types/array/count.d.ts +3 -3
  31. package/types/array/exists.d.cts +2 -5
  32. package/types/array/exists.d.ts +3 -3
  33. package/types/array/filter.d.cts +2 -5
  34. package/types/array/filter.d.ts +3 -3
  35. package/types/array/find.d.cts +2 -5
  36. package/types/array/find.d.ts +3 -3
  37. package/types/array/group-by.d.cts +8 -11
  38. package/types/array/group-by.d.ts +10 -11
  39. package/types/array/index-of.d.cts +2 -5
  40. package/types/array/index-of.d.ts +3 -3
  41. package/types/array/index.d.cts +43 -48
  42. package/types/array/models.d.cts +2 -7
  43. package/types/array/models.d.ts +2 -7
  44. package/types/array/sort.d.cts +3 -4
  45. package/types/array/sort.d.ts +3 -3
  46. package/types/array/to-map.d.cts +8 -11
  47. package/types/array/to-map.d.ts +9 -10
  48. package/types/array/to-record.d.cts +8 -11
  49. package/types/array/to-record.d.ts +9 -10
  50. package/types/array/unique.d.cts +3 -5
  51. package/types/array/unique.d.ts +4 -4
  52. package/types/index.d.cts +321 -1019
  53. package/types/internal/array/find.d.cts +2 -2
  54. package/types/internal/array/find.d.ts +2 -2
  55. package/types/models.d.cts +210 -467
  56. package/types/value/get.d.cts +210 -469
  57. package/types/value/index.d.cts +223 -514
  58. package/types/value/set.d.cts +169 -356
  59. package/types/value/smush.d.cts +209 -463
@@ -5,14 +5,7 @@ Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/
5
5
 
6
6
  @category Type
7
7
  */
8
- export type Primitive =
9
- | null
10
- | undefined
11
- | string
12
- | number
13
- | boolean
14
- | symbol
15
- | bigint;
8
+ export type Primitive = null | undefined | string | number | boolean | symbol | bigint;
16
9
  declare const emptyObjectSymbol: unique symbol;
17
10
  /**
18
11
  Represents a strictly empty plain object, the `{}` value.
@@ -69,11 +62,7 @@ type Includes<Value extends readonly any[], Item> =
69
62
  @category Type Guard
70
63
  @category Utilities
71
64
  */
72
- export type IsEqual<A, B> = (<G>() => G extends A ? 1 : 2) extends <
73
- G,
74
- >() => G extends B ? 1 : 2
75
- ? true
76
- : false;
65
+ export type IsEqual<A, B> = (<G>() => G extends A ? 1 : 2) extends (<G>() => G extends B ? 1 : 2) ? true : false;
77
66
  /**
78
67
  Represents an object with `unknown` value. You probably want this instead of `{}`.
79
68
 
@@ -140,16 +129,14 @@ type B = StaticPartOfArray<A>;
140
129
  //=> [string, number, boolean]
141
130
  ```
142
131
  */
143
- export type StaticPartOfArray<
144
- T extends UnknownArray,
145
- Result extends UnknownArray = [],
146
- > = T extends unknown
147
- ? number extends T['length']
148
- ? T extends readonly [infer U, ...infer V]
149
- ? StaticPartOfArray<V, [...Result, U]>
150
- : Result
151
- : T
152
- : never; // Should never happen
132
+ export type StaticPartOfArray<T extends UnknownArray, Result extends UnknownArray = [
133
+ ]> = T extends unknown ? number extends T["length"] ? T extends readonly [
134
+ infer U,
135
+ ...infer V
136
+ ] ? StaticPartOfArray<V, [
137
+ ...Result,
138
+ U
139
+ ]> : Result : T : never; // Should never happen
153
140
  /**
154
141
  Returns the variable, non-fixed-length portion of the given array, excluding static-length parts.
155
142
 
@@ -160,22 +147,12 @@ type B = VariablePartOfArray<A>;
160
147
  //=> string[]
161
148
  ```
162
149
  */
163
- export type VariablePartOfArray<T extends UnknownArray> = T extends unknown
164
- ? T extends readonly [...StaticPartOfArray<T>, ...infer U]
165
- ? U
166
- : []
167
- : never; // Should never happen
168
- export type StringDigit =
169
- | '0'
170
- | '1'
171
- | '2'
172
- | '3'
173
- | '4'
174
- | '5'
175
- | '6'
176
- | '7'
177
- | '8'
178
- | '9';
150
+ export type VariablePartOfArray<T extends UnknownArray> = T extends unknown ? T extends readonly [
151
+ ...StaticPartOfArray<T>,
152
+ ...infer U
153
+ ] ? U : [
154
+ ] : never; // Should never happen
155
+ export type StringDigit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
179
156
  /**
180
157
  Returns a boolean for whether the given type is `any`.
181
158
 
@@ -218,7 +195,7 @@ Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277)
218
195
  */
219
196
  // See https://github.com/microsoft/TypeScript/issues/31752
220
197
  // eslint-disable-next-line @typescript-eslint/no-loss-of-precision
221
- export type PositiveInfinity = 1e999;
198
+ export type PositiveInfinity = Infinity;
222
199
  /**
223
200
  Matches the hidden `-Infinity` type.
224
201
 
@@ -230,7 +207,7 @@ Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277)
230
207
  */
231
208
  // See https://github.com/microsoft/TypeScript/issues/31752
232
209
  // eslint-disable-next-line @typescript-eslint/no-loss-of-precision
233
- export type NegativeInfinity = -1e999;
210
+ export type NegativeInfinity = -Infinity;
234
211
  /**
235
212
  A negative `number`/`bigint` (`-∞ < x < 0`)
236
213
 
@@ -241,11 +218,7 @@ Use-case: Validating and documenting parameters.
241
218
 
242
219
  @category Numeric
243
220
  */
244
- export type Negative<T extends Numeric> = T extends Zero
245
- ? never
246
- : `${T}` extends `-${string}`
247
- ? T
248
- : never;
221
+ export type Negative<T extends Numeric> = T extends Zero ? never : `${T}` extends `-${string}` ? T : never;
249
222
  /**
250
223
  Returns a boolean for whether the given number is a negative number.
251
224
 
@@ -261,9 +234,7 @@ type ShouldBeTrue = IsNegative<-1>;
261
234
 
262
235
  @category Numeric
263
236
  */
264
- export type IsNegative<T extends Numeric> = T extends Negative<T>
265
- ? true
266
- : false;
237
+ export type IsNegative<T extends Numeric> = T extends Negative<T> ? true : false;
267
238
  /**
268
239
  Returns a boolean for whether two given types are both true.
269
240
 
@@ -284,12 +255,11 @@ And<true, false>;
284
255
  */
285
256
  export type And<A extends boolean, B extends boolean> = [
286
257
  A,
287
- B,
288
- ][number] extends true
289
- ? true
290
- : true extends [IsEqual<A, false>, IsEqual<B, false>][number]
291
- ? false
292
- : never;
258
+ B
259
+ ][number] extends true ? true : true extends [
260
+ IsEqual<A, false>,
261
+ IsEqual<B, false>
262
+ ][number] ? false : never;
293
263
  /**
294
264
  Returns a boolean for whether either of two given types are true.
295
265
 
@@ -310,12 +280,11 @@ Or<false, false>;
310
280
  */
311
281
  export type Or<A extends boolean, B extends boolean> = [
312
282
  A,
313
- B,
314
- ][number] extends false
315
- ? false
316
- : true extends [IsEqual<A, true>, IsEqual<B, true>][number]
317
- ? true
318
- : never;
283
+ B
284
+ ][number] extends false ? false : true extends [
285
+ IsEqual<A, true>,
286
+ IsEqual<B, true>
287
+ ][number] ? true : never;
319
288
  /**
320
289
  Returns a boolean for whether a given number is greater than another number.
321
290
 
@@ -333,44 +302,32 @@ GreaterThan<1, 5>;
333
302
  //=> false
334
303
  ```
335
304
  */
336
- export type GreaterThan<A extends number, B extends number> = number extends
337
- | A
338
- | B
339
- ? never
340
- : [
341
- IsEqual<A, PositiveInfinity>,
342
- IsEqual<A, NegativeInfinity>,
343
- IsEqual<B, PositiveInfinity>,
344
- IsEqual<B, NegativeInfinity>,
345
- ] extends infer R extends [boolean, boolean, boolean, boolean]
346
- ? Or<
347
- And<IsEqual<R[0], true>, IsEqual<R[2], false>>,
348
- And<IsEqual<R[3], true>, IsEqual<R[1], false>>
349
- > extends true
350
- ? true
351
- : Or<
352
- And<IsEqual<R[1], true>, IsEqual<R[3], false>>,
353
- And<IsEqual<R[2], true>, IsEqual<R[0], false>>
354
- > extends true
355
- ? false
356
- : true extends R[number]
357
- ? false
358
- : [IsNegative<A>, IsNegative<B>] extends infer R extends [
359
- boolean,
360
- boolean,
361
- ]
362
- ? [true, false] extends R
363
- ? false
364
- : [false, true] extends R
365
- ? true
366
- : [false, false] extends R
367
- ? PositiveNumericStringGt<`${A}`, `${B}`>
368
- : PositiveNumericStringGt<
369
- `${NumberAbsolute<B>}`,
370
- `${NumberAbsolute<A>}`
371
- >
372
- : never
373
- : never;
305
+ export type GreaterThan<A extends number, B extends number> = number extends A | B ? never : [
306
+ IsEqual<A, PositiveInfinity>,
307
+ IsEqual<A, NegativeInfinity>,
308
+ IsEqual<B, PositiveInfinity>,
309
+ IsEqual<B, NegativeInfinity>
310
+ ] extends infer R extends [
311
+ boolean,
312
+ boolean,
313
+ boolean,
314
+ boolean
315
+ ] ? 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 : [
316
+ IsNegative<A>,
317
+ IsNegative<B>
318
+ ] extends infer R extends [
319
+ boolean,
320
+ boolean
321
+ ] ? [
322
+ true,
323
+ false
324
+ ] extends R ? false : [
325
+ false,
326
+ true
327
+ ] extends R ? true : [
328
+ false,
329
+ false
330
+ ] extends R ? PositiveNumericStringGt<`${A}`, `${B}`> : PositiveNumericStringGt<`${NumberAbsolute<B>}`, `${NumberAbsolute<A>}`> : never : never;
374
331
  /**
375
332
  Returns a boolean for whether a given number is greater than or equal to another number.
376
333
 
@@ -388,10 +345,7 @@ GreaterThanOrEqual<1, 5>;
388
345
  //=> false
389
346
  ```
390
347
  */
391
- export type GreaterThanOrEqual<
392
- A extends number,
393
- B extends number,
394
- > = number extends A | B ? never : A extends B ? true : GreaterThan<A, B>;
348
+ export type GreaterThanOrEqual<A extends number, B extends number> = number extends A | B ? never : A extends B ? true : GreaterThan<A, B>;
395
349
  /**
396
350
  Returns a boolean for whether a given number is less than another number.
397
351
 
@@ -409,11 +363,7 @@ LessThan<1, 5>;
409
363
  //=> true
410
364
  ```
411
365
  */
412
- export type LessThan<A extends number, B extends number> = number extends A | B
413
- ? never
414
- : GreaterThanOrEqual<A, B> extends true
415
- ? false
416
- : true;
366
+ export type LessThan<A extends number, B extends number> = number extends A | B ? never : GreaterThanOrEqual<A, B> extends true ? false : true;
417
367
  /**
418
368
  Create a tuple type of the given length `<L>` and fill it with the given type `<Fill>`.
419
369
 
@@ -421,11 +371,11 @@ If `<Fill>` is not provided, it will default to `unknown`.
421
371
 
422
372
  @link https://itnext.io/implementing-arithmetic-within-typescripts-type-system-a1ef140a6f6f
423
373
  */
424
- export type BuildTuple<
425
- L extends number,
426
- Fill = unknown,
427
- T extends readonly unknown[] = [],
428
- > = T['length'] extends L ? T : BuildTuple<L, Fill, [...T, Fill]>;
374
+ export type BuildTuple<L extends number, Fill = unknown, T extends readonly unknown[] = [
375
+ ]> = T["length"] extends L ? T : BuildTuple<L, Fill, [
376
+ ...T,
377
+ Fill
378
+ ]>;
429
379
  /**
430
380
  Returns the maximum value from a tuple of integers.
431
381
 
@@ -441,16 +391,10 @@ ArrayMax<[1, 2, 5, 3, 99, -1]>;
441
391
  //=> 99
442
392
  ```
443
393
  */
444
- export type TupleMax<
445
- A extends number[],
446
- Result extends number = NegativeInfinity,
447
- > = number extends A[number]
448
- ? never
449
- : A extends [infer F extends number, ...infer R extends number[]]
450
- ? GreaterThan<F, Result> extends true
451
- ? TupleMax<R, F>
452
- : TupleMax<R, Result>
453
- : Result;
394
+ export type TupleMax<A extends number[], Result extends number = NegativeInfinity> = number extends A[number] ? never : A extends [
395
+ infer F extends number,
396
+ ...infer R extends number[]
397
+ ] ? GreaterThan<F, Result> extends true ? TupleMax<R, F> : TupleMax<R, Result> : Result;
454
398
  /**
455
399
  Returns the minimum value from a tuple of integers.
456
400
 
@@ -466,16 +410,10 @@ ArrayMin<[1, 2, 5, 3, -5]>;
466
410
  //=> -5
467
411
  ```
468
412
  */
469
- export type TupleMin<
470
- A extends number[],
471
- Result extends number = PositiveInfinity,
472
- > = number extends A[number]
473
- ? never
474
- : A extends [infer F extends number, ...infer R extends number[]]
475
- ? LessThan<F, Result> extends true
476
- ? TupleMin<R, F>
477
- : TupleMin<R, Result>
478
- : Result;
413
+ export type TupleMin<A extends number[], Result extends number = PositiveInfinity> = number extends A[number] ? never : A extends [
414
+ infer F extends number,
415
+ ...infer R extends number[]
416
+ ] ? LessThan<F, Result> extends true ? TupleMin<R, F> : TupleMin<R, Result> : Result;
479
417
  /**
480
418
  Return a string representation of the given string or number.
481
419
 
@@ -510,14 +448,7 @@ type NegativeInfinity = StringToNumber<'-Infinity'>;
510
448
  @category Numeric
511
449
  @category Template literal
512
450
  */
513
- export type StringToNumber<S extends string> =
514
- S extends `${infer N extends number}`
515
- ? N
516
- : S extends 'Infinity'
517
- ? PositiveInfinity
518
- : S extends '-Infinity'
519
- ? NegativeInfinity
520
- : never;
451
+ export type StringToNumber<S extends string> = S extends `${infer N extends number}` ? N : S extends "Infinity" ? PositiveInfinity : S extends "-Infinity" ? NegativeInfinity : never;
521
452
  /**
522
453
  Returns an array of the characters of the string.
523
454
 
@@ -532,14 +463,11 @@ StringToArray<string>;
532
463
 
533
464
  @category String
534
465
  */
535
- export type StringToArray<
536
- S extends string,
537
- Result extends string[] = [],
538
- > = string extends S
539
- ? never
540
- : S extends `${infer F}${infer R}`
541
- ? StringToArray<R, [...Result, F]>
542
- : Result;
466
+ export type StringToArray<S extends string, Result extends string[] = [
467
+ ]> = string extends S ? never : S extends `${infer F}${infer R}` ? StringToArray<R, [
468
+ ...Result,
469
+ F
470
+ ]> : Result;
543
471
  /**
544
472
  Returns the length of the given string.
545
473
 
@@ -555,9 +483,7 @@ StringLength<string>;
555
483
  @category String
556
484
  @category Template literal
557
485
  */
558
- export type StringLength<S extends string> = string extends S
559
- ? never
560
- : StringToArray<S>['length'];
486
+ export type StringLength<S extends string> = string extends S ? never : StringToArray<S>["length"];
561
487
  /**
562
488
  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.
563
489
 
@@ -570,17 +496,8 @@ SameLengthPositiveNumericStringGt<'10', '10'>;
570
496
  //=> false
571
497
  ```
572
498
  */
573
- export type SameLengthPositiveNumericStringGt<
574
- A extends string,
575
- B extends string,
576
- > = A extends `${infer FirstA}${infer RestA}`
577
- ? B extends `${infer FirstB}${infer RestB}`
578
- ? FirstA extends FirstB
579
- ? SameLengthPositiveNumericStringGt<RestA, RestB>
580
- : PositiveNumericCharacterGt<FirstA, FirstB>
581
- : never
582
- : false;
583
- export type NumericString = '0123456789';
499
+ 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;
500
+ export type NumericString = "0123456789";
584
501
  /**
585
502
  Returns a boolean for whether `A` is greater than `B`, where `A` and `B` are both positive numeric strings.
586
503
 
@@ -596,21 +513,16 @@ PositiveNumericStringGt<'1', '500'>;
596
513
  //=> false
597
514
  ```
598
515
  */
599
- export type PositiveNumericStringGt<
600
- A extends string,
601
- B extends string,
602
- > = A extends B
603
- ? false
604
- : [
605
- BuildTuple<StringLength<A>, 0>,
606
- BuildTuple<StringLength<B>, 0>,
607
- ] extends infer R extends [readonly unknown[], readonly unknown[]]
608
- ? R[0] extends [...R[1], ...infer Remain extends readonly unknown[]]
609
- ? 0 extends Remain['length']
610
- ? SameLengthPositiveNumericStringGt<A, B>
611
- : true
612
- : false
613
- : never;
516
+ export type PositiveNumericStringGt<A extends string, B extends string> = A extends B ? false : [
517
+ BuildTuple<StringLength<A>, 0>,
518
+ BuildTuple<StringLength<B>, 0>
519
+ ] extends infer R extends [
520
+ readonly unknown[],
521
+ readonly unknown[]
522
+ ] ? R[0] extends [
523
+ ...R[1],
524
+ ...infer Remain extends readonly unknown[]
525
+ ] ? 0 extends Remain["length"] ? SameLengthPositiveNumericStringGt<A, B> : true : false : never;
614
526
  /**
615
527
  Returns a boolean for whether `A` represents a number greater than `B`, where `A` and `B` are both positive numeric characters.
616
528
 
@@ -623,16 +535,7 @@ PositiveNumericCharacterGt<'1', '1'>;
623
535
  //=> false
624
536
  ```
625
537
  */
626
- export type PositiveNumericCharacterGt<
627
- A extends string,
628
- B extends string,
629
- > = NumericString extends `${infer HeadA}${A}${infer TailA}`
630
- ? NumericString extends `${infer HeadB}${B}${infer TailB}`
631
- ? HeadA extends `${HeadB}${infer _}${infer __}`
632
- ? true
633
- : false
634
- : never
635
- : never;
538
+ 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;
636
539
  /**
637
540
  Returns the absolute value of a given value.
638
541
 
@@ -648,10 +551,7 @@ NumberAbsolute<NegativeInfinity>
648
551
  //=> PositiveInfinity
649
552
  ```
650
553
  */
651
- export type NumberAbsolute<N extends number> =
652
- `${N}` extends `-${infer StringPositiveN}`
653
- ? StringToNumber<StringPositiveN>
654
- : N;
554
+ export type NumberAbsolute<N extends number> = `${N}` extends `-${infer StringPositiveN}` ? StringToNumber<StringPositiveN> : N;
655
555
  /**
656
556
  Check whether the given type is a number or a number string.
657
557
 
@@ -671,13 +571,7 @@ type C = IsNumberLike<1>;
671
571
  type D = IsNumberLike<'a'>;
672
572
  //=> false
673
573
  */
674
- export type IsNumberLike<N> = N extends number
675
- ? true
676
- : N extends `${number}`
677
- ? true
678
- : N extends `${number}.${number}`
679
- ? true
680
- : false;
574
+ export type IsNumberLike<N> = N extends number ? true : N extends `${number}` ? true : N extends `${number}.${number}` ? true : false;
681
575
  /**
682
576
  Matches any primitive, `void`, `Date`, or `RegExp` value.
683
577
  */
@@ -685,12 +579,7 @@ export type BuiltIns = Primitive | void | Date | RegExp;
685
579
  /**
686
580
  Matches non-recursive types.
687
581
  */
688
- export type NonRecursiveType =
689
- | BuiltIns
690
- | Function
691
- | (new (
692
- ...arguments_: any[]
693
- ) => unknown);
582
+ export type NonRecursiveType = BuiltIns | Function | (new (...arguments_: any[]) => unknown);
694
583
  /**
695
584
  Returns the sum of two numbers.
696
585
 
@@ -722,45 +611,35 @@ Sum<PositiveInfinity, NegativeInfinity>;
722
611
  @category Numeric
723
612
  */
724
613
  // TODO: Support big integer and negative number.
725
- export type Sum<A extends number, B extends number> = number extends A | B
726
- ? number
727
- : [
728
- IsEqual<A, PositiveInfinity>,
729
- IsEqual<A, NegativeInfinity>,
730
- IsEqual<B, PositiveInfinity>,
731
- IsEqual<B, NegativeInfinity>,
732
- ] extends infer R extends [boolean, boolean, boolean, boolean]
733
- ? Or<
734
- And<IsEqual<R[0], true>, IsEqual<R[3], false>>,
735
- And<IsEqual<R[2], true>, IsEqual<R[1], false>>
736
- > extends true
737
- ? PositiveInfinity
738
- : Or<
739
- And<IsEqual<R[1], true>, IsEqual<R[2], false>>,
740
- And<IsEqual<R[3], true>, IsEqual<R[0], false>>
741
- > extends true
742
- ? NegativeInfinity
743
- : true extends R[number]
744
- ? number
745
- : ([IsNegative<A>, IsNegative<B>] extends infer R
746
- ? [false, false] extends R
747
- ? [...BuildTuple<A>, ...BuildTuple<B>]['length']
748
- : [true, true] extends R
749
- ? number
750
- : TupleMax<
751
- [NumberAbsolute<A>, NumberAbsolute<B>]
752
- > extends infer Max_
753
- ? TupleMin<
754
- [NumberAbsolute<A>, NumberAbsolute<B>]
755
- > extends infer Min_ extends number
756
- ? Max_ extends A | B
757
- ? Subtract<Max_, Min_>
758
- : number
759
- : never
760
- : never
761
- : never) &
762
- number
763
- : never;
614
+ export type Sum<A extends number, B extends number> = number extends A | B ? number : [
615
+ IsEqual<A, PositiveInfinity>,
616
+ IsEqual<A, NegativeInfinity>,
617
+ IsEqual<B, PositiveInfinity>,
618
+ IsEqual<B, NegativeInfinity>
619
+ ] extends infer R extends [
620
+ boolean,
621
+ boolean,
622
+ boolean,
623
+ boolean
624
+ ] ? 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 : ([
625
+ IsNegative<A>,
626
+ IsNegative<B>
627
+ ] extends infer R ? [
628
+ false,
629
+ false
630
+ ] extends R ? [
631
+ ...BuildTuple<A>,
632
+ ...BuildTuple<B>
633
+ ]["length"] : [
634
+ true,
635
+ true
636
+ ] extends R ? number : TupleMax<[
637
+ NumberAbsolute<A>,
638
+ NumberAbsolute<B>
639
+ ]> extends infer Max_ ? TupleMin<[
640
+ NumberAbsolute<A>,
641
+ NumberAbsolute<B>
642
+ ]> extends infer Min_ extends number ? Max_ extends A | B ? Subtract<Max_, Min_> : number : never : never : never) & number : never;
764
643
  /**
765
644
  Returns the difference between two numbers.
766
645
 
@@ -791,40 +670,29 @@ Subtract<PositiveInfinity, PositiveInfinity>;
791
670
  @category Numeric
792
671
  */
793
672
  // TODO: Support big integer and negative number.
794
- export type Subtract<A extends number, B extends number> = number extends A | B
795
- ? number
796
- : [
797
- IsEqual<A, PositiveInfinity>,
798
- IsEqual<A, NegativeInfinity>,
799
- IsEqual<B, PositiveInfinity>,
800
- IsEqual<B, NegativeInfinity>,
801
- ] extends infer R extends [boolean, boolean, boolean, boolean]
802
- ? Or<
803
- And<IsEqual<R[0], true>, IsEqual<R[2], false>>,
804
- And<IsEqual<R[3], true>, IsEqual<R[1], false>>
805
- > extends true
806
- ? PositiveInfinity
807
- : Or<
808
- And<IsEqual<R[1], true>, IsEqual<R[3], false>>,
809
- And<IsEqual<R[2], true>, IsEqual<R[0], false>>
810
- > extends true
811
- ? NegativeInfinity
812
- : true extends R[number]
813
- ? number
814
- : [IsNegative<A>, IsNegative<B>] extends infer R
815
- ? [false, false] extends R
816
- ? BuildTuple<A> extends infer R
817
- ? R extends [...BuildTuple<B>, ...infer R]
818
- ? R['length']
819
- : number
820
- : never
821
- : LessThan<A, B> extends true
822
- ? number
823
- : [false, true] extends R
824
- ? Sum<A, NumberAbsolute<B>>
825
- : Subtract<NumberAbsolute<B>, NumberAbsolute<A>>
826
- : never
827
- : never;
673
+ export type Subtract<A extends number, B extends number> = number extends A | B ? number : [
674
+ IsEqual<A, PositiveInfinity>,
675
+ IsEqual<A, NegativeInfinity>,
676
+ IsEqual<B, PositiveInfinity>,
677
+ IsEqual<B, NegativeInfinity>
678
+ ] extends infer R extends [
679
+ boolean,
680
+ boolean,
681
+ boolean,
682
+ boolean
683
+ ] ? 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 : [
684
+ IsNegative<A>,
685
+ IsNegative<B>
686
+ ] extends infer R ? [
687
+ false,
688
+ false
689
+ ] extends R ? BuildTuple<A> extends infer R ? R extends [
690
+ ...BuildTuple<B>,
691
+ ...infer R
692
+ ] ? R["length"] : number : never : LessThan<A, B> extends true ? number : [
693
+ false,
694
+ true
695
+ ] extends R ? Sum<A, NumberAbsolute<B>> : Subtract<NumberAbsolute<B>, NumberAbsolute<A>> : never : never;
828
696
  /**
829
697
  Paths options.
830
698
 
@@ -915,85 +783,28 @@ open('listB.1'); // TypeError. Because listB only has one element.
915
783
  @category Object
916
784
  @category Array
917
785
  */
918
- export type Paths<T, Options extends PathsOptions = {}> = _Paths<
919
- T,
920
- {
921
- // Set default maxRecursionDepth to 10
922
- maxRecursionDepth: Options['maxRecursionDepth'] extends number
923
- ? Options['maxRecursionDepth']
924
- : DefaultPathsOptions['maxRecursionDepth'];
925
- // Set default bracketNotation to false
926
- bracketNotation: Options['bracketNotation'] extends boolean
927
- ? Options['bracketNotation']
928
- : DefaultPathsOptions['bracketNotation'];
929
- }
930
- >;
931
- export type _Paths<T, Options extends Required<PathsOptions>> = T extends
932
- | NonRecursiveType
933
- | ReadonlyMap<unknown, unknown>
934
- | ReadonlySet<unknown>
935
- ? never
936
- : IsAny<T> extends true
937
- ? never
938
- : T extends UnknownArray
939
- ? number extends T['length']
940
- ?
941
- | InternalPaths<StaticPartOfArray<T>, Options>
942
- | InternalPaths<Array<VariablePartOfArray<T>[number]>, Options>
943
- : InternalPaths<T, Options>
944
- : T extends object
945
- ? InternalPaths<T, Options>
946
- : never;
947
- export type InternalPaths<
948
- T,
949
- Options extends Required<PathsOptions>,
950
- > = Options['maxRecursionDepth'] extends infer MaxDepth extends number
951
- ? Required<T> extends infer T
952
- ? T extends EmptyObject | readonly []
953
- ? never
954
- : {
955
- [Key in keyof T]: Key extends string | number // Limit `Key` to string or number.
956
- ? (
957
- Options['bracketNotation'] extends true
958
- ? IsNumberLike<Key> extends true
959
- ? `[${Key}]`
960
- : Key | ToString<Key>
961
- : never | Options['bracketNotation'] extends false
962
- ? Key | ToString<Key>
963
- : never
964
- ) extends infer TranformedKey extends string | number
965
- ? // 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
966
- // 2. If style is 'a.0.b', transform 'Key' to `${Key}` | Key
967
- | TranformedKey
968
- // Recursively generate paths for the current key
969
- | (GreaterThan<MaxDepth, 0> extends true // Limit the depth to prevent infinite recursion
970
- ? _Paths<
971
- T[Key],
972
- {
973
- bracketNotation: Options['bracketNotation'];
974
- maxRecursionDepth: Subtract<MaxDepth, 1>;
975
- }
976
- > extends infer SubPath
977
- ? SubPath extends string | number
978
- ?
979
- | (Options['bracketNotation'] extends true
980
- ? SubPath extends
981
- | `[${any}]`
982
- | `[${any}]${string}`
983
- ? `${TranformedKey}${SubPath}` // If next node is number key like `[3]`, no need to add `.` before it.
984
- : `${TranformedKey}.${SubPath}`
985
- : never)
986
- | (Options['bracketNotation'] extends false
987
- ? `${TranformedKey}.${SubPath}`
988
- : never)
989
- : never
990
- : never
991
- : never)
992
- : never
993
- : never;
994
- }[keyof T & (T extends UnknownArray ? number : unknown)]
995
- : never
996
- : never;
786
+ export type Paths<T, Options extends PathsOptions = {}> = _Paths<T, {
787
+ // Set default maxRecursionDepth to 10
788
+ maxRecursionDepth: Options["maxRecursionDepth"] extends number ? Options["maxRecursionDepth"] : DefaultPathsOptions["maxRecursionDepth"];
789
+ // Set default bracketNotation to false
790
+ bracketNotation: Options["bracketNotation"] extends boolean ? Options["bracketNotation"] : DefaultPathsOptions["bracketNotation"];
791
+ }>;
792
+ 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;
793
+ export type InternalPaths<T, Options extends Required<PathsOptions>> = Options["maxRecursionDepth"] extends infer MaxDepth extends number ? Required<T> extends infer T ? T extends EmptyObject | readonly [
794
+ ] ? never : {
795
+ [Key in keyof T]: Key extends string | number // Limit `Key` to string or number.
796
+ ? (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 ?
797
+ // 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
798
+ // 2. If style is 'a.0.b', transform 'Key' to `${Key}` | Key
799
+ TranformedKey | (
800
+ // Recursively generate paths for the current key
801
+ GreaterThan<MaxDepth, 0> extends true // Limit the depth to prevent infinite recursion
802
+ ? _Paths<T[Key], {
803
+ bracketNotation: Options["bracketNotation"];
804
+ maxRecursionDepth: Subtract<MaxDepth, 1>;
805
+ }> 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.
806
+ : `${TranformedKey}.${SubPath}` : never) | (Options["bracketNotation"] extends false ? `${TranformedKey}.${SubPath}` : never) : never : never : never) : never : never;
807
+ }[keyof T & (T extends UnknownArray ? number : unknown)] : never : never;
997
808
  export type LiteralStringUnion<T> = LiteralUnion<T, string>;
998
809
  /**
999
810
  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.
@@ -1024,9 +835,7 @@ const pet: Pet2 = '';
1024
835
 
1025
836
  @category Type
1026
837
  */
1027
- export type LiteralUnion<LiteralType, BaseType extends Primitive> =
1028
- | LiteralType
1029
- | (BaseType & Record<never, never>);
838
+ export type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
1030
839
  /**
1031
840
  Get keys of the given type as strings.
1032
841
 
@@ -1051,8 +860,7 @@ type StringKeysOfFoo = StringKeyOf<Foo>;
1051
860
 
1052
861
  @category Object
1053
862
  */
1054
- export type StringKeyOf<BaseType> =
1055
- `${Extract<keyof BaseType, string | number>}`;
863
+ export type StringKeyOf<BaseType> = `${Extract<keyof BaseType, string | number>}`;
1056
864
  /**
1057
865
  Represents an array of strings split using a given character or character set.
1058
866
 
@@ -1074,14 +882,13 @@ array = split(items, ',');
1074
882
  @category String
1075
883
  @category Template literal
1076
884
  */
1077
- export type Split<
1078
- S extends string,
1079
- Delimiter extends string,
1080
- > = S extends `${infer Head}${Delimiter}${infer Tail}`
1081
- ? [Head, ...Split<Tail, Delimiter>]
1082
- : S extends Delimiter
1083
- ? []
1084
- : [S];
885
+ export type Split<S extends string, Delimiter extends string> = S extends `${infer Head}${Delimiter}${infer Tail}` ? [
886
+ Head,
887
+ ...Split<Tail, Delimiter>
888
+ ] : S extends Delimiter ? [
889
+ ] : [
890
+ S
891
+ ];
1085
892
  export type GetOptions = {
1086
893
  /**
1087
894
  Include `undefined` in the return type when accessing properties.
@@ -1095,41 +902,24 @@ export type GetOptions = {
1095
902
  /**
1096
903
  Like the `Get` type but receives an array of strings as a path parameter.
1097
904
  */
1098
- export type GetWithPath<
1099
- BaseType,
1100
- Keys,
1101
- Options extends GetOptions = {},
1102
- > = Keys extends readonly []
1103
- ? BaseType
1104
- : Keys extends readonly [infer Head, ...infer Tail]
1105
- ? GetWithPath<
1106
- PropertyOf<BaseType, Extract<Head, string>, Options>,
1107
- Extract<Tail, string[]>,
1108
- Options
1109
- >
1110
- : never;
905
+ export type GetWithPath<BaseType, Keys, Options extends GetOptions = {}> = Keys extends readonly [
906
+ ] ? BaseType : Keys extends readonly [
907
+ infer Head,
908
+ ...infer Tail
909
+ ] ? GetWithPath<PropertyOf<BaseType, Extract<Head, string>, Options>, Extract<Tail, string[]>, Options> : never;
1111
910
  /**
1112
911
  Adds `undefined` to `Type` if `strict` is enabled.
1113
912
  */
1114
- export type Strictify<
1115
- Type,
1116
- Options extends GetOptions,
1117
- > = Options['strict'] extends false ? Type : Type | undefined;
913
+ export type Strictify<Type, Options extends GetOptions> = Options["strict"] extends false ? Type : (Type | undefined);
1118
914
  /**
1119
915
  If `Options['strict']` is `true`, includes `undefined` in the returned type when accessing properties on `Record<string, any>`.
1120
916
 
1121
917
  Known limitations:
1122
918
  - Does not include `undefined` in the type on object types with an index signature (for example, `{a: string; [key: string]: string}`).
1123
919
  */
1124
- export type StrictPropertyOf<
1125
- BaseType,
1126
- Key extends keyof BaseType,
1127
- Options extends GetOptions,
1128
- > = Record<string, any> extends BaseType
1129
- ? string extends keyof BaseType
1130
- ? Strictify<BaseType[Key], Options> // Record<string, any>
1131
- : BaseType[Key] // Record<'a' | 'b', any> (Records with a string union as keys have required properties)
1132
- : BaseType[Key];
920
+ 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>
921
+ : BaseType[Key] // Record<'a' | 'b', any> (Records with a string union as keys have required properties)
922
+ : BaseType[Key];
1133
923
  /**
1134
924
  Splits a dot-prop style path into a tuple comprised of the properties in the path. Handles square-bracket notation.
1135
925
 
@@ -1142,18 +932,11 @@ ToPath<'foo[0].bar.baz'>
1142
932
  //=> ['foo', '0', 'bar', 'baz']
1143
933
  ```
1144
934
  */
1145
- export type ToPath<S extends string> = Split<FixPathSquareBrackets<S>, '.'>;
935
+ export type ToPath<S extends string> = Split<FixPathSquareBrackets<S>, ".">;
1146
936
  /**
1147
937
  Replaces square-bracketed dot notation with dots, for example, `foo[0].bar` -> `foo.0.bar`.
1148
938
  */
1149
- export type FixPathSquareBrackets<Path extends string> =
1150
- Path extends `[${infer Head}]${infer Tail}`
1151
- ? Tail extends `[${string}`
1152
- ? `${Head}.${FixPathSquareBrackets<Tail>}`
1153
- : `${Head}${FixPathSquareBrackets<Tail>}`
1154
- : Path extends `${infer Head}[${infer Middle}]${infer Tail}`
1155
- ? `${Head}.${FixPathSquareBrackets<`[${Middle}]${Tail}`>}`
1156
- : Path;
939
+ 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;
1157
940
  /**
1158
941
  Returns true if `LongString` is made up out of `Substring` repeated 0 or more times.
1159
942
 
@@ -1165,14 +948,7 @@ ConsistsOnlyOf<'aBa', 'a'> //=> false
1165
948
  ConsistsOnlyOf<'', 'a'> //=> true
1166
949
  ```
1167
950
  */
1168
- export type ConsistsOnlyOf<
1169
- LongString extends string,
1170
- Substring extends string,
1171
- > = LongString extends ''
1172
- ? true
1173
- : LongString extends `${Substring}${infer Tail}`
1174
- ? ConsistsOnlyOf<Tail, Substring>
1175
- : false;
951
+ export type ConsistsOnlyOf<LongString extends string, Substring extends string> = LongString extends "" ? true : LongString extends `${Substring}${infer Tail}` ? ConsistsOnlyOf<Tail, Substring> : false;
1176
952
  /**
1177
953
  Convert a type which may have number keys to one with string keys, making it possible to index using strings retrieved from template types.
1178
954
 
@@ -1193,11 +969,11 @@ export type WithStringKeys<BaseType> = {
1193
969
  /**
1194
970
  Perform a `T[U]` operation if `T` supports indexing.
1195
971
  */
1196
- export type UncheckedIndex<T, U extends string | number> = [T] extends [
1197
- Record<string | number, any>,
1198
- ]
1199
- ? T[U]
1200
- : never;
972
+ export type UncheckedIndex<T, U extends string | number> = [
973
+ T
974
+ ] extends [
975
+ Record<string | number, any>
976
+ ] ? T[U] : never;
1201
977
  /**
1202
978
  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.
1203
979
 
@@ -1205,26 +981,15 @@ Note:
1205
981
  - 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.
1206
982
  - Returns `undefined` from nullish values, to match the behaviour of most deep-key libraries like `lodash`, `dot-prop`, etc.
1207
983
  */
1208
- export type PropertyOf<
1209
- BaseType,
1210
- Key extends string,
1211
- Options extends GetOptions = {},
1212
- > = BaseType extends null | undefined
1213
- ? undefined
1214
- : Key extends keyof BaseType
1215
- ? StrictPropertyOf<BaseType, Key, Options>
1216
- : BaseType extends readonly [] | readonly [unknown, ...unknown[]]
1217
- ? unknown // It's a tuple, but `Key` did not extend `keyof BaseType`. So the index is out of bounds.
1218
- : BaseType extends {
1219
- [n: number]: infer Item;
1220
- length: number; // Note: This is needed to avoid being too lax with records types using number keys like `{0: string; 1: boolean}`.
1221
- }
1222
- ? ConsistsOnlyOf<Key, StringDigit> extends true
1223
- ? Strictify<Item, Options>
1224
- : unknown
1225
- : Key extends keyof WithStringKeys<BaseType>
1226
- ? StrictPropertyOf<WithStringKeys<BaseType>, Key, Options>
1227
- : unknown;
984
+ 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 [
985
+ ] | readonly [
986
+ unknown,
987
+ ...unknown[]
988
+ ] ? unknown // It's a tuple, but `Key` did not extend `keyof BaseType`. So the index is out of bounds.
989
+ : BaseType extends {
990
+ [n: number]: infer Item;
991
+ length: number; // Note: This is needed to avoid being too lax with records types using number keys like `{0: string; 1: boolean}`.
992
+ } ? (ConsistsOnlyOf<Key, StringDigit> extends true ? Strictify<Item, Options> : unknown) : Key extends keyof WithStringKeys<BaseType> ? StrictPropertyOf<WithStringKeys<BaseType>, Key, Options> : unknown;
1228
993
  // 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.
1229
994
  /**
1230
995
  Get a deeply-nested property from an object using a key path, like Lodash's `.get()` function.
@@ -1272,48 +1037,24 @@ Get<Record<string, string>, 'foo', {strict: true}> // => string
1272
1037
  @category Array
1273
1038
  @category Template literal
1274
1039
  */
1275
- export type Get<
1276
- BaseType,
1277
- Path extends
1278
- | readonly string[]
1279
- | LiteralStringUnion<
1280
- ToString<
1281
- | Paths<
1282
- BaseType,
1283
- {
1284
- bracketNotation: false;
1285
- }
1286
- >
1287
- | Paths<
1288
- BaseType,
1289
- {
1290
- bracketNotation: true;
1291
- }
1292
- >
1293
- >
1294
- >,
1295
- Options extends GetOptions = {},
1296
- > = GetWithPath<BaseType, Path extends string ? ToPath<Path> : Path, Options>;
1040
+ export type Get<BaseType, Path extends readonly string[] | LiteralStringUnion<ToString<Paths<BaseType, {
1041
+ bracketNotation: false;
1042
+ }> | Paths<BaseType, {
1043
+ bracketNotation: true;
1044
+ }>>>, Options extends GetOptions = {}> = GetWithPath<BaseType, Path extends string ? ToPath<Path> : Path, Options>;
1297
1045
  export type PlainObject = UnknownRecord;
1298
1046
  /**
1299
1047
  * - Get the value from an object using a known path
1300
1048
  * - You can retrieve a nested value by using dot notation, e.g., `foo.bar.baz`
1301
1049
  * - Returns `undefined` if the value is not found
1302
1050
  */
1303
- export declare function getValue<
1304
- Data extends PlainObject,
1305
- Path extends Paths<Data>,
1306
- >(data: Data, path: Path): Get<Data, ToString<Path>>;
1051
+ export declare function getValue<Data extends PlainObject, Path extends Paths<Data>>(data: Data, path: Path): Get<Data, ToString<Path>>;
1307
1052
  /**
1308
1053
  * - Get the value from an object using an unknown path
1309
1054
  * - You can retrieve a nested value by using dot notation, e.g., `foo.bar.baz`
1310
1055
  * - If `ignoreCase` is `true`, path matching will be case-insensitive
1311
1056
  * - Returns `undefined` if the value is not found
1312
1057
  */
1313
- export declare function getValue<Data extends PlainObject>(
1314
- data: Data,
1315
- path: string,
1316
- ignoreCase?: boolean,
1317
- ): unknown;
1058
+ export declare function getValue<Data extends PlainObject>(data: Data, path: string, ignoreCase?: boolean): unknown;
1318
1059
 
1319
1060
  export {};