@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.
- package/dist/js/array/count.cjs +1 -8
- package/dist/js/array/count.js +1 -8
- package/dist/js/array/exists.cjs +1 -8
- package/dist/js/array/exists.js +1 -8
- package/dist/js/array/filter.cjs +1 -8
- package/dist/js/array/filter.js +1 -8
- package/dist/js/array/find.cjs +1 -8
- package/dist/js/array/find.js +1 -8
- package/dist/js/array/index-of.cjs +1 -8
- package/dist/js/array/index-of.js +1 -8
- package/dist/js/array/unique.cjs +1 -1
- package/dist/js/array/unique.js +1 -1
- package/dist/js/internal/array/find.cjs +12 -2
- package/dist/js/internal/array/find.js +12 -2
- package/package.json +11 -4
- package/src/js/array/count.ts +7 -20
- package/src/js/array/exists.ts +7 -22
- package/src/js/array/filter.ts +7 -20
- package/src/js/array/find.ts +7 -20
- package/src/js/array/group-by.ts +19 -21
- package/src/js/array/index-of.ts +7 -20
- package/src/js/array/models.ts +2 -16
- package/src/js/array/sort.ts +3 -7
- package/src/js/array/to-map.ts +19 -21
- package/src/js/array/to-record.ts +17 -19
- package/src/js/array/unique.ts +8 -8
- package/src/js/internal/array/callbacks.ts +4 -4
- package/src/js/internal/array/find.ts +29 -6
- package/types/array/count.d.cts +2 -5
- package/types/array/count.d.ts +3 -3
- package/types/array/exists.d.cts +2 -5
- package/types/array/exists.d.ts +3 -3
- package/types/array/filter.d.cts +2 -5
- package/types/array/filter.d.ts +3 -3
- package/types/array/find.d.cts +2 -5
- package/types/array/find.d.ts +3 -3
- package/types/array/group-by.d.cts +8 -11
- package/types/array/group-by.d.ts +10 -11
- package/types/array/index-of.d.cts +2 -5
- package/types/array/index-of.d.ts +3 -3
- package/types/array/index.d.cts +43 -48
- package/types/array/models.d.cts +2 -7
- package/types/array/models.d.ts +2 -7
- package/types/array/sort.d.cts +3 -4
- package/types/array/sort.d.ts +3 -3
- package/types/array/to-map.d.cts +8 -11
- package/types/array/to-map.d.ts +9 -10
- package/types/array/to-record.d.cts +8 -11
- package/types/array/to-record.d.ts +9 -10
- package/types/array/unique.d.cts +3 -5
- package/types/array/unique.d.ts +4 -4
- package/types/index.d.cts +321 -1019
- package/types/internal/array/find.d.cts +2 -2
- package/types/internal/array/find.d.ts +2 -2
- package/types/models.d.cts +210 -467
- package/types/value/get.d.cts +210 -469
- package/types/value/index.d.cts +223 -514
- package/types/value/set.d.cts +169 -356
- package/types/value/smush.d.cts +209 -463
package/types/index.d.cts
CHANGED
|
@@ -5,10 +5,7 @@
|
|
|
5
5
|
* - Maximum size defaults to _2^20_; any provided size will be clamped at _2^24_
|
|
6
6
|
* - Behaviour is similar to a _LRU_-cache, where the least recently used entries are removed
|
|
7
7
|
*/
|
|
8
|
-
export declare class SizedMap<Key = unknown, Value = unknown> extends Map<
|
|
9
|
-
Key,
|
|
10
|
-
Value
|
|
11
|
-
> {
|
|
8
|
+
export declare class SizedMap<Key = unknown, Value = unknown> extends Map<Key, Value> {
|
|
12
9
|
private readonly maximumSize;
|
|
13
10
|
/**
|
|
14
11
|
* Is the Map full?
|
|
@@ -21,7 +18,10 @@ export declare class SizedMap<Key = unknown, Value = unknown> extends Map<
|
|
|
21
18
|
/**
|
|
22
19
|
* Create a new Map with entries and a maximum size _(2^20)_
|
|
23
20
|
*/
|
|
24
|
-
constructor(entries: Array<[
|
|
21
|
+
constructor(entries: Array<[
|
|
22
|
+
Key,
|
|
23
|
+
Value
|
|
24
|
+
]>);
|
|
25
25
|
/**
|
|
26
26
|
* Create a new Map with a maximum size _(but clamped at 2^24)_
|
|
27
27
|
*/
|
|
@@ -29,7 +29,10 @@ export declare class SizedMap<Key = unknown, Value = unknown> extends Map<
|
|
|
29
29
|
/**
|
|
30
30
|
* Create a new Map with _(optional)_ entries and a maximum size _(defaults to 2^20; clamped at 2^24)_
|
|
31
31
|
*/
|
|
32
|
-
constructor(entries?: Array<[
|
|
32
|
+
constructor(entries?: Array<[
|
|
33
|
+
Key,
|
|
34
|
+
Value
|
|
35
|
+
]>, maximum?: number);
|
|
33
36
|
/**
|
|
34
37
|
* @inheritdoc
|
|
35
38
|
*/
|
|
@@ -89,10 +92,7 @@ export declare function getRandomBoolean(): boolean;
|
|
|
89
92
|
* Get a random string of characters with a specified length
|
|
90
93
|
* - `selection` defaults to all lowercase letters in the English alphabet
|
|
91
94
|
*/
|
|
92
|
-
export declare function getRandomCharacters(
|
|
93
|
-
length: number,
|
|
94
|
-
selection?: string,
|
|
95
|
-
): string;
|
|
95
|
+
export declare function getRandomCharacters(length: number, selection?: string): string;
|
|
96
96
|
/**
|
|
97
97
|
* Get a random hexadecimal colour
|
|
98
98
|
*/
|
|
@@ -117,10 +117,7 @@ export declare function getRandomItem<Value>(array: Value[]): Value;
|
|
|
117
117
|
* - Get an amount of random items from an array
|
|
118
118
|
* - If `amount` is not specified, a shuffled array will be returned instead
|
|
119
119
|
*/
|
|
120
|
-
export declare function getRandomItems<Value>(
|
|
121
|
-
array: Value[],
|
|
122
|
-
amount?: number,
|
|
123
|
-
): Value[];
|
|
120
|
+
export declare function getRandomItems<Value>(array: Value[], amount?: number): Value[];
|
|
124
121
|
/**
|
|
125
122
|
* Queue a callback to be executed at the next best time
|
|
126
123
|
*/
|
|
@@ -130,14 +127,7 @@ Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/
|
|
|
130
127
|
|
|
131
128
|
@category Type
|
|
132
129
|
*/
|
|
133
|
-
export type Primitive =
|
|
134
|
-
| null
|
|
135
|
-
| undefined
|
|
136
|
-
| string
|
|
137
|
-
| number
|
|
138
|
-
| boolean
|
|
139
|
-
| symbol
|
|
140
|
-
| bigint;
|
|
130
|
+
export type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
141
131
|
/**
|
|
142
132
|
Create a union of all keys from a given type, even those exclusive to specific union members.
|
|
143
133
|
|
|
@@ -175,9 +165,7 @@ type AllKeys = KeysOfUnion<Union>;
|
|
|
175
165
|
|
|
176
166
|
@category Object
|
|
177
167
|
*/
|
|
178
|
-
export type KeysOfUnion<ObjectType> = ObjectType extends unknown
|
|
179
|
-
? keyof ObjectType
|
|
180
|
-
: never;
|
|
168
|
+
export type KeysOfUnion<ObjectType> = ObjectType extends unknown ? keyof ObjectType : never;
|
|
181
169
|
declare const emptyObjectSymbol: unique symbol;
|
|
182
170
|
/**
|
|
183
171
|
Represents a strictly empty plain object, the `{}` value.
|
|
@@ -234,11 +222,7 @@ type Includes<Value extends readonly any[], Item> =
|
|
|
234
222
|
@category Type Guard
|
|
235
223
|
@category Utilities
|
|
236
224
|
*/
|
|
237
|
-
export type IsEqual<A, B> = (<G>() => G extends A ? 1 : 2) extends <
|
|
238
|
-
G,
|
|
239
|
-
>() => G extends B ? 1 : 2
|
|
240
|
-
? true
|
|
241
|
-
: false;
|
|
225
|
+
export type IsEqual<A, B> = (<G>() => G extends A ? 1 : 2) extends (<G>() => G extends B ? 1 : 2) ? true : false;
|
|
242
226
|
/**
|
|
243
227
|
Represents an object with `unknown` value. You probably want this instead of `{}`.
|
|
244
228
|
|
|
@@ -365,16 +349,14 @@ type B = StaticPartOfArray<A>;
|
|
|
365
349
|
//=> [string, number, boolean]
|
|
366
350
|
```
|
|
367
351
|
*/
|
|
368
|
-
export type StaticPartOfArray<
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
: T
|
|
377
|
-
: never; // Should never happen
|
|
352
|
+
export type StaticPartOfArray<T extends UnknownArray, Result extends UnknownArray = [
|
|
353
|
+
]> = T extends unknown ? number extends T["length"] ? T extends readonly [
|
|
354
|
+
infer U,
|
|
355
|
+
...infer V
|
|
356
|
+
] ? StaticPartOfArray<V, [
|
|
357
|
+
...Result,
|
|
358
|
+
U
|
|
359
|
+
]> : Result : T : never; // Should never happen
|
|
378
360
|
/**
|
|
379
361
|
Returns the variable, non-fixed-length portion of the given array, excluding static-length parts.
|
|
380
362
|
|
|
@@ -385,22 +367,12 @@ type B = VariablePartOfArray<A>;
|
|
|
385
367
|
//=> string[]
|
|
386
368
|
```
|
|
387
369
|
*/
|
|
388
|
-
export type VariablePartOfArray<T extends UnknownArray> = T extends unknown
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
export type StringDigit =
|
|
394
|
-
| '0'
|
|
395
|
-
| '1'
|
|
396
|
-
| '2'
|
|
397
|
-
| '3'
|
|
398
|
-
| '4'
|
|
399
|
-
| '5'
|
|
400
|
-
| '6'
|
|
401
|
-
| '7'
|
|
402
|
-
| '8'
|
|
403
|
-
| '9';
|
|
370
|
+
export type VariablePartOfArray<T extends UnknownArray> = T extends unknown ? T extends readonly [
|
|
371
|
+
...StaticPartOfArray<T>,
|
|
372
|
+
...infer U
|
|
373
|
+
] ? U : [
|
|
374
|
+
] : never; // Should never happen
|
|
375
|
+
export type StringDigit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
404
376
|
/**
|
|
405
377
|
Returns a boolean for whether the given type is `any`.
|
|
406
378
|
|
|
@@ -443,7 +415,7 @@ Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277)
|
|
|
443
415
|
*/
|
|
444
416
|
// See https://github.com/microsoft/TypeScript/issues/31752
|
|
445
417
|
// eslint-disable-next-line @typescript-eslint/no-loss-of-precision
|
|
446
|
-
export type PositiveInfinity =
|
|
418
|
+
export type PositiveInfinity = Infinity;
|
|
447
419
|
/**
|
|
448
420
|
Matches the hidden `-Infinity` type.
|
|
449
421
|
|
|
@@ -455,7 +427,7 @@ Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277)
|
|
|
455
427
|
*/
|
|
456
428
|
// See https://github.com/microsoft/TypeScript/issues/31752
|
|
457
429
|
// eslint-disable-next-line @typescript-eslint/no-loss-of-precision
|
|
458
|
-
export type NegativeInfinity = -
|
|
430
|
+
export type NegativeInfinity = -Infinity;
|
|
459
431
|
/**
|
|
460
432
|
A negative `number`/`bigint` (`-∞ < x < 0`)
|
|
461
433
|
|
|
@@ -466,11 +438,7 @@ Use-case: Validating and documenting parameters.
|
|
|
466
438
|
|
|
467
439
|
@category Numeric
|
|
468
440
|
*/
|
|
469
|
-
export type Negative<T extends Numeric> = T extends Zero
|
|
470
|
-
? never
|
|
471
|
-
: `${T}` extends `-${string}`
|
|
472
|
-
? T
|
|
473
|
-
: never;
|
|
441
|
+
export type Negative<T extends Numeric> = T extends Zero ? never : `${T}` extends `-${string}` ? T : never;
|
|
474
442
|
/**
|
|
475
443
|
Returns a boolean for whether the given number is a negative number.
|
|
476
444
|
|
|
@@ -486,9 +454,7 @@ type ShouldBeTrue = IsNegative<-1>;
|
|
|
486
454
|
|
|
487
455
|
@category Numeric
|
|
488
456
|
*/
|
|
489
|
-
export type IsNegative<T extends Numeric> = T extends Negative<T>
|
|
490
|
-
? true
|
|
491
|
-
: false;
|
|
457
|
+
export type IsNegative<T extends Numeric> = T extends Negative<T> ? true : false;
|
|
492
458
|
/**
|
|
493
459
|
Returns a boolean for whether two given types are both true.
|
|
494
460
|
|
|
@@ -509,12 +475,11 @@ And<true, false>;
|
|
|
509
475
|
*/
|
|
510
476
|
export type And<A extends boolean, B extends boolean> = [
|
|
511
477
|
A,
|
|
512
|
-
B
|
|
513
|
-
][number] extends true
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
: never;
|
|
478
|
+
B
|
|
479
|
+
][number] extends true ? true : true extends [
|
|
480
|
+
IsEqual<A, false>,
|
|
481
|
+
IsEqual<B, false>
|
|
482
|
+
][number] ? false : never;
|
|
518
483
|
/**
|
|
519
484
|
Returns a boolean for whether either of two given types are true.
|
|
520
485
|
|
|
@@ -535,12 +500,11 @@ Or<false, false>;
|
|
|
535
500
|
*/
|
|
536
501
|
export type Or<A extends boolean, B extends boolean> = [
|
|
537
502
|
A,
|
|
538
|
-
B
|
|
539
|
-
][number] extends false
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
: never;
|
|
503
|
+
B
|
|
504
|
+
][number] extends false ? false : true extends [
|
|
505
|
+
IsEqual<A, true>,
|
|
506
|
+
IsEqual<B, true>
|
|
507
|
+
][number] ? true : never;
|
|
544
508
|
/**
|
|
545
509
|
Returns a boolean for whether a given number is greater than another number.
|
|
546
510
|
|
|
@@ -558,44 +522,32 @@ GreaterThan<1, 5>;
|
|
|
558
522
|
//=> false
|
|
559
523
|
```
|
|
560
524
|
*/
|
|
561
|
-
export type GreaterThan<A extends number, B extends number> = number extends
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
? [true, false] extends R
|
|
588
|
-
? false
|
|
589
|
-
: [false, true] extends R
|
|
590
|
-
? true
|
|
591
|
-
: [false, false] extends R
|
|
592
|
-
? PositiveNumericStringGt<`${A}`, `${B}`>
|
|
593
|
-
: PositiveNumericStringGt<
|
|
594
|
-
`${NumberAbsolute<B>}`,
|
|
595
|
-
`${NumberAbsolute<A>}`
|
|
596
|
-
>
|
|
597
|
-
: never
|
|
598
|
-
: never;
|
|
525
|
+
export type GreaterThan<A extends number, B extends number> = number extends A | B ? never : [
|
|
526
|
+
IsEqual<A, PositiveInfinity>,
|
|
527
|
+
IsEqual<A, NegativeInfinity>,
|
|
528
|
+
IsEqual<B, PositiveInfinity>,
|
|
529
|
+
IsEqual<B, NegativeInfinity>
|
|
530
|
+
] extends infer R extends [
|
|
531
|
+
boolean,
|
|
532
|
+
boolean,
|
|
533
|
+
boolean,
|
|
534
|
+
boolean
|
|
535
|
+
] ? 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 : [
|
|
536
|
+
IsNegative<A>,
|
|
537
|
+
IsNegative<B>
|
|
538
|
+
] extends infer R extends [
|
|
539
|
+
boolean,
|
|
540
|
+
boolean
|
|
541
|
+
] ? [
|
|
542
|
+
true,
|
|
543
|
+
false
|
|
544
|
+
] extends R ? false : [
|
|
545
|
+
false,
|
|
546
|
+
true
|
|
547
|
+
] extends R ? true : [
|
|
548
|
+
false,
|
|
549
|
+
false
|
|
550
|
+
] extends R ? PositiveNumericStringGt<`${A}`, `${B}`> : PositiveNumericStringGt<`${NumberAbsolute<B>}`, `${NumberAbsolute<A>}`> : never : never;
|
|
599
551
|
/**
|
|
600
552
|
Returns a boolean for whether a given number is greater than or equal to another number.
|
|
601
553
|
|
|
@@ -613,10 +565,7 @@ GreaterThanOrEqual<1, 5>;
|
|
|
613
565
|
//=> false
|
|
614
566
|
```
|
|
615
567
|
*/
|
|
616
|
-
export type GreaterThanOrEqual<
|
|
617
|
-
A extends number,
|
|
618
|
-
B extends number,
|
|
619
|
-
> = number extends A | B ? never : A extends B ? true : GreaterThan<A, B>;
|
|
568
|
+
export type GreaterThanOrEqual<A extends number, B extends number> = number extends A | B ? never : A extends B ? true : GreaterThan<A, B>;
|
|
620
569
|
/**
|
|
621
570
|
Returns a boolean for whether a given number is less than another number.
|
|
622
571
|
|
|
@@ -634,11 +583,7 @@ LessThan<1, 5>;
|
|
|
634
583
|
//=> true
|
|
635
584
|
```
|
|
636
585
|
*/
|
|
637
|
-
export type LessThan<A extends number, B extends number> = number extends A | B
|
|
638
|
-
? never
|
|
639
|
-
: GreaterThanOrEqual<A, B> extends true
|
|
640
|
-
? false
|
|
641
|
-
: true;
|
|
586
|
+
export type LessThan<A extends number, B extends number> = number extends A | B ? never : GreaterThanOrEqual<A, B> extends true ? false : true;
|
|
642
587
|
/**
|
|
643
588
|
Create a tuple type of the given length `<L>` and fill it with the given type `<Fill>`.
|
|
644
589
|
|
|
@@ -646,11 +591,11 @@ If `<Fill>` is not provided, it will default to `unknown`.
|
|
|
646
591
|
|
|
647
592
|
@link https://itnext.io/implementing-arithmetic-within-typescripts-type-system-a1ef140a6f6f
|
|
648
593
|
*/
|
|
649
|
-
export type BuildTuple<
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
594
|
+
export type BuildTuple<L extends number, Fill = unknown, T extends readonly unknown[] = [
|
|
595
|
+
]> = T["length"] extends L ? T : BuildTuple<L, Fill, [
|
|
596
|
+
...T,
|
|
597
|
+
Fill
|
|
598
|
+
]>;
|
|
654
599
|
/**
|
|
655
600
|
Returns the maximum value from a tuple of integers.
|
|
656
601
|
|
|
@@ -666,16 +611,10 @@ ArrayMax<[1, 2, 5, 3, 99, -1]>;
|
|
|
666
611
|
//=> 99
|
|
667
612
|
```
|
|
668
613
|
*/
|
|
669
|
-
export type TupleMax<
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
? never
|
|
674
|
-
: A extends [infer F extends number, ...infer R extends number[]]
|
|
675
|
-
? GreaterThan<F, Result> extends true
|
|
676
|
-
? TupleMax<R, F>
|
|
677
|
-
: TupleMax<R, Result>
|
|
678
|
-
: Result;
|
|
614
|
+
export type TupleMax<A extends number[], Result extends number = NegativeInfinity> = number extends A[number] ? never : A extends [
|
|
615
|
+
infer F extends number,
|
|
616
|
+
...infer R extends number[]
|
|
617
|
+
] ? GreaterThan<F, Result> extends true ? TupleMax<R, F> : TupleMax<R, Result> : Result;
|
|
679
618
|
/**
|
|
680
619
|
Returns the minimum value from a tuple of integers.
|
|
681
620
|
|
|
@@ -691,16 +630,10 @@ ArrayMin<[1, 2, 5, 3, -5]>;
|
|
|
691
630
|
//=> -5
|
|
692
631
|
```
|
|
693
632
|
*/
|
|
694
|
-
export type TupleMin<
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
? never
|
|
699
|
-
: A extends [infer F extends number, ...infer R extends number[]]
|
|
700
|
-
? LessThan<F, Result> extends true
|
|
701
|
-
? TupleMin<R, F>
|
|
702
|
-
: TupleMin<R, Result>
|
|
703
|
-
: Result;
|
|
633
|
+
export type TupleMin<A extends number[], Result extends number = PositiveInfinity> = number extends A[number] ? never : A extends [
|
|
634
|
+
infer F extends number,
|
|
635
|
+
...infer R extends number[]
|
|
636
|
+
] ? LessThan<F, Result> extends true ? TupleMin<R, F> : TupleMin<R, Result> : Result;
|
|
704
637
|
/**
|
|
705
638
|
Return a string representation of the given string or number.
|
|
706
639
|
|
|
@@ -735,14 +668,7 @@ type NegativeInfinity = StringToNumber<'-Infinity'>;
|
|
|
735
668
|
@category Numeric
|
|
736
669
|
@category Template literal
|
|
737
670
|
*/
|
|
738
|
-
export type StringToNumber<S extends string> =
|
|
739
|
-
S extends `${infer N extends number}`
|
|
740
|
-
? N
|
|
741
|
-
: S extends 'Infinity'
|
|
742
|
-
? PositiveInfinity
|
|
743
|
-
: S extends '-Infinity'
|
|
744
|
-
? NegativeInfinity
|
|
745
|
-
: never;
|
|
671
|
+
export type StringToNumber<S extends string> = S extends `${infer N extends number}` ? N : S extends "Infinity" ? PositiveInfinity : S extends "-Infinity" ? NegativeInfinity : never;
|
|
746
672
|
/**
|
|
747
673
|
Returns an array of the characters of the string.
|
|
748
674
|
|
|
@@ -757,14 +683,11 @@ StringToArray<string>;
|
|
|
757
683
|
|
|
758
684
|
@category String
|
|
759
685
|
*/
|
|
760
|
-
export type StringToArray<
|
|
761
|
-
|
|
762
|
-
Result
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
: S extends `${infer F}${infer R}`
|
|
766
|
-
? StringToArray<R, [...Result, F]>
|
|
767
|
-
: Result;
|
|
686
|
+
export type StringToArray<S extends string, Result extends string[] = [
|
|
687
|
+
]> = string extends S ? never : S extends `${infer F}${infer R}` ? StringToArray<R, [
|
|
688
|
+
...Result,
|
|
689
|
+
F
|
|
690
|
+
]> : Result;
|
|
768
691
|
/**
|
|
769
692
|
Returns the length of the given string.
|
|
770
693
|
|
|
@@ -780,9 +703,7 @@ StringLength<string>;
|
|
|
780
703
|
@category String
|
|
781
704
|
@category Template literal
|
|
782
705
|
*/
|
|
783
|
-
export type StringLength<S extends string> = string extends S
|
|
784
|
-
? never
|
|
785
|
-
: StringToArray<S>['length'];
|
|
706
|
+
export type StringLength<S extends string> = string extends S ? never : StringToArray<S>["length"];
|
|
786
707
|
/**
|
|
787
708
|
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.
|
|
788
709
|
|
|
@@ -795,17 +716,8 @@ SameLengthPositiveNumericStringGt<'10', '10'>;
|
|
|
795
716
|
//=> false
|
|
796
717
|
```
|
|
797
718
|
*/
|
|
798
|
-
export type SameLengthPositiveNumericStringGt<
|
|
799
|
-
|
|
800
|
-
B extends string,
|
|
801
|
-
> = A extends `${infer FirstA}${infer RestA}`
|
|
802
|
-
? B extends `${infer FirstB}${infer RestB}`
|
|
803
|
-
? FirstA extends FirstB
|
|
804
|
-
? SameLengthPositiveNumericStringGt<RestA, RestB>
|
|
805
|
-
: PositiveNumericCharacterGt<FirstA, FirstB>
|
|
806
|
-
: never
|
|
807
|
-
: false;
|
|
808
|
-
export type NumericString = '0123456789';
|
|
719
|
+
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;
|
|
720
|
+
export type NumericString = "0123456789";
|
|
809
721
|
/**
|
|
810
722
|
Returns a boolean for whether `A` is greater than `B`, where `A` and `B` are both positive numeric strings.
|
|
811
723
|
|
|
@@ -821,21 +733,16 @@ PositiveNumericStringGt<'1', '500'>;
|
|
|
821
733
|
//=> false
|
|
822
734
|
```
|
|
823
735
|
*/
|
|
824
|
-
export type PositiveNumericStringGt<
|
|
825
|
-
A
|
|
826
|
-
B
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
? 0 extends Remain['length']
|
|
835
|
-
? SameLengthPositiveNumericStringGt<A, B>
|
|
836
|
-
: true
|
|
837
|
-
: false
|
|
838
|
-
: never;
|
|
736
|
+
export type PositiveNumericStringGt<A extends string, B extends string> = A extends B ? false : [
|
|
737
|
+
BuildTuple<StringLength<A>, 0>,
|
|
738
|
+
BuildTuple<StringLength<B>, 0>
|
|
739
|
+
] extends infer R extends [
|
|
740
|
+
readonly unknown[],
|
|
741
|
+
readonly unknown[]
|
|
742
|
+
] ? R[0] extends [
|
|
743
|
+
...R[1],
|
|
744
|
+
...infer Remain extends readonly unknown[]
|
|
745
|
+
] ? 0 extends Remain["length"] ? SameLengthPositiveNumericStringGt<A, B> : true : false : never;
|
|
839
746
|
/**
|
|
840
747
|
Returns a boolean for whether `A` represents a number greater than `B`, where `A` and `B` are both positive numeric characters.
|
|
841
748
|
|
|
@@ -848,16 +755,7 @@ PositiveNumericCharacterGt<'1', '1'>;
|
|
|
848
755
|
//=> false
|
|
849
756
|
```
|
|
850
757
|
*/
|
|
851
|
-
export type PositiveNumericCharacterGt<
|
|
852
|
-
A extends string,
|
|
853
|
-
B extends string,
|
|
854
|
-
> = NumericString extends `${infer HeadA}${A}${infer TailA}`
|
|
855
|
-
? NumericString extends `${infer HeadB}${B}${infer TailB}`
|
|
856
|
-
? HeadA extends `${HeadB}${infer _}${infer __}`
|
|
857
|
-
? true
|
|
858
|
-
: false
|
|
859
|
-
: never
|
|
860
|
-
: never;
|
|
758
|
+
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;
|
|
861
759
|
/**
|
|
862
760
|
Returns the absolute value of a given value.
|
|
863
761
|
|
|
@@ -873,10 +771,7 @@ NumberAbsolute<NegativeInfinity>
|
|
|
873
771
|
//=> PositiveInfinity
|
|
874
772
|
```
|
|
875
773
|
*/
|
|
876
|
-
export type NumberAbsolute<N extends number> =
|
|
877
|
-
`${N}` extends `-${infer StringPositiveN}`
|
|
878
|
-
? StringToNumber<StringPositiveN>
|
|
879
|
-
: N;
|
|
774
|
+
export type NumberAbsolute<N extends number> = `${N}` extends `-${infer StringPositiveN}` ? StringToNumber<StringPositiveN> : N;
|
|
880
775
|
/**
|
|
881
776
|
Check whether the given type is a number or a number string.
|
|
882
777
|
|
|
@@ -896,13 +791,7 @@ type C = IsNumberLike<1>;
|
|
|
896
791
|
type D = IsNumberLike<'a'>;
|
|
897
792
|
//=> false
|
|
898
793
|
*/
|
|
899
|
-
export type IsNumberLike<N> = N extends number
|
|
900
|
-
? true
|
|
901
|
-
: N extends `${number}`
|
|
902
|
-
? true
|
|
903
|
-
: N extends `${number}.${number}`
|
|
904
|
-
? true
|
|
905
|
-
: false;
|
|
794
|
+
export type IsNumberLike<N> = N extends number ? true : N extends `${number}` ? true : N extends `${number}.${number}` ? true : false;
|
|
906
795
|
/**
|
|
907
796
|
Matches any primitive, `void`, `Date`, or `RegExp` value.
|
|
908
797
|
*/
|
|
@@ -910,12 +799,7 @@ export type BuiltIns = Primitive | void | Date | RegExp;
|
|
|
910
799
|
/**
|
|
911
800
|
Matches non-recursive types.
|
|
912
801
|
*/
|
|
913
|
-
export type NonRecursiveType =
|
|
914
|
-
| BuiltIns
|
|
915
|
-
| Function
|
|
916
|
-
| (new (
|
|
917
|
-
...arguments_: any[]
|
|
918
|
-
) => unknown);
|
|
802
|
+
export type NonRecursiveType = BuiltIns | Function | (new (...arguments_: any[]) => unknown);
|
|
919
803
|
/**
|
|
920
804
|
Returns the sum of two numbers.
|
|
921
805
|
|
|
@@ -947,45 +831,35 @@ Sum<PositiveInfinity, NegativeInfinity>;
|
|
|
947
831
|
@category Numeric
|
|
948
832
|
*/
|
|
949
833
|
// TODO: Support big integer and negative number.
|
|
950
|
-
export type Sum<A extends number, B extends number> = number extends A | B
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
[NumberAbsolute<A>, NumberAbsolute<B>]
|
|
980
|
-
> extends infer Min_ extends number
|
|
981
|
-
? Max_ extends A | B
|
|
982
|
-
? Subtract<Max_, Min_>
|
|
983
|
-
: number
|
|
984
|
-
: never
|
|
985
|
-
: never
|
|
986
|
-
: never) &
|
|
987
|
-
number
|
|
988
|
-
: never;
|
|
834
|
+
export type Sum<A extends number, B extends number> = number extends A | B ? number : [
|
|
835
|
+
IsEqual<A, PositiveInfinity>,
|
|
836
|
+
IsEqual<A, NegativeInfinity>,
|
|
837
|
+
IsEqual<B, PositiveInfinity>,
|
|
838
|
+
IsEqual<B, NegativeInfinity>
|
|
839
|
+
] extends infer R extends [
|
|
840
|
+
boolean,
|
|
841
|
+
boolean,
|
|
842
|
+
boolean,
|
|
843
|
+
boolean
|
|
844
|
+
] ? 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 : ([
|
|
845
|
+
IsNegative<A>,
|
|
846
|
+
IsNegative<B>
|
|
847
|
+
] extends infer R ? [
|
|
848
|
+
false,
|
|
849
|
+
false
|
|
850
|
+
] extends R ? [
|
|
851
|
+
...BuildTuple<A>,
|
|
852
|
+
...BuildTuple<B>
|
|
853
|
+
]["length"] : [
|
|
854
|
+
true,
|
|
855
|
+
true
|
|
856
|
+
] extends R ? number : TupleMax<[
|
|
857
|
+
NumberAbsolute<A>,
|
|
858
|
+
NumberAbsolute<B>
|
|
859
|
+
]> extends infer Max_ ? TupleMin<[
|
|
860
|
+
NumberAbsolute<A>,
|
|
861
|
+
NumberAbsolute<B>
|
|
862
|
+
]> extends infer Min_ extends number ? Max_ extends A | B ? Subtract<Max_, Min_> : number : never : never : never) & number : never;
|
|
989
863
|
/**
|
|
990
864
|
Returns the difference between two numbers.
|
|
991
865
|
|
|
@@ -1016,40 +890,29 @@ Subtract<PositiveInfinity, PositiveInfinity>;
|
|
|
1016
890
|
@category Numeric
|
|
1017
891
|
*/
|
|
1018
892
|
// TODO: Support big integer and negative number.
|
|
1019
|
-
export type Subtract<A extends number, B extends number> = number extends A | B
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
? R extends [...BuildTuple<B>, ...infer R]
|
|
1043
|
-
? R['length']
|
|
1044
|
-
: number
|
|
1045
|
-
: never
|
|
1046
|
-
: LessThan<A, B> extends true
|
|
1047
|
-
? number
|
|
1048
|
-
: [false, true] extends R
|
|
1049
|
-
? Sum<A, NumberAbsolute<B>>
|
|
1050
|
-
: Subtract<NumberAbsolute<B>, NumberAbsolute<A>>
|
|
1051
|
-
: never
|
|
1052
|
-
: never;
|
|
893
|
+
export type Subtract<A extends number, B extends number> = number extends A | B ? number : [
|
|
894
|
+
IsEqual<A, PositiveInfinity>,
|
|
895
|
+
IsEqual<A, NegativeInfinity>,
|
|
896
|
+
IsEqual<B, PositiveInfinity>,
|
|
897
|
+
IsEqual<B, NegativeInfinity>
|
|
898
|
+
] extends infer R extends [
|
|
899
|
+
boolean,
|
|
900
|
+
boolean,
|
|
901
|
+
boolean,
|
|
902
|
+
boolean
|
|
903
|
+
] ? 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 : [
|
|
904
|
+
IsNegative<A>,
|
|
905
|
+
IsNegative<B>
|
|
906
|
+
] extends infer R ? [
|
|
907
|
+
false,
|
|
908
|
+
false
|
|
909
|
+
] extends R ? BuildTuple<A> extends infer R ? R extends [
|
|
910
|
+
...BuildTuple<B>,
|
|
911
|
+
...infer R
|
|
912
|
+
] ? R["length"] : number : never : LessThan<A, B> extends true ? number : [
|
|
913
|
+
false,
|
|
914
|
+
true
|
|
915
|
+
] extends R ? Sum<A, NumberAbsolute<B>> : Subtract<NumberAbsolute<B>, NumberAbsolute<A>> : never : never;
|
|
1053
916
|
/**
|
|
1054
917
|
Paths options.
|
|
1055
918
|
|
|
@@ -1140,85 +1003,28 @@ open('listB.1'); // TypeError. Because listB only has one element.
|
|
|
1140
1003
|
@category Object
|
|
1141
1004
|
@category Array
|
|
1142
1005
|
*/
|
|
1143
|
-
export type Paths<T, Options extends PathsOptions = {}> = _Paths<
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
}
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
?
|
|
1166
|
-
| InternalPaths<StaticPartOfArray<T>, Options>
|
|
1167
|
-
| InternalPaths<Array<VariablePartOfArray<T>[number]>, Options>
|
|
1168
|
-
: InternalPaths<T, Options>
|
|
1169
|
-
: T extends object
|
|
1170
|
-
? InternalPaths<T, Options>
|
|
1171
|
-
: never;
|
|
1172
|
-
export type InternalPaths<
|
|
1173
|
-
T,
|
|
1174
|
-
Options extends Required<PathsOptions>,
|
|
1175
|
-
> = Options['maxRecursionDepth'] extends infer MaxDepth extends number
|
|
1176
|
-
? Required<T> extends infer T
|
|
1177
|
-
? T extends EmptyObject | readonly []
|
|
1178
|
-
? never
|
|
1179
|
-
: {
|
|
1180
|
-
[Key in keyof T]: Key extends string | number // Limit `Key` to string or number.
|
|
1181
|
-
? (
|
|
1182
|
-
Options['bracketNotation'] extends true
|
|
1183
|
-
? IsNumberLike<Key> extends true
|
|
1184
|
-
? `[${Key}]`
|
|
1185
|
-
: Key | ToString<Key>
|
|
1186
|
-
: never | Options['bracketNotation'] extends false
|
|
1187
|
-
? Key | ToString<Key>
|
|
1188
|
-
: never
|
|
1189
|
-
) extends infer TranformedKey extends string | number
|
|
1190
|
-
? // 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
|
|
1191
|
-
// 2. If style is 'a.0.b', transform 'Key' to `${Key}` | Key
|
|
1192
|
-
| TranformedKey
|
|
1193
|
-
// Recursively generate paths for the current key
|
|
1194
|
-
| (GreaterThan<MaxDepth, 0> extends true // Limit the depth to prevent infinite recursion
|
|
1195
|
-
? _Paths<
|
|
1196
|
-
T[Key],
|
|
1197
|
-
{
|
|
1198
|
-
bracketNotation: Options['bracketNotation'];
|
|
1199
|
-
maxRecursionDepth: Subtract<MaxDepth, 1>;
|
|
1200
|
-
}
|
|
1201
|
-
> extends infer SubPath
|
|
1202
|
-
? SubPath extends string | number
|
|
1203
|
-
?
|
|
1204
|
-
| (Options['bracketNotation'] extends true
|
|
1205
|
-
? SubPath extends
|
|
1206
|
-
| `[${any}]`
|
|
1207
|
-
| `[${any}]${string}`
|
|
1208
|
-
? `${TranformedKey}${SubPath}` // If next node is number key like `[3]`, no need to add `.` before it.
|
|
1209
|
-
: `${TranformedKey}.${SubPath}`
|
|
1210
|
-
: never)
|
|
1211
|
-
| (Options['bracketNotation'] extends false
|
|
1212
|
-
? `${TranformedKey}.${SubPath}`
|
|
1213
|
-
: never)
|
|
1214
|
-
: never
|
|
1215
|
-
: never
|
|
1216
|
-
: never)
|
|
1217
|
-
: never
|
|
1218
|
-
: never;
|
|
1219
|
-
}[keyof T & (T extends UnknownArray ? number : unknown)]
|
|
1220
|
-
: never
|
|
1221
|
-
: never;
|
|
1006
|
+
export type Paths<T, Options extends PathsOptions = {}> = _Paths<T, {
|
|
1007
|
+
// Set default maxRecursionDepth to 10
|
|
1008
|
+
maxRecursionDepth: Options["maxRecursionDepth"] extends number ? Options["maxRecursionDepth"] : DefaultPathsOptions["maxRecursionDepth"];
|
|
1009
|
+
// Set default bracketNotation to false
|
|
1010
|
+
bracketNotation: Options["bracketNotation"] extends boolean ? Options["bracketNotation"] : DefaultPathsOptions["bracketNotation"];
|
|
1011
|
+
}>;
|
|
1012
|
+
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;
|
|
1013
|
+
export type InternalPaths<T, Options extends Required<PathsOptions>> = Options["maxRecursionDepth"] extends infer MaxDepth extends number ? Required<T> extends infer T ? T extends EmptyObject | readonly [
|
|
1014
|
+
] ? never : {
|
|
1015
|
+
[Key in keyof T]: Key extends string | number // Limit `Key` to string or number.
|
|
1016
|
+
? (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 ?
|
|
1017
|
+
// 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
|
|
1018
|
+
// 2. If style is 'a.0.b', transform 'Key' to `${Key}` | Key
|
|
1019
|
+
TranformedKey | (
|
|
1020
|
+
// Recursively generate paths for the current key
|
|
1021
|
+
GreaterThan<MaxDepth, 0> extends true // Limit the depth to prevent infinite recursion
|
|
1022
|
+
? _Paths<T[Key], {
|
|
1023
|
+
bracketNotation: Options["bracketNotation"];
|
|
1024
|
+
maxRecursionDepth: Subtract<MaxDepth, 1>;
|
|
1025
|
+
}> 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.
|
|
1026
|
+
: `${TranformedKey}.${SubPath}` : never) | (Options["bracketNotation"] extends false ? `${TranformedKey}.${SubPath}` : never) : never : never : never) : never : never;
|
|
1027
|
+
}[keyof T & (T extends UnknownArray ? number : unknown)] : never : never;
|
|
1222
1028
|
export type LiteralStringUnion<T> = LiteralUnion<T, string>;
|
|
1223
1029
|
/**
|
|
1224
1030
|
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.
|
|
@@ -1249,9 +1055,7 @@ const pet: Pet2 = '';
|
|
|
1249
1055
|
|
|
1250
1056
|
@category Type
|
|
1251
1057
|
*/
|
|
1252
|
-
export type LiteralUnion<LiteralType, BaseType extends Primitive> =
|
|
1253
|
-
| LiteralType
|
|
1254
|
-
| (BaseType & Record<never, never>);
|
|
1058
|
+
export type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
|
|
1255
1059
|
/**
|
|
1256
1060
|
Get keys of the given type as strings.
|
|
1257
1061
|
|
|
@@ -1276,8 +1080,7 @@ type StringKeysOfFoo = StringKeyOf<Foo>;
|
|
|
1276
1080
|
|
|
1277
1081
|
@category Object
|
|
1278
1082
|
*/
|
|
1279
|
-
export type StringKeyOf<BaseType> =
|
|
1280
|
-
`${Extract<keyof BaseType, string | number>}`;
|
|
1083
|
+
export type StringKeyOf<BaseType> = `${Extract<keyof BaseType, string | number>}`;
|
|
1281
1084
|
/**
|
|
1282
1085
|
Represents an array of strings split using a given character or character set.
|
|
1283
1086
|
|
|
@@ -1299,14 +1102,13 @@ array = split(items, ',');
|
|
|
1299
1102
|
@category String
|
|
1300
1103
|
@category Template literal
|
|
1301
1104
|
*/
|
|
1302
|
-
export type Split<
|
|
1303
|
-
|
|
1304
|
-
Delimiter
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
: [S];
|
|
1105
|
+
export type Split<S extends string, Delimiter extends string> = S extends `${infer Head}${Delimiter}${infer Tail}` ? [
|
|
1106
|
+
Head,
|
|
1107
|
+
...Split<Tail, Delimiter>
|
|
1108
|
+
] : S extends Delimiter ? [
|
|
1109
|
+
] : [
|
|
1110
|
+
S
|
|
1111
|
+
];
|
|
1310
1112
|
export type GetOptions = {
|
|
1311
1113
|
/**
|
|
1312
1114
|
Include `undefined` in the return type when accessing properties.
|
|
@@ -1320,41 +1122,24 @@ export type GetOptions = {
|
|
|
1320
1122
|
/**
|
|
1321
1123
|
Like the `Get` type but receives an array of strings as a path parameter.
|
|
1322
1124
|
*/
|
|
1323
|
-
export type GetWithPath<
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
? BaseType
|
|
1329
|
-
: Keys extends readonly [infer Head, ...infer Tail]
|
|
1330
|
-
? GetWithPath<
|
|
1331
|
-
PropertyOf<BaseType, Extract<Head, string>, Options>,
|
|
1332
|
-
Extract<Tail, string[]>,
|
|
1333
|
-
Options
|
|
1334
|
-
>
|
|
1335
|
-
: never;
|
|
1125
|
+
export type GetWithPath<BaseType, Keys, Options extends GetOptions = {}> = Keys extends readonly [
|
|
1126
|
+
] ? BaseType : Keys extends readonly [
|
|
1127
|
+
infer Head,
|
|
1128
|
+
...infer Tail
|
|
1129
|
+
] ? GetWithPath<PropertyOf<BaseType, Extract<Head, string>, Options>, Extract<Tail, string[]>, Options> : never;
|
|
1336
1130
|
/**
|
|
1337
1131
|
Adds `undefined` to `Type` if `strict` is enabled.
|
|
1338
1132
|
*/
|
|
1339
|
-
export type Strictify<
|
|
1340
|
-
Type,
|
|
1341
|
-
Options extends GetOptions,
|
|
1342
|
-
> = Options['strict'] extends false ? Type : Type | undefined;
|
|
1133
|
+
export type Strictify<Type, Options extends GetOptions> = Options["strict"] extends false ? Type : (Type | undefined);
|
|
1343
1134
|
/**
|
|
1344
1135
|
If `Options['strict']` is `true`, includes `undefined` in the returned type when accessing properties on `Record<string, any>`.
|
|
1345
1136
|
|
|
1346
1137
|
Known limitations:
|
|
1347
1138
|
- Does not include `undefined` in the type on object types with an index signature (for example, `{a: string; [key: string]: string}`).
|
|
1348
1139
|
*/
|
|
1349
|
-
export type StrictPropertyOf<
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
Options extends GetOptions,
|
|
1353
|
-
> = Record<string, any> extends BaseType
|
|
1354
|
-
? string extends keyof BaseType
|
|
1355
|
-
? Strictify<BaseType[Key], Options> // Record<string, any>
|
|
1356
|
-
: BaseType[Key] // Record<'a' | 'b', any> (Records with a string union as keys have required properties)
|
|
1357
|
-
: BaseType[Key];
|
|
1140
|
+
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>
|
|
1141
|
+
: BaseType[Key] // Record<'a' | 'b', any> (Records with a string union as keys have required properties)
|
|
1142
|
+
: BaseType[Key];
|
|
1358
1143
|
/**
|
|
1359
1144
|
Splits a dot-prop style path into a tuple comprised of the properties in the path. Handles square-bracket notation.
|
|
1360
1145
|
|
|
@@ -1367,18 +1152,11 @@ ToPath<'foo[0].bar.baz'>
|
|
|
1367
1152
|
//=> ['foo', '0', 'bar', 'baz']
|
|
1368
1153
|
```
|
|
1369
1154
|
*/
|
|
1370
|
-
export type ToPath<S extends string> = Split<FixPathSquareBrackets<S>,
|
|
1155
|
+
export type ToPath<S extends string> = Split<FixPathSquareBrackets<S>, ".">;
|
|
1371
1156
|
/**
|
|
1372
1157
|
Replaces square-bracketed dot notation with dots, for example, `foo[0].bar` -> `foo.0.bar`.
|
|
1373
1158
|
*/
|
|
1374
|
-
export type FixPathSquareBrackets<Path extends string> =
|
|
1375
|
-
Path extends `[${infer Head}]${infer Tail}`
|
|
1376
|
-
? Tail extends `[${string}`
|
|
1377
|
-
? `${Head}.${FixPathSquareBrackets<Tail>}`
|
|
1378
|
-
: `${Head}${FixPathSquareBrackets<Tail>}`
|
|
1379
|
-
: Path extends `${infer Head}[${infer Middle}]${infer Tail}`
|
|
1380
|
-
? `${Head}.${FixPathSquareBrackets<`[${Middle}]${Tail}`>}`
|
|
1381
|
-
: Path;
|
|
1159
|
+
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;
|
|
1382
1160
|
/**
|
|
1383
1161
|
Returns true if `LongString` is made up out of `Substring` repeated 0 or more times.
|
|
1384
1162
|
|
|
@@ -1390,14 +1168,7 @@ ConsistsOnlyOf<'aBa', 'a'> //=> false
|
|
|
1390
1168
|
ConsistsOnlyOf<'', 'a'> //=> true
|
|
1391
1169
|
```
|
|
1392
1170
|
*/
|
|
1393
|
-
export type ConsistsOnlyOf<
|
|
1394
|
-
LongString extends string,
|
|
1395
|
-
Substring extends string,
|
|
1396
|
-
> = LongString extends ''
|
|
1397
|
-
? true
|
|
1398
|
-
: LongString extends `${Substring}${infer Tail}`
|
|
1399
|
-
? ConsistsOnlyOf<Tail, Substring>
|
|
1400
|
-
: false;
|
|
1171
|
+
export type ConsistsOnlyOf<LongString extends string, Substring extends string> = LongString extends "" ? true : LongString extends `${Substring}${infer Tail}` ? ConsistsOnlyOf<Tail, Substring> : false;
|
|
1401
1172
|
/**
|
|
1402
1173
|
Convert a type which may have number keys to one with string keys, making it possible to index using strings retrieved from template types.
|
|
1403
1174
|
|
|
@@ -1418,11 +1189,11 @@ export type WithStringKeys<BaseType> = {
|
|
|
1418
1189
|
/**
|
|
1419
1190
|
Perform a `T[U]` operation if `T` supports indexing.
|
|
1420
1191
|
*/
|
|
1421
|
-
export type UncheckedIndex<T, U extends string | number> = [
|
|
1422
|
-
|
|
1423
|
-
]
|
|
1424
|
-
|
|
1425
|
-
|
|
1192
|
+
export type UncheckedIndex<T, U extends string | number> = [
|
|
1193
|
+
T
|
|
1194
|
+
] extends [
|
|
1195
|
+
Record<string | number, any>
|
|
1196
|
+
] ? T[U] : never;
|
|
1426
1197
|
/**
|
|
1427
1198
|
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.
|
|
1428
1199
|
|
|
@@ -1430,26 +1201,15 @@ Note:
|
|
|
1430
1201
|
- 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.
|
|
1431
1202
|
- Returns `undefined` from nullish values, to match the behaviour of most deep-key libraries like `lodash`, `dot-prop`, etc.
|
|
1432
1203
|
*/
|
|
1433
|
-
export type PropertyOf<
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
:
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
? unknown // It's a tuple, but `Key` did not extend `keyof BaseType`. So the index is out of bounds.
|
|
1443
|
-
: BaseType extends {
|
|
1444
|
-
[n: number]: infer Item;
|
|
1445
|
-
length: number; // Note: This is needed to avoid being too lax with records types using number keys like `{0: string; 1: boolean}`.
|
|
1446
|
-
}
|
|
1447
|
-
? ConsistsOnlyOf<Key, StringDigit> extends true
|
|
1448
|
-
? Strictify<Item, Options>
|
|
1449
|
-
: unknown
|
|
1450
|
-
: Key extends keyof WithStringKeys<BaseType>
|
|
1451
|
-
? StrictPropertyOf<WithStringKeys<BaseType>, Key, Options>
|
|
1452
|
-
: unknown;
|
|
1204
|
+
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 [
|
|
1205
|
+
] | readonly [
|
|
1206
|
+
unknown,
|
|
1207
|
+
...unknown[]
|
|
1208
|
+
] ? unknown // It's a tuple, but `Key` did not extend `keyof BaseType`. So the index is out of bounds.
|
|
1209
|
+
: BaseType extends {
|
|
1210
|
+
[n: number]: infer Item;
|
|
1211
|
+
length: number; // Note: This is needed to avoid being too lax with records types using number keys like `{0: string; 1: boolean}`.
|
|
1212
|
+
} ? (ConsistsOnlyOf<Key, StringDigit> extends true ? Strictify<Item, Options> : unknown) : Key extends keyof WithStringKeys<BaseType> ? StrictPropertyOf<WithStringKeys<BaseType>, Key, Options> : unknown;
|
|
1453
1213
|
// 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.
|
|
1454
1214
|
/**
|
|
1455
1215
|
Get a deeply-nested property from an object using a key path, like Lodash's `.get()` function.
|
|
@@ -1497,40 +1257,18 @@ Get<Record<string, string>, 'foo', {strict: true}> // => string
|
|
|
1497
1257
|
@category Array
|
|
1498
1258
|
@category Template literal
|
|
1499
1259
|
*/
|
|
1500
|
-
export type Get<
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
ToString<
|
|
1506
|
-
| Paths<
|
|
1507
|
-
BaseType,
|
|
1508
|
-
{
|
|
1509
|
-
bracketNotation: false;
|
|
1510
|
-
}
|
|
1511
|
-
>
|
|
1512
|
-
| Paths<
|
|
1513
|
-
BaseType,
|
|
1514
|
-
{
|
|
1515
|
-
bracketNotation: true;
|
|
1516
|
-
}
|
|
1517
|
-
>
|
|
1518
|
-
>
|
|
1519
|
-
>,
|
|
1520
|
-
Options extends GetOptions = {},
|
|
1521
|
-
> = GetWithPath<BaseType, Path extends string ? ToPath<Path> : Path, Options>;
|
|
1260
|
+
export type Get<BaseType, Path extends readonly string[] | LiteralStringUnion<ToString<Paths<BaseType, {
|
|
1261
|
+
bracketNotation: false;
|
|
1262
|
+
}> | Paths<BaseType, {
|
|
1263
|
+
bracketNotation: true;
|
|
1264
|
+
}>>>, Options extends GetOptions = {}> = GetWithPath<BaseType, Path extends string ? ToPath<Path> : Path, Options>;
|
|
1522
1265
|
export type ArrayOrPlainObject = UnknownArray | UnknownRecord;
|
|
1523
1266
|
export type EventPosition = {
|
|
1524
1267
|
x: number;
|
|
1525
1268
|
y: number;
|
|
1526
1269
|
};
|
|
1527
|
-
export type KeyedValue<
|
|
1528
|
-
|
|
1529
|
-
Key extends keyof Item,
|
|
1530
|
-
> = Item[Key] extends PropertyKey ? Item[Key] : never;
|
|
1531
|
-
export type NestedArrayType<Value> = Value extends Array<infer NestedValue>
|
|
1532
|
-
? NestedArrayType<NestedValue>
|
|
1533
|
-
: Value;
|
|
1270
|
+
export type KeyedValue<Item, Key extends keyof Item> = Item[Key] extends PropertyKey ? Item[Key] : never;
|
|
1271
|
+
export type NestedArrayType<Value> = Value extends Array<infer NestedValue> ? NestedArrayType<NestedValue> : Value;
|
|
1534
1272
|
export type GenericCallback = (...args: any[]) => any;
|
|
1535
1273
|
export type Key = number | string;
|
|
1536
1274
|
export type PlainObject = UnknownRecord;
|
|
@@ -1546,21 +1284,12 @@ export declare function toQuery(parameters: PlainObject): string;
|
|
|
1546
1284
|
/**
|
|
1547
1285
|
* Is the number between a minimum and maximum value?
|
|
1548
1286
|
*/
|
|
1549
|
-
export declare function between(
|
|
1550
|
-
value: number,
|
|
1551
|
-
min: number,
|
|
1552
|
-
max: number,
|
|
1553
|
-
): boolean;
|
|
1287
|
+
export declare function between(value: number, min: number, max: number): boolean;
|
|
1554
1288
|
/**
|
|
1555
1289
|
* - Clamp a number between a minimum and maximum value
|
|
1556
1290
|
* - If `loop` is `true`, when the value is less than the minimum, it will be clamped as the maximum, and vice versa
|
|
1557
1291
|
*/
|
|
1558
|
-
export declare function clamp(
|
|
1559
|
-
value: number,
|
|
1560
|
-
min: number,
|
|
1561
|
-
max: number,
|
|
1562
|
-
loop?: boolean,
|
|
1563
|
-
): number;
|
|
1292
|
+
export declare function clamp(value: number, min: number, max: number, loop?: boolean): number;
|
|
1564
1293
|
/**
|
|
1565
1294
|
* - Get the number value from an unknown value
|
|
1566
1295
|
* - Returns `NaN` if the value is `undefined`, `null`, or cannot be parsed
|
|
@@ -1600,7 +1329,7 @@ declare class Logger {
|
|
|
1600
1329
|
*/
|
|
1601
1330
|
get dir(): {
|
|
1602
1331
|
(item?: any, options?: any): void;
|
|
1603
|
-
(obj: any, options?: import(
|
|
1332
|
+
(obj: any, options?: import("util").InspectOptions): void;
|
|
1604
1333
|
};
|
|
1605
1334
|
/**
|
|
1606
1335
|
* Is logging to the console enabled? _(defaults to `true`)_
|
|
@@ -1676,9 +1405,7 @@ export declare const logger: Logger;
|
|
|
1676
1405
|
/**
|
|
1677
1406
|
* Is the value an array or a record?
|
|
1678
1407
|
*/
|
|
1679
|
-
export declare function isArrayOrPlainObject(
|
|
1680
|
-
value: unknown,
|
|
1681
|
-
): value is ArrayOrPlainObject;
|
|
1408
|
+
export declare function isArrayOrPlainObject(value: unknown): value is ArrayOrPlainObject;
|
|
1682
1409
|
/**
|
|
1683
1410
|
* Is the array or object completely empty or only containing `null` or `undefined` values?
|
|
1684
1411
|
*/
|
|
@@ -1694,15 +1421,11 @@ export declare function isNullable(value: unknown): value is undefined | null;
|
|
|
1694
1421
|
/**
|
|
1695
1422
|
* Is the value undefined, null, or an empty string?
|
|
1696
1423
|
*/
|
|
1697
|
-
export declare function isNullableOrEmpty(
|
|
1698
|
-
value: unknown,
|
|
1699
|
-
): value is undefined | null | '';
|
|
1424
|
+
export declare function isNullableOrEmpty(value: unknown): value is undefined | null | "";
|
|
1700
1425
|
/**
|
|
1701
1426
|
* Is the value undefined, null, or a whitespace-only string?
|
|
1702
1427
|
*/
|
|
1703
|
-
export declare function isNullableOrWhitespace(
|
|
1704
|
-
value: unknown,
|
|
1705
|
-
): value is undefined | null | '';
|
|
1428
|
+
export declare function isNullableOrWhitespace(value: unknown): value is undefined | null | "";
|
|
1706
1429
|
/**
|
|
1707
1430
|
* Is the value a number?
|
|
1708
1431
|
*/
|
|
@@ -1710,9 +1433,7 @@ export declare function isNumber(value: unknown): value is number;
|
|
|
1710
1433
|
/**
|
|
1711
1434
|
* Is the value a number, or a number-like string?
|
|
1712
1435
|
*/
|
|
1713
|
-
export declare function isNumerical(
|
|
1714
|
-
value: unknown,
|
|
1715
|
-
): value is number | `${number}`;
|
|
1436
|
+
export declare function isNumerical(value: unknown): value is number | `${number}`;
|
|
1716
1437
|
/**
|
|
1717
1438
|
* Is the value an object?
|
|
1718
1439
|
*/
|
|
@@ -1732,29 +1453,11 @@ export declare function chunk<Item>(array: Item[], size?: number): Item[][];
|
|
|
1732
1453
|
/**
|
|
1733
1454
|
* Compact an array _(removing all `null` and `undefined` values)_
|
|
1734
1455
|
*/
|
|
1735
|
-
export declare function compact<Item>(
|
|
1736
|
-
array: Item[],
|
|
1737
|
-
): Exclude<Item, null | undefined>[];
|
|
1456
|
+
export declare function compact<Item>(array: Item[]): Exclude<Item, null | undefined>[];
|
|
1738
1457
|
/**
|
|
1739
1458
|
* Compact an array _(removing all falsey values)_
|
|
1740
1459
|
*/
|
|
1741
|
-
export declare function compact<Item>(
|
|
1742
|
-
array: Item[],
|
|
1743
|
-
strict: true,
|
|
1744
|
-
): Exclude<Item, 0 | '' | false | null | undefined>[];
|
|
1745
|
-
export type ArrayCallback<Item, Value> = (
|
|
1746
|
-
item: Item,
|
|
1747
|
-
index: number,
|
|
1748
|
-
array: Item[],
|
|
1749
|
-
) => Value;
|
|
1750
|
-
export type BooleanCallback<Item> = ArrayCallback<Item, boolean>;
|
|
1751
|
-
export type KeyCallback<Item> = ArrayCallback<Item, Key>;
|
|
1752
|
-
export type SortKey<Item> = {
|
|
1753
|
-
direction: 'asc' | 'desc';
|
|
1754
|
-
value: Key | SortKeyCallback<Item>;
|
|
1755
|
-
};
|
|
1756
|
-
export type SortKeyCallback<Item> = (item: Item) => unknown;
|
|
1757
|
-
export type ValueCallback<Item> = ArrayCallback<Item, unknown>;
|
|
1460
|
+
export declare function compact<Item>(array: Item[], strict: true): Exclude<Item, 0 | "" | false | null | undefined>[];
|
|
1758
1461
|
/**
|
|
1759
1462
|
* Get the number of items _(count)_ that match the given value
|
|
1760
1463
|
*/
|
|
@@ -1762,26 +1465,15 @@ export declare function count<Item>(array: Item[], value: Item): number;
|
|
|
1762
1465
|
/**
|
|
1763
1466
|
* Get the number of items _(count)_ that match the given value
|
|
1764
1467
|
*/
|
|
1765
|
-
export declare function count<Item>(
|
|
1766
|
-
array: Item[],
|
|
1767
|
-
matches: BooleanCallback<Item>,
|
|
1768
|
-
): number;
|
|
1468
|
+
export declare function count<Item>(array: Item[], matches: (item: Item, index: number, array: Item[]) => boolean): number;
|
|
1769
1469
|
/**
|
|
1770
1470
|
* Get the number of items _(count)_ that match the given value
|
|
1771
1471
|
*/
|
|
1772
|
-
export declare function count<Item, Key extends keyof Item>(
|
|
1773
|
-
array: Item[],
|
|
1774
|
-
key: Key,
|
|
1775
|
-
value: Item[Key],
|
|
1776
|
-
): number;
|
|
1472
|
+
export declare function count<Item, Key extends keyof Item>(array: Item[], key: Key, value: Item[Key]): number;
|
|
1777
1473
|
/**
|
|
1778
1474
|
* Get the number of items _(count)_ that match the given value
|
|
1779
1475
|
*/
|
|
1780
|
-
export declare function count<Item, Key extends
|
|
1781
|
-
array: Item[],
|
|
1782
|
-
key: Key,
|
|
1783
|
-
value: ReturnType<Key>,
|
|
1784
|
-
): number;
|
|
1476
|
+
export declare function count<Item, Key extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: Key, value: ReturnType<Key>): number;
|
|
1785
1477
|
/**
|
|
1786
1478
|
* Does the value exist in array?
|
|
1787
1479
|
*/
|
|
@@ -1789,28 +1481,17 @@ export declare function exists<Item>(array: Item[], value: Item): boolean;
|
|
|
1789
1481
|
/**
|
|
1790
1482
|
* Does the value exist in array?
|
|
1791
1483
|
*/
|
|
1792
|
-
export declare function exists<Item>(
|
|
1793
|
-
array: Item[],
|
|
1794
|
-
matches: BooleanCallback<Item>,
|
|
1795
|
-
): boolean;
|
|
1484
|
+
export declare function exists<Item>(array: Item[], matches: (item: Item, index: number, array: Item[]) => boolean): boolean;
|
|
1796
1485
|
/**
|
|
1797
1486
|
* - Does the value exist in array?
|
|
1798
1487
|
* - Use `key` to find a comparison value to match with `value`
|
|
1799
1488
|
*/
|
|
1800
|
-
export declare function exists<Item, Key extends keyof Item>(
|
|
1801
|
-
array: Item[],
|
|
1802
|
-
key: Key,
|
|
1803
|
-
value: Item[Key],
|
|
1804
|
-
): boolean;
|
|
1489
|
+
export declare function exists<Item, Key extends keyof Item>(array: Item[], key: Key, value: Item[Key]): boolean;
|
|
1805
1490
|
/**
|
|
1806
1491
|
* - Does the value exist in array?
|
|
1807
1492
|
* - Use `key` to find a comparison value to match with `value`
|
|
1808
1493
|
*/
|
|
1809
|
-
export declare function exists<Item, Key extends
|
|
1810
|
-
array: Item[],
|
|
1811
|
-
key: Key,
|
|
1812
|
-
value: ReturnType<Key>,
|
|
1813
|
-
): boolean;
|
|
1494
|
+
export declare function exists<Item, Key extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: Key, value: ReturnType<Key>): boolean;
|
|
1814
1495
|
/**
|
|
1815
1496
|
* Get a filtered array of items matching `value`
|
|
1816
1497
|
*/
|
|
@@ -1818,190 +1499,83 @@ export declare function filter<Item>(array: Item[], value: Item): Item[];
|
|
|
1818
1499
|
/**
|
|
1819
1500
|
* Get a filtered array of items matching `value`
|
|
1820
1501
|
*/
|
|
1821
|
-
export declare function filter<Item>(
|
|
1822
|
-
array: Item[],
|
|
1823
|
-
matches: BooleanCallback<Item>,
|
|
1824
|
-
): Item[];
|
|
1502
|
+
export declare function filter<Item>(array: Item[], matches: (item: Item, index: number, array: Item[]) => boolean): Item[];
|
|
1825
1503
|
/**
|
|
1826
1504
|
* - Get a filtered array of items
|
|
1827
1505
|
* - Use `key` to find a comparison value to match with `value`
|
|
1828
1506
|
*/
|
|
1829
|
-
export declare function filter<Item, Key extends keyof Item>(
|
|
1830
|
-
array: Item[],
|
|
1831
|
-
key: Key,
|
|
1832
|
-
value: Item[Key],
|
|
1833
|
-
): Item[];
|
|
1507
|
+
export declare function filter<Item, Key extends keyof Item>(array: Item[], key: Key, value: Item[Key]): Item[];
|
|
1834
1508
|
/**
|
|
1835
1509
|
* - Get a filtered array of items
|
|
1836
1510
|
* - Use `key` to find a comparison value to match with `value`
|
|
1837
1511
|
*/
|
|
1838
|
-
export declare function filter<Item, Key extends
|
|
1839
|
-
array: Item[],
|
|
1840
|
-
key: Key,
|
|
1841
|
-
value: ReturnType<Key>,
|
|
1842
|
-
): Item[];
|
|
1512
|
+
export declare function filter<Item, Key extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: Key, value: ReturnType<Key>): Item[];
|
|
1843
1513
|
/**
|
|
1844
1514
|
* Get the first item matching `value` _(or `undefined` if no match is found)_
|
|
1845
1515
|
*/
|
|
1846
|
-
export declare function find<Item>(
|
|
1847
|
-
array: Item[],
|
|
1848
|
-
value: Item,
|
|
1849
|
-
): Item | undefined;
|
|
1516
|
+
export declare function find<Item>(array: Item[], value: Item): Item | undefined;
|
|
1850
1517
|
/**
|
|
1851
1518
|
* Get the first item matching `value` _(or `undefined` if no match is found)_
|
|
1852
1519
|
*/
|
|
1853
|
-
export declare function find<Item>(
|
|
1854
|
-
array: Item[],
|
|
1855
|
-
matches: BooleanCallback<Item>,
|
|
1856
|
-
): Item | undefined;
|
|
1520
|
+
export declare function find<Item>(array: Item[], matches: (item: Item, index: number, array: Item[]) => boolean): Item | undefined;
|
|
1857
1521
|
/**
|
|
1858
1522
|
* - Get the first matching item _(or `undefined` if no match is found)_
|
|
1859
1523
|
* - Use `key` to find a comparison value to match with `value`
|
|
1860
1524
|
*/
|
|
1861
|
-
export declare function find<Item, Key extends keyof Item>(
|
|
1862
|
-
array: Item[],
|
|
1863
|
-
key: Key,
|
|
1864
|
-
value: Item[Key],
|
|
1865
|
-
): Item | undefined;
|
|
1525
|
+
export declare function find<Item, Key extends keyof Item>(array: Item[], key: Key, value: Item[Key]): Item | undefined;
|
|
1866
1526
|
/**
|
|
1867
1527
|
* - Get the first matching item _(or `undefined` if no match is found)_
|
|
1868
1528
|
* - Use `key` to find a comparison value to match with `value`
|
|
1869
1529
|
*/
|
|
1870
|
-
export declare function find<Item, Key extends
|
|
1871
|
-
array: Item[],
|
|
1872
|
-
key: Key,
|
|
1873
|
-
value: ReturnType<Key>,
|
|
1874
|
-
): Item | undefined;
|
|
1530
|
+
export declare function find<Item, Key extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: Key, value: ReturnType<Key>): Item | undefined;
|
|
1875
1531
|
/**
|
|
1876
1532
|
* Create a record from an array of items using a specific key
|
|
1877
1533
|
*/
|
|
1878
|
-
export declare function groupBy<Item, Key extends keyof Item>(
|
|
1879
|
-
array: Item[],
|
|
1880
|
-
key: Key,
|
|
1881
|
-
): Record<KeyedValue<Item, Key>, Item>;
|
|
1534
|
+
export declare function groupBy<Item, Key extends keyof Item>(array: Item[], key: Key): Record<KeyedValue<Item, Key>, Item>;
|
|
1882
1535
|
/**
|
|
1883
1536
|
* Create a record from an array of items using a specific key, and grouping them into arrays
|
|
1884
1537
|
*/
|
|
1885
|
-
export declare function groupBy<Item, Key extends keyof Item>(
|
|
1886
|
-
array: Item[],
|
|
1887
|
-
key: Key,
|
|
1888
|
-
arrays: true,
|
|
1889
|
-
): Record<KeyedValue<Item, Key>, Item[]>;
|
|
1538
|
+
export declare function groupBy<Item, Key extends keyof Item>(array: Item[], key: Key, arrays: true): Record<KeyedValue<Item, Key>, Item[]>;
|
|
1890
1539
|
/**
|
|
1891
1540
|
* Create a record from an array of items using a specific key
|
|
1892
1541
|
*/
|
|
1893
|
-
export declare function groupBy<Item, Key extends
|
|
1894
|
-
array: Item[],
|
|
1895
|
-
key: Key,
|
|
1896
|
-
): Record<ReturnType<Key>, Item>;
|
|
1542
|
+
export declare function groupBy<Item, Key extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: Key): Record<ReturnType<Key>, Item>;
|
|
1897
1543
|
/**
|
|
1898
1544
|
* Create a record from an array of items using a specific key, and grouping them into arrays
|
|
1899
1545
|
*/
|
|
1900
|
-
export declare function groupBy<Item, Key extends
|
|
1901
|
-
array: Item[],
|
|
1902
|
-
key: Key,
|
|
1903
|
-
arrays: true,
|
|
1904
|
-
): Record<ReturnType<Key>, Item[]>;
|
|
1546
|
+
export declare function groupBy<Item, Key extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: Key, arrays: true): Record<ReturnType<Key>, Item[]>;
|
|
1905
1547
|
/**
|
|
1906
1548
|
* Create a record from an array of items using a specific key and value
|
|
1907
1549
|
*/
|
|
1908
|
-
export declare function groupBy<
|
|
1909
|
-
Item,
|
|
1910
|
-
Key extends keyof Item,
|
|
1911
|
-
Value extends keyof Item,
|
|
1912
|
-
>(
|
|
1913
|
-
array: Item[],
|
|
1914
|
-
key: Key,
|
|
1915
|
-
value: Value,
|
|
1916
|
-
): Record<KeyedValue<Item, Key>, KeyedValue<Item, Value>>;
|
|
1550
|
+
export declare function groupBy<Item, Key extends keyof Item, Value extends keyof Item>(array: Item[], key: Key, value: Value): Record<KeyedValue<Item, Key>, KeyedValue<Item, Value>>;
|
|
1917
1551
|
/**
|
|
1918
1552
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
1919
1553
|
*/
|
|
1920
|
-
export declare function groupBy<
|
|
1921
|
-
Item,
|
|
1922
|
-
Key extends keyof Item,
|
|
1923
|
-
Value extends keyof Item,
|
|
1924
|
-
>(
|
|
1925
|
-
array: Item[],
|
|
1926
|
-
key: Key,
|
|
1927
|
-
value: Value,
|
|
1928
|
-
arrays: true,
|
|
1929
|
-
): Record<KeyedValue<Item, Key>, Array<KeyedValue<Item, Value>>>;
|
|
1554
|
+
export declare function groupBy<Item, Key extends keyof Item, Value extends keyof Item>(array: Item[], key: Key, value: Value, arrays: true): Record<KeyedValue<Item, Key>, Array<KeyedValue<Item, Value>>>;
|
|
1930
1555
|
/**
|
|
1931
1556
|
* Create a record from an array of items using a specific key and value
|
|
1932
1557
|
*/
|
|
1933
|
-
export declare function groupBy<
|
|
1934
|
-
Item,
|
|
1935
|
-
Key extends keyof Item,
|
|
1936
|
-
Value extends ValueCallback<Item>,
|
|
1937
|
-
>(
|
|
1938
|
-
array: Item[],
|
|
1939
|
-
key: Key,
|
|
1940
|
-
value: Value,
|
|
1941
|
-
): Record<KeyedValue<Item, Key>, ReturnType<Value>>;
|
|
1558
|
+
export declare function groupBy<Item, Key extends keyof Item, Value extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: Key, value: Value): Record<KeyedValue<Item, Key>, ReturnType<Value>>;
|
|
1942
1559
|
/**
|
|
1943
1560
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
1944
1561
|
*/
|
|
1945
|
-
export declare function groupBy<
|
|
1946
|
-
Item,
|
|
1947
|
-
Key extends keyof Item,
|
|
1948
|
-
Value extends ValueCallback<Item>,
|
|
1949
|
-
>(
|
|
1950
|
-
array: Item[],
|
|
1951
|
-
key: Key,
|
|
1952
|
-
value: Value,
|
|
1953
|
-
arrays: true,
|
|
1954
|
-
): Record<KeyedValue<Item, Key>, Array<ReturnType<Value>>>;
|
|
1562
|
+
export declare function groupBy<Item, Key extends keyof Item, Value extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: Key, value: Value, arrays: true): Record<KeyedValue<Item, Key>, Array<ReturnType<Value>>>;
|
|
1955
1563
|
/**
|
|
1956
1564
|
* Create a record from an array of items using a specific key and value
|
|
1957
1565
|
*/
|
|
1958
|
-
export declare function groupBy<
|
|
1959
|
-
Item,
|
|
1960
|
-
Key extends KeyCallback<Item>,
|
|
1961
|
-
Value extends keyof Item,
|
|
1962
|
-
>(
|
|
1963
|
-
array: Item[],
|
|
1964
|
-
key: Key,
|
|
1965
|
-
value: Value,
|
|
1966
|
-
): Record<ReturnType<Key>, KeyedValue<Item, Value>>;
|
|
1566
|
+
export declare function groupBy<Item, Key extends (item: Item, index: number, array: Item[]) => Key, Value extends keyof Item>(array: Item[], key: Key, value: Value): Record<ReturnType<Key>, KeyedValue<Item, Value>>;
|
|
1967
1567
|
/**
|
|
1968
1568
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
1969
1569
|
*/
|
|
1970
|
-
export declare function groupBy<
|
|
1971
|
-
Item,
|
|
1972
|
-
Key extends KeyCallback<Item>,
|
|
1973
|
-
Value extends keyof Item,
|
|
1974
|
-
>(
|
|
1975
|
-
array: Item[],
|
|
1976
|
-
key: Key,
|
|
1977
|
-
value: Value,
|
|
1978
|
-
arrays: true,
|
|
1979
|
-
): Record<ReturnType<Key>, Array<KeyedValue<Item, Value>>>;
|
|
1570
|
+
export declare function groupBy<Item, Key extends (item: Item, index: number, array: Item[]) => Key, Value extends keyof Item>(array: Item[], key: Key, value: Value, arrays: true): Record<ReturnType<Key>, Array<KeyedValue<Item, Value>>>;
|
|
1980
1571
|
/**
|
|
1981
1572
|
* Create a record from an array of items using a specific key and value
|
|
1982
1573
|
*/
|
|
1983
|
-
export declare function groupBy<
|
|
1984
|
-
Item,
|
|
1985
|
-
Key extends KeyCallback<Item>,
|
|
1986
|
-
Value extends ValueCallback<Item>,
|
|
1987
|
-
>(
|
|
1988
|
-
array: Item[],
|
|
1989
|
-
key: Key,
|
|
1990
|
-
value: Value,
|
|
1991
|
-
): Record<ReturnType<Key>, ReturnType<Value>>;
|
|
1574
|
+
export declare function groupBy<Item, Key extends (item: Item, index: number, array: Item[]) => Key, Value extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: Key, value: Value): Record<ReturnType<Key>, ReturnType<Value>>;
|
|
1992
1575
|
/**
|
|
1993
1576
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
1994
1577
|
*/
|
|
1995
|
-
export declare function groupBy<
|
|
1996
|
-
Item,
|
|
1997
|
-
Key extends KeyCallback<Item>,
|
|
1998
|
-
Value extends ValueCallback<Item>,
|
|
1999
|
-
>(
|
|
2000
|
-
array: Item[],
|
|
2001
|
-
key: Key,
|
|
2002
|
-
value: Value,
|
|
2003
|
-
arrays: true,
|
|
2004
|
-
): Record<ReturnType<Key>, Array<ReturnType<Value>>>;
|
|
1578
|
+
export declare function groupBy<Item, Key extends (item: Item, index: number, array: Item[]) => Key, Value extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: Key, value: Value, arrays: true): Record<ReturnType<Key>, Array<ReturnType<Value>>>;
|
|
2005
1579
|
/**
|
|
2006
1580
|
* Get the index for the first item matching `value` _(or `-1` if no match is found)_
|
|
2007
1581
|
*/
|
|
@@ -2009,28 +1583,21 @@ export declare function indexOf<Item>(array: Item[], value: Item): number;
|
|
|
2009
1583
|
/**
|
|
2010
1584
|
* Get the index for the first item matching `value` _(or `-1` if no match is found)_
|
|
2011
1585
|
*/
|
|
2012
|
-
export declare function indexOf<Item>(
|
|
2013
|
-
array: Item[],
|
|
2014
|
-
matches: BooleanCallback<Item>,
|
|
2015
|
-
): number;
|
|
1586
|
+
export declare function indexOf<Item>(array: Item[], matches: (item: Item, index: number, array: Item[]) => boolean): number;
|
|
2016
1587
|
/**
|
|
2017
1588
|
* - Get the index for the first matching item _(or `-1` if no match is found)_
|
|
2018
1589
|
* - Use `key` to find a comparison value to match with `value`
|
|
2019
1590
|
*/
|
|
2020
|
-
export declare function indexOf<Item, Key extends keyof Item>(
|
|
2021
|
-
array: Item[],
|
|
2022
|
-
key: Key,
|
|
2023
|
-
value: Item[Key],
|
|
2024
|
-
): number;
|
|
1591
|
+
export declare function indexOf<Item, Key extends keyof Item>(array: Item[], key: Key, value: Item[Key]): number;
|
|
2025
1592
|
/**
|
|
2026
1593
|
* - Get the index for the first matching item _(or `-1` if no match is found)_
|
|
2027
1594
|
* - Use `key` to find a comparison value to match with `value`
|
|
2028
1595
|
*/
|
|
2029
|
-
export declare function indexOf<Item, Key extends
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
value:
|
|
2033
|
-
|
|
1596
|
+
export declare function indexOf<Item, Key extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: Key, value: ReturnType<Key>): number;
|
|
1597
|
+
export type SortKey<Item> = {
|
|
1598
|
+
direction: "asc" | "desc";
|
|
1599
|
+
value: Key | ((item: Item) => Key);
|
|
1600
|
+
};
|
|
2034
1601
|
/**
|
|
2035
1602
|
* - Insert values into an array _(at the end)_
|
|
2036
1603
|
* - _(Uses chunking to avoid stack overflow_)
|
|
@@ -2040,11 +1607,7 @@ export declare function insert<Item>(array: Item[], items: Item[]): void;
|
|
|
2040
1607
|
* - Insert values into an array at a specified index
|
|
2041
1608
|
* - _(Uses chunking to avoid stack overflow_)
|
|
2042
1609
|
*/
|
|
2043
|
-
export declare function insert<Item>(
|
|
2044
|
-
array: Item[],
|
|
2045
|
-
index: number,
|
|
2046
|
-
items: Item[],
|
|
2047
|
-
): void;
|
|
1610
|
+
export declare function insert<Item>(array: Item[], index: number, items: Item[]): void;
|
|
2048
1611
|
/**
|
|
2049
1612
|
* Shuffle an array
|
|
2050
1613
|
*/
|
|
@@ -2057,20 +1620,12 @@ export declare function sort<Item>(array: Item[], descending?: boolean): Item[];
|
|
|
2057
1620
|
* - Sort an array of items, using a `key` to sort by a specific value
|
|
2058
1621
|
* - Defaults to ascending, but can be changed by setting `descending` to `true`, or using a `SortKey`
|
|
2059
1622
|
*/
|
|
2060
|
-
export declare function sort<Item>(
|
|
2061
|
-
array: Item[],
|
|
2062
|
-
key: Key | SortKey<Item> | SortKeyCallback<Item>,
|
|
2063
|
-
descending?: boolean,
|
|
2064
|
-
): Item[];
|
|
1623
|
+
export declare function sort<Item>(array: Item[], key: Key | SortKey<Item> | ((item: Item) => Key), descending?: boolean): Item[];
|
|
2065
1624
|
/**
|
|
2066
1625
|
* - Sort an array of items, using multiple `keys` to sort by specific values
|
|
2067
1626
|
* - Defaults to ascending, but can be changed by setting `descending` to `true`, or using `SortKey`
|
|
2068
1627
|
*/
|
|
2069
|
-
export declare function sort<Item>(
|
|
2070
|
-
array: Item[],
|
|
2071
|
-
keys: Array<Key | SortKey<Item> | SortKeyCallback<Item>>,
|
|
2072
|
-
descending?: boolean,
|
|
2073
|
-
): Item[];
|
|
1628
|
+
export declare function sort<Item>(array: Item[], keys: Array<Key | SortKey<Item> | ((item: Item) => Key)>, descending?: boolean): Item[];
|
|
2074
1629
|
/**
|
|
2075
1630
|
* Removes and returns all items from an array starting from a specific index
|
|
2076
1631
|
*/
|
|
@@ -2078,30 +1633,17 @@ export declare function splice<Item>(array: Item[], start: number): Item[];
|
|
|
2078
1633
|
/**
|
|
2079
1634
|
* Removes and returns _(up to)_ a specific amount of items from an array, starting from a specific index
|
|
2080
1635
|
*/
|
|
2081
|
-
export declare function splice<Item>(
|
|
2082
|
-
array: Item[],
|
|
2083
|
-
start: number,
|
|
2084
|
-
amount: number,
|
|
2085
|
-
): Item[];
|
|
1636
|
+
export declare function splice<Item>(array: Item[], start: number, amount: number): Item[];
|
|
2086
1637
|
/**
|
|
2087
1638
|
* - Splices values into an array and returns any removed values
|
|
2088
1639
|
* - Uses chunking to avoid stack overflow
|
|
2089
1640
|
*/
|
|
2090
|
-
export declare function splice<Item>(
|
|
2091
|
-
array: Item[],
|
|
2092
|
-
start: number,
|
|
2093
|
-
added: Item[],
|
|
2094
|
-
): Item[];
|
|
1641
|
+
export declare function splice<Item>(array: Item[], start: number, added: Item[]): Item[];
|
|
2095
1642
|
/**
|
|
2096
1643
|
* - Splices values into an array and returns any removed values
|
|
2097
1644
|
* - Uses chunking to avoid stack overflow
|
|
2098
1645
|
*/
|
|
2099
|
-
export declare function splice<Item>(
|
|
2100
|
-
array: Item[],
|
|
2101
|
-
start: number,
|
|
2102
|
-
amount: number,
|
|
2103
|
-
added: Item[],
|
|
2104
|
-
): Item[];
|
|
1646
|
+
export declare function splice<Item>(array: Item[], start: number, amount: number, added: Item[]): Item[];
|
|
2105
1647
|
/**
|
|
2106
1648
|
* Create a map from an array of items _(using their indices as keys)_
|
|
2107
1649
|
*/
|
|
@@ -2109,133 +1651,51 @@ export declare function toMap<Item>(array: Item[]): Map<number, Item>;
|
|
|
2109
1651
|
/**
|
|
2110
1652
|
* Create a map from an array of items using a specific key
|
|
2111
1653
|
*/
|
|
2112
|
-
export declare function toMap<Item, Key extends keyof Item>(
|
|
2113
|
-
array: Item[],
|
|
2114
|
-
key: Key,
|
|
2115
|
-
): Map<KeyedValue<Item, Key>, Item>;
|
|
1654
|
+
export declare function toMap<Item, Key extends keyof Item>(array: Item[], key: Key): Map<KeyedValue<Item, Key>, Item>;
|
|
2116
1655
|
/**
|
|
2117
1656
|
* Create a map from an array of items using a specific key, and grouping them into arrays
|
|
2118
1657
|
*/
|
|
2119
|
-
export declare function toMap<Item, Key extends keyof Item>(
|
|
2120
|
-
array: Item[],
|
|
2121
|
-
key: Key,
|
|
2122
|
-
arrays: true,
|
|
2123
|
-
): Map<KeyedValue<Item, Key>, Item[]>;
|
|
1658
|
+
export declare function toMap<Item, Key extends keyof Item>(array: Item[], key: Key, arrays: true): Map<KeyedValue<Item, Key>, Item[]>;
|
|
2124
1659
|
/**
|
|
2125
1660
|
* Create a map from an array of items using a specific key
|
|
2126
1661
|
*/
|
|
2127
|
-
export declare function toMap<Item, Key extends
|
|
2128
|
-
array: Item[],
|
|
2129
|
-
key: Key,
|
|
2130
|
-
): Map<ReturnType<Key>, Item>;
|
|
1662
|
+
export declare function toMap<Item, Key extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: Key): Map<ReturnType<Key>, Item>;
|
|
2131
1663
|
/**
|
|
2132
1664
|
* Create a map from an array of items using a specific key, and grouping them into arrays
|
|
2133
1665
|
*/
|
|
2134
|
-
export declare function toMap<Item, Key extends
|
|
2135
|
-
array: Item[],
|
|
2136
|
-
key: Key,
|
|
2137
|
-
arrays: true,
|
|
2138
|
-
): Map<ReturnType<Key>, Item[]>;
|
|
1666
|
+
export declare function toMap<Item, Key extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: Key, arrays: true): Map<ReturnType<Key>, Item[]>;
|
|
2139
1667
|
/**
|
|
2140
1668
|
* Create a map from an array of items using a specific key and value
|
|
2141
1669
|
*/
|
|
2142
|
-
export declare function toMap<
|
|
2143
|
-
Item,
|
|
2144
|
-
Key extends keyof Item,
|
|
2145
|
-
Value extends keyof Item,
|
|
2146
|
-
>(
|
|
2147
|
-
array: Item[],
|
|
2148
|
-
key: Key,
|
|
2149
|
-
value: Value,
|
|
2150
|
-
): Map<KeyedValue<Item, Key>, KeyedValue<Item, Value>>;
|
|
1670
|
+
export declare function toMap<Item, Key extends keyof Item, Value extends keyof Item>(array: Item[], key: Key, value: Value): Map<KeyedValue<Item, Key>, KeyedValue<Item, Value>>;
|
|
2151
1671
|
/**
|
|
2152
1672
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
2153
1673
|
*/
|
|
2154
|
-
export declare function toMap<
|
|
2155
|
-
Item,
|
|
2156
|
-
Key extends keyof Item,
|
|
2157
|
-
Value extends keyof Item,
|
|
2158
|
-
>(
|
|
2159
|
-
array: Item[],
|
|
2160
|
-
key: Key,
|
|
2161
|
-
value: Value,
|
|
2162
|
-
arrays: true,
|
|
2163
|
-
): Map<KeyedValue<Item, Key>, Array<KeyedValue<Item, Value>>>;
|
|
1674
|
+
export declare function toMap<Item, Key extends keyof Item, Value extends keyof Item>(array: Item[], key: Key, value: Value, arrays: true): Map<KeyedValue<Item, Key>, Array<KeyedValue<Item, Value>>>;
|
|
2164
1675
|
/**
|
|
2165
1676
|
* Create a map from an array of items using a specific key and value
|
|
2166
1677
|
*/
|
|
2167
|
-
export declare function toMap<
|
|
2168
|
-
Item,
|
|
2169
|
-
Key extends keyof Item,
|
|
2170
|
-
Value extends ValueCallback<Item>,
|
|
2171
|
-
>(
|
|
2172
|
-
array: Item[],
|
|
2173
|
-
key: Key,
|
|
2174
|
-
value: Value,
|
|
2175
|
-
): Map<KeyedValue<Item, Key>, ReturnType<Value>>;
|
|
1678
|
+
export declare function toMap<Item, Key extends keyof Item, Value extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: Key, value: Value): Map<KeyedValue<Item, Key>, ReturnType<Value>>;
|
|
2176
1679
|
/**
|
|
2177
1680
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
2178
1681
|
*/
|
|
2179
|
-
export declare function toMap<
|
|
2180
|
-
Item,
|
|
2181
|
-
Key extends keyof Item,
|
|
2182
|
-
Value extends ValueCallback<Item>,
|
|
2183
|
-
>(
|
|
2184
|
-
array: Item[],
|
|
2185
|
-
key: Key,
|
|
2186
|
-
value: Value,
|
|
2187
|
-
arrays: true,
|
|
2188
|
-
): Map<KeyedValue<Item, Key>, Array<ReturnType<Value>>>;
|
|
1682
|
+
export declare function toMap<Item, Key extends keyof Item, Value extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: Key, value: Value, arrays: true): Map<KeyedValue<Item, Key>, Array<ReturnType<Value>>>;
|
|
2189
1683
|
/**
|
|
2190
1684
|
* Create a map from an array of items using a specific key and value
|
|
2191
1685
|
*/
|
|
2192
|
-
export declare function toMap<
|
|
2193
|
-
Item,
|
|
2194
|
-
Key extends KeyCallback<Item>,
|
|
2195
|
-
Value extends keyof Item,
|
|
2196
|
-
>(
|
|
2197
|
-
array: Item[],
|
|
2198
|
-
key: Key,
|
|
2199
|
-
value: Value,
|
|
2200
|
-
): Map<ReturnType<Key>, KeyedValue<Item, Value>>;
|
|
1686
|
+
export declare function toMap<Item, Key extends (item: Item, index: number, array: Item[]) => Key, Value extends keyof Item>(array: Item[], key: Key, value: Value): Map<ReturnType<Key>, KeyedValue<Item, Value>>;
|
|
2201
1687
|
/**
|
|
2202
1688
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
2203
1689
|
*/
|
|
2204
|
-
export declare function toMap<
|
|
2205
|
-
Item,
|
|
2206
|
-
Key extends KeyCallback<Item>,
|
|
2207
|
-
Value extends keyof Item,
|
|
2208
|
-
>(
|
|
2209
|
-
array: Item[],
|
|
2210
|
-
key: Key,
|
|
2211
|
-
value: Value,
|
|
2212
|
-
arrays: true,
|
|
2213
|
-
): Map<ReturnType<Key>, Array<KeyedValue<Item, Value>>>;
|
|
1690
|
+
export declare function toMap<Item, Key extends (item: Item, index: number, array: Item[]) => Key, Value extends keyof Item>(array: Item[], key: Key, value: Value, arrays: true): Map<ReturnType<Key>, Array<KeyedValue<Item, Value>>>;
|
|
2214
1691
|
/**
|
|
2215
1692
|
* Create a map from an array of items using a specific key and value
|
|
2216
1693
|
*/
|
|
2217
|
-
export declare function toMap<
|
|
2218
|
-
Item,
|
|
2219
|
-
Key extends KeyCallback<Item>,
|
|
2220
|
-
Value extends ValueCallback<Item>,
|
|
2221
|
-
>(
|
|
2222
|
-
array: Item[],
|
|
2223
|
-
key: Key,
|
|
2224
|
-
value: Value,
|
|
2225
|
-
): Map<ReturnType<Key>, ReturnType<Value>>;
|
|
1694
|
+
export declare function toMap<Item, Key extends (item: Item, index: number, array: Item[]) => Key, Value extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: Key, value: Value): Map<ReturnType<Key>, ReturnType<Value>>;
|
|
2226
1695
|
/**
|
|
2227
1696
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
2228
1697
|
*/
|
|
2229
|
-
export declare function toMap<
|
|
2230
|
-
Item,
|
|
2231
|
-
Key extends KeyCallback<Item>,
|
|
2232
|
-
Value extends ValueCallback<Item>,
|
|
2233
|
-
>(
|
|
2234
|
-
array: Item[],
|
|
2235
|
-
key: Key,
|
|
2236
|
-
value: Value,
|
|
2237
|
-
arrays: true,
|
|
2238
|
-
): Map<ReturnType<Key>, Array<ReturnType<Value>>>;
|
|
1698
|
+
export declare function toMap<Item, Key extends (item: Item, index: number, array: Item[]) => Key, Value extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: Key, value: Value, arrays: true): Map<ReturnType<Key>, Array<ReturnType<Value>>>;
|
|
2239
1699
|
/**
|
|
2240
1700
|
* Create a record from an array of items _(using their indices as keys)_
|
|
2241
1701
|
*/
|
|
@@ -2243,153 +1703,65 @@ export declare function toRecord<Item>(array: Item[]): Record<number, Item>;
|
|
|
2243
1703
|
/**
|
|
2244
1704
|
* Create a record from an array of items using a specific key
|
|
2245
1705
|
*/
|
|
2246
|
-
export declare function toRecord<Item, Key extends keyof Item>(
|
|
2247
|
-
array: Item[],
|
|
2248
|
-
key: Key,
|
|
2249
|
-
): Record<KeyedValue<Item, Key>, Item>;
|
|
1706
|
+
export declare function toRecord<Item, Key extends keyof Item>(array: Item[], key: Key): Record<KeyedValue<Item, Key>, Item>;
|
|
2250
1707
|
/**
|
|
2251
1708
|
* Create a record from an array of items using a specific key, and grouping them into arrays
|
|
2252
1709
|
*/
|
|
2253
|
-
export declare function toRecord<Item, Key extends keyof Item>(
|
|
2254
|
-
array: Item[],
|
|
2255
|
-
key: Key,
|
|
2256
|
-
arrays: true,
|
|
2257
|
-
): Record<KeyedValue<Item, Key>, Item[]>;
|
|
1710
|
+
export declare function toRecord<Item, Key extends keyof Item>(array: Item[], key: Key, arrays: true): Record<KeyedValue<Item, Key>, Item[]>;
|
|
2258
1711
|
/**
|
|
2259
1712
|
* Create a record from an array of items using a specific key
|
|
2260
1713
|
*/
|
|
2261
|
-
export declare function toRecord<Item, Key extends
|
|
2262
|
-
array: Item[],
|
|
2263
|
-
key: Key,
|
|
2264
|
-
): Record<ReturnType<Key>, Item>;
|
|
1714
|
+
export declare function toRecord<Item, Key extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: Key): Record<ReturnType<Key>, Item>;
|
|
2265
1715
|
/**
|
|
2266
1716
|
* Create a record from an array of items using a specific key, and grouping them into arrays
|
|
2267
1717
|
*/
|
|
2268
|
-
export declare function toRecord<Item, Key extends
|
|
2269
|
-
array: Item[],
|
|
2270
|
-
key: Key,
|
|
2271
|
-
arrays: true,
|
|
2272
|
-
): Record<ReturnType<Key>, Item[]>;
|
|
1718
|
+
export declare function toRecord<Item, Key extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: Key, arrays: true): Record<ReturnType<Key>, Item[]>;
|
|
2273
1719
|
/**
|
|
2274
1720
|
* Create a record from an array of items using a specific key and value
|
|
2275
1721
|
*/
|
|
2276
|
-
export declare function toRecord<
|
|
2277
|
-
Item,
|
|
2278
|
-
Key extends keyof Item,
|
|
2279
|
-
Value extends keyof Item,
|
|
2280
|
-
>(
|
|
2281
|
-
array: Item[],
|
|
2282
|
-
key: Key,
|
|
2283
|
-
value: Value,
|
|
2284
|
-
): Record<KeyedValue<Item, Key>, KeyedValue<Item, Value>>;
|
|
1722
|
+
export declare function toRecord<Item, Key extends keyof Item, Value extends keyof Item>(array: Item[], key: Key, value: Value): Record<KeyedValue<Item, Key>, KeyedValue<Item, Value>>;
|
|
2285
1723
|
/**
|
|
2286
1724
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
2287
1725
|
*/
|
|
2288
|
-
export declare function toRecord<
|
|
2289
|
-
Item,
|
|
2290
|
-
Key extends keyof Item,
|
|
2291
|
-
Value extends keyof Item,
|
|
2292
|
-
>(
|
|
2293
|
-
array: Item[],
|
|
2294
|
-
key: Key,
|
|
2295
|
-
value: Value,
|
|
2296
|
-
arrays: true,
|
|
2297
|
-
): Record<KeyedValue<Item, Key>, Array<KeyedValue<Item, Value>>>;
|
|
1726
|
+
export declare function toRecord<Item, Key extends keyof Item, Value extends keyof Item>(array: Item[], key: Key, value: Value, arrays: true): Record<KeyedValue<Item, Key>, Array<KeyedValue<Item, Value>>>;
|
|
2298
1727
|
/**
|
|
2299
1728
|
* Create a record from an array of items using a specific key and value
|
|
2300
1729
|
*/
|
|
2301
|
-
export declare function toRecord<
|
|
2302
|
-
Item,
|
|
2303
|
-
Key extends keyof Item,
|
|
2304
|
-
Value extends ValueCallback<Item>,
|
|
2305
|
-
>(
|
|
2306
|
-
array: Item[],
|
|
2307
|
-
key: Key,
|
|
2308
|
-
value: Value,
|
|
2309
|
-
): Record<KeyedValue<Item, Key>, ReturnType<Value>>;
|
|
1730
|
+
export declare function toRecord<Item, Key extends keyof Item, Value extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: Key, value: Value): Record<KeyedValue<Item, Key>, ReturnType<Value>>;
|
|
2310
1731
|
/**
|
|
2311
1732
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
2312
1733
|
*/
|
|
2313
|
-
export declare function toRecord<
|
|
2314
|
-
Item,
|
|
2315
|
-
Key extends keyof Item,
|
|
2316
|
-
Value extends ValueCallback<Item>,
|
|
2317
|
-
>(
|
|
2318
|
-
array: Item[],
|
|
2319
|
-
key: Key,
|
|
2320
|
-
value: Value,
|
|
2321
|
-
arrays: true,
|
|
2322
|
-
): Record<KeyedValue<Item, Key>, Array<ReturnType<Value>>>;
|
|
1734
|
+
export declare function toRecord<Item, Key extends keyof Item, Value extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: Key, value: Value, arrays: true): Record<KeyedValue<Item, Key>, Array<ReturnType<Value>>>;
|
|
2323
1735
|
/**
|
|
2324
1736
|
* Create a record from an array of items using a specific key and value
|
|
2325
1737
|
*/
|
|
2326
|
-
export declare function toRecord<
|
|
2327
|
-
Item,
|
|
2328
|
-
Key extends KeyCallback<Item>,
|
|
2329
|
-
Value extends keyof Item,
|
|
2330
|
-
>(
|
|
2331
|
-
array: Item[],
|
|
2332
|
-
key: Key,
|
|
2333
|
-
value: Value,
|
|
2334
|
-
): Record<ReturnType<Key>, KeyedValue<Item, Value>>;
|
|
1738
|
+
export declare function toRecord<Item, Key extends (item: Item, index: number, array: Item[]) => Key, Value extends keyof Item>(array: Item[], key: Key, value: Value): Record<ReturnType<Key>, KeyedValue<Item, Value>>;
|
|
2335
1739
|
/**
|
|
2336
1740
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
2337
1741
|
*/
|
|
2338
|
-
export declare function toRecord<
|
|
2339
|
-
Item,
|
|
2340
|
-
Key extends KeyCallback<Item>,
|
|
2341
|
-
Value extends keyof Item,
|
|
2342
|
-
>(
|
|
2343
|
-
array: Item[],
|
|
2344
|
-
key: Key,
|
|
2345
|
-
value: Value,
|
|
2346
|
-
arrays: true,
|
|
2347
|
-
): Record<ReturnType<Key>, Array<KeyedValue<Item, Value>>>;
|
|
1742
|
+
export declare function toRecord<Item, Key extends (item: Item, index: number, array: Item[]) => Key, Value extends keyof Item>(array: Item[], key: Key, value: Value, arrays: true): Record<ReturnType<Key>, Array<KeyedValue<Item, Value>>>;
|
|
2348
1743
|
/**
|
|
2349
1744
|
* Create a record from an array of items using a specific key and value
|
|
2350
1745
|
*/
|
|
2351
|
-
export declare function toRecord<
|
|
2352
|
-
Item,
|
|
2353
|
-
Key extends KeyCallback<Item>,
|
|
2354
|
-
Value extends ValueCallback<Item>,
|
|
2355
|
-
>(
|
|
2356
|
-
array: Item[],
|
|
2357
|
-
key: Key,
|
|
2358
|
-
value: Value,
|
|
2359
|
-
): Record<ReturnType<Key>, ReturnType<Value>>;
|
|
1746
|
+
export declare function toRecord<Item, Key extends (item: Item, index: number, array: Item[]) => Key, Value extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: Key, value: Value): Record<ReturnType<Key>, ReturnType<Value>>;
|
|
2360
1747
|
/**
|
|
2361
1748
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
2362
1749
|
*/
|
|
2363
|
-
export declare function toRecord<
|
|
2364
|
-
Item,
|
|
2365
|
-
Key extends KeyCallback<Item>,
|
|
2366
|
-
Value extends ValueCallback<Item>,
|
|
2367
|
-
>(
|
|
2368
|
-
array: Item[],
|
|
2369
|
-
key: Key,
|
|
2370
|
-
value: Value,
|
|
2371
|
-
arrays: true,
|
|
2372
|
-
): Record<ReturnType<Key>, Array<ReturnType<Value>>>;
|
|
1750
|
+
export declare function toRecord<Item, Key extends (item: Item, index: number, array: Item[]) => Key, Value extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: Key, value: Value, arrays: true): Record<ReturnType<Key>, Array<ReturnType<Value>>>;
|
|
2373
1751
|
/**
|
|
2374
1752
|
* Get an array of unique items
|
|
2375
1753
|
*/
|
|
2376
1754
|
export declare function unique<Item>(array: Item[]): Item[];
|
|
2377
1755
|
/**
|
|
2378
1756
|
* - Get an array of unique items
|
|
2379
|
-
* - Use `key` to find a comparison value
|
|
1757
|
+
* - Use `key` to find a comparison value for an item
|
|
2380
1758
|
*/
|
|
2381
|
-
export declare function unique<Item, Key extends keyof Item>(
|
|
2382
|
-
array: Item[],
|
|
2383
|
-
key: Key,
|
|
2384
|
-
): Item[];
|
|
1759
|
+
export declare function unique<Item, Key extends keyof Item>(array: Item[], key: Key): Item[];
|
|
2385
1760
|
/**
|
|
2386
1761
|
* - Get an array of unique items
|
|
2387
|
-
* - Use `key` to find a comparison value
|
|
1762
|
+
* - Use `key` to find a comparison value for an item
|
|
2388
1763
|
*/
|
|
2389
|
-
export declare function unique<Item, Key extends
|
|
2390
|
-
array: Item[],
|
|
2391
|
-
key: Key,
|
|
2392
|
-
): Item[];
|
|
1764
|
+
export declare function unique<Item, Key extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: Key): Item[];
|
|
2393
1765
|
/**
|
|
2394
1766
|
* Flatten an array _(using native `flat` and maximum depth)_
|
|
2395
1767
|
*/
|
|
@@ -2492,12 +1864,7 @@ declare abstract class Colour<Model> {
|
|
|
2492
1864
|
* Get the current value of the colour
|
|
2493
1865
|
*/
|
|
2494
1866
|
get value(): Model;
|
|
2495
|
-
constructor(
|
|
2496
|
-
type: string,
|
|
2497
|
-
value: Model,
|
|
2498
|
-
defaults: Model,
|
|
2499
|
-
properties: Array<keyof Model>,
|
|
2500
|
-
);
|
|
1867
|
+
constructor(type: string, value: Model, defaults: Model, properties: Array<keyof Model>);
|
|
2501
1868
|
/**
|
|
2502
1869
|
* Convert the colour to a hex-colour
|
|
2503
1870
|
*/
|
|
@@ -2569,9 +1936,7 @@ export declare function getRGBColour(value: RGBColourValue): RGBColour;
|
|
|
2569
1936
|
/**
|
|
2570
1937
|
* Is the value a colour?
|
|
2571
1938
|
*/
|
|
2572
|
-
export declare function isColour(
|
|
2573
|
-
value: unknown,
|
|
2574
|
-
): value is HexColour | HSLColour | RGBColour;
|
|
1939
|
+
export declare function isColour(value: unknown): value is HexColour | HSLColour | RGBColour;
|
|
2575
1940
|
/**
|
|
2576
1941
|
* Is the value a hex-colour?
|
|
2577
1942
|
*/
|
|
@@ -2622,10 +1987,7 @@ export declare class Emitter<Value> {
|
|
|
2622
1987
|
}
|
|
2623
1988
|
export declare class Observable<Value> {
|
|
2624
1989
|
private readonly state;
|
|
2625
|
-
constructor(
|
|
2626
|
-
emitter: Emitter<Value>,
|
|
2627
|
-
observers: Map<Subscription<Value>, Observer<Value>>,
|
|
2628
|
-
);
|
|
1990
|
+
constructor(emitter: Emitter<Value>, observers: Map<Subscription<Value>, Observer<Value>>);
|
|
2629
1991
|
/**
|
|
2630
1992
|
* Subscribe to value changes
|
|
2631
1993
|
*/
|
|
@@ -2633,11 +1995,7 @@ export declare class Observable<Value> {
|
|
|
2633
1995
|
/**
|
|
2634
1996
|
* Subscribe to value changes
|
|
2635
1997
|
*/
|
|
2636
|
-
subscribe(
|
|
2637
|
-
onNext: (value: Value) => void,
|
|
2638
|
-
onError?: (error: Error) => void,
|
|
2639
|
-
onComplete?: () => void,
|
|
2640
|
-
): Subscription<Value>;
|
|
1998
|
+
subscribe(onNext: (value: Value) => void, onError?: (error: Error) => void, onComplete?: () => void): Subscription<Value>;
|
|
2641
1999
|
}
|
|
2642
2000
|
export type ObservableState<Value> = {
|
|
2643
2001
|
emitter: Emitter<Value>;
|
|
@@ -2721,16 +2079,11 @@ export type MemoisedState<Callback extends GenericCallback> = {
|
|
|
2721
2079
|
* - Time is clamped between _0_ and _1000_ milliseconds
|
|
2722
2080
|
* - Returns the callback with an added `cancel`-method for manually cancelling the debounce
|
|
2723
2081
|
*/
|
|
2724
|
-
export declare function debounce<Callback extends GenericCallback>(
|
|
2725
|
-
callback: Callback,
|
|
2726
|
-
time?: number,
|
|
2727
|
-
): Debounced<Callback>;
|
|
2082
|
+
export declare function debounce<Callback extends GenericCallback>(callback: Callback, time?: number): Debounced<Callback>;
|
|
2728
2083
|
/**
|
|
2729
2084
|
* Memoise a function, caching and retrieving results based on the first parameter
|
|
2730
2085
|
*/
|
|
2731
|
-
export declare function memoise<Callback extends GenericCallback>(
|
|
2732
|
-
callback: Callback,
|
|
2733
|
-
): Memoised<Callback>;
|
|
2086
|
+
export declare function memoise<Callback extends GenericCallback>(callback: Callback): Memoised<Callback>;
|
|
2734
2087
|
/**
|
|
2735
2088
|
* A function that does nothing, which can be useful, I guess…
|
|
2736
2089
|
*/
|
|
@@ -2739,10 +2092,7 @@ export declare function noop(): void;
|
|
|
2739
2092
|
* - Throttle a function, ensuring it is only called once every `time` milliseconds
|
|
2740
2093
|
* - Time is clamped between _0_ and _1000_ milliseconds
|
|
2741
2094
|
*/
|
|
2742
|
-
export declare function throttle<Callback extends GenericCallback>(
|
|
2743
|
-
callback: Callback,
|
|
2744
|
-
time?: number,
|
|
2745
|
-
): Callback;
|
|
2095
|
+
export declare function throttle<Callback extends GenericCallback>(callback: Callback, time?: number): Callback;
|
|
2746
2096
|
/**
|
|
2747
2097
|
* Convert a string to camel case _(thisIsCamelCase)_
|
|
2748
2098
|
*/
|
|
@@ -2780,11 +2130,7 @@ export type Options = {
|
|
|
2780
2130
|
/**
|
|
2781
2131
|
* Render a string from a template with variables
|
|
2782
2132
|
*/
|
|
2783
|
-
export declare function template(
|
|
2784
|
-
value: string,
|
|
2785
|
-
variables: PlainObject,
|
|
2786
|
-
options?: Partial<Options>,
|
|
2787
|
-
): string;
|
|
2133
|
+
export declare function template(value: string, variables: PlainObject, options?: Partial<Options>): string;
|
|
2788
2134
|
/**
|
|
2789
2135
|
* Create a new UUID
|
|
2790
2136
|
*/
|
|
@@ -2800,20 +2146,13 @@ export declare function join(value: unknown[], delimiter?: string): string;
|
|
|
2800
2146
|
/**
|
|
2801
2147
|
* Parse a JSON string into its proper value _(or `undefined` if it fails)_
|
|
2802
2148
|
*/
|
|
2803
|
-
export declare function parse(
|
|
2804
|
-
value: string,
|
|
2805
|
-
reviver?: (this: unknown, key: string, value: unknown) => unknown,
|
|
2806
|
-
): unknown;
|
|
2149
|
+
export declare function parse(value: string, reviver?: (this: unknown, key: string, value: unknown) => unknown): unknown;
|
|
2807
2150
|
/**
|
|
2808
2151
|
* Truncate a string to a specified length, when possible
|
|
2809
2152
|
* - Returned as-is if the string is already short enough
|
|
2810
2153
|
* - A suffix may be appended to the truncated string, e.g., an ellipsis
|
|
2811
2154
|
*/
|
|
2812
|
-
export declare function truncate(
|
|
2813
|
-
value: string,
|
|
2814
|
-
length: number,
|
|
2815
|
-
suffix?: string,
|
|
2816
|
-
): string;
|
|
2155
|
+
export declare function truncate(value: string, length: number, suffix?: string): string;
|
|
2817
2156
|
/**
|
|
2818
2157
|
* Split a string into words _(and other readable parts)_
|
|
2819
2158
|
*/
|
|
@@ -2826,7 +2165,7 @@ export declare function clone(value: unknown): {} | null | undefined;
|
|
|
2826
2165
|
* Compare two values _(for sorting purposes)_
|
|
2827
2166
|
*/
|
|
2828
2167
|
export declare function compare(first: unknown, second: unknown): number;
|
|
2829
|
-
export type DiffType =
|
|
2168
|
+
export type DiffType = "full" | "none" | "partial";
|
|
2830
2169
|
export type DiffResult<First, Second = First> = {
|
|
2831
2170
|
original: DiffValue<First, Second>;
|
|
2832
2171
|
type: DiffType;
|
|
@@ -2846,18 +2185,11 @@ export type DiffValue<First = unknown, Second = First> = {
|
|
|
2846
2185
|
* - `partial` if the values are partially different
|
|
2847
2186
|
* - `values` holds the differences with dot notation keys
|
|
2848
2187
|
*/
|
|
2849
|
-
export declare function diff<First, Second = First>(
|
|
2850
|
-
first: First,
|
|
2851
|
-
second: Second,
|
|
2852
|
-
): DiffResult<First, Second>;
|
|
2188
|
+
export declare function diff<First, Second = First>(first: First, second: Second): DiffResult<First, Second>;
|
|
2853
2189
|
/**
|
|
2854
2190
|
* Are two strings equal? _(Case-sensitive by default)_
|
|
2855
2191
|
*/
|
|
2856
|
-
export declare function equal(
|
|
2857
|
-
first: string,
|
|
2858
|
-
second: string,
|
|
2859
|
-
ignoreCase?: boolean,
|
|
2860
|
-
): boolean;
|
|
2192
|
+
export declare function equal(first: string, second: string, ignoreCase?: boolean): boolean;
|
|
2861
2193
|
/**
|
|
2862
2194
|
* Are two values equal? _(Does a deep comparison, if needed)_
|
|
2863
2195
|
*/
|
|
@@ -2867,21 +2199,14 @@ export declare function equal(first: unknown, second: unknown): boolean;
|
|
|
2867
2199
|
* - You can retrieve a nested value by using dot notation, e.g., `foo.bar.baz`
|
|
2868
2200
|
* - Returns `undefined` if the value is not found
|
|
2869
2201
|
*/
|
|
2870
|
-
export declare function getValue<
|
|
2871
|
-
Data extends PlainObject,
|
|
2872
|
-
Path extends Paths<Data>,
|
|
2873
|
-
>(data: Data, path: Path): Get<Data, ToString<Path>>;
|
|
2202
|
+
export declare function getValue<Data extends PlainObject, Path extends Paths<Data>>(data: Data, path: Path): Get<Data, ToString<Path>>;
|
|
2874
2203
|
/**
|
|
2875
2204
|
* - Get the value from an object using an unknown path
|
|
2876
2205
|
* - You can retrieve a nested value by using dot notation, e.g., `foo.bar.baz`
|
|
2877
2206
|
* - If `ignoreCase` is `true`, path matching will be case-insensitive
|
|
2878
2207
|
* - Returns `undefined` if the value is not found
|
|
2879
2208
|
*/
|
|
2880
|
-
export declare function getValue<Data extends PlainObject>(
|
|
2881
|
-
data: Data,
|
|
2882
|
-
path: string,
|
|
2883
|
-
ignoreCase?: boolean,
|
|
2884
|
-
): unknown;
|
|
2209
|
+
export declare function getValue<Data extends PlainObject>(data: Data, path: string, ignoreCase?: boolean): unknown;
|
|
2885
2210
|
export type MergeOptions = {
|
|
2886
2211
|
/**
|
|
2887
2212
|
* - Skip nullable values when merging arrays?
|
|
@@ -2892,20 +2217,14 @@ export type MergeOptions = {
|
|
|
2892
2217
|
/**
|
|
2893
2218
|
* Merge multiple arrays or objects into a single one
|
|
2894
2219
|
*/
|
|
2895
|
-
export declare function merge<Model extends ArrayOrPlainObject>(
|
|
2896
|
-
values: Model[],
|
|
2897
|
-
options?: Partial<MergeOptions>,
|
|
2898
|
-
): Model;
|
|
2220
|
+
export declare function merge<Model extends ArrayOrPlainObject>(values: Model[], options?: Partial<MergeOptions>): Model;
|
|
2899
2221
|
/**
|
|
2900
2222
|
* - Set the value in an object using a known path
|
|
2901
2223
|
* - You can set a nested value by using dot notation, e.g., `foo.bar.baz`
|
|
2902
2224
|
* - 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
|
|
2903
2225
|
* - Returns the original object
|
|
2904
2226
|
*/
|
|
2905
|
-
export declare function setValue<
|
|
2906
|
-
Data extends PlainObject,
|
|
2907
|
-
Path extends Paths<Data>,
|
|
2908
|
-
>(data: Data, path: Path, value: unknown): Data;
|
|
2227
|
+
export declare function setValue<Data extends PlainObject, Path extends Paths<Data>>(data: Data, path: Path, value: unknown): Data;
|
|
2909
2228
|
/**
|
|
2910
2229
|
* - Set the value in an object using an unknown path
|
|
2911
2230
|
* - You can set a nested value by using dot notation, e.g., `foo.bar.baz`
|
|
@@ -2913,41 +2232,24 @@ export declare function setValue<
|
|
|
2913
2232
|
* - If `ignoreCase` is `true`, path matching will be case-insensitive
|
|
2914
2233
|
* - Returns the original object
|
|
2915
2234
|
*/
|
|
2916
|
-
export declare function setValue<Data extends PlainObject>(
|
|
2917
|
-
data: Data,
|
|
2918
|
-
path: string,
|
|
2919
|
-
value: unknown,
|
|
2920
|
-
ignoreCase?: boolean,
|
|
2921
|
-
): Data;
|
|
2235
|
+
export declare function setValue<Data extends PlainObject>(data: Data, path: string, value: unknown, ignoreCase?: boolean): Data;
|
|
2922
2236
|
export type Smushed<Value> = Simplify<{
|
|
2923
2237
|
[Key in Paths<Value>]: Get<Value, ToString<Key>>;
|
|
2924
2238
|
}>;
|
|
2925
2239
|
/**
|
|
2926
2240
|
* Smush an object into a flat object that uses dot notation keys
|
|
2927
2241
|
*/
|
|
2928
|
-
export declare function smush<Value extends PlainObject>(
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
Omit<
|
|
2933
|
-
{
|
|
2934
|
-
[Key in KeysOfUnion<Value>]: Value[Key];
|
|
2935
|
-
},
|
|
2936
|
-
`${string}.${string}`
|
|
2937
|
-
>
|
|
2938
|
-
>;
|
|
2242
|
+
export declare function smush<Value extends PlainObject>(value: Value): Smushed<Value>;
|
|
2243
|
+
export type Unsmushed<Value extends PlainObject> = Simplify<Omit<{
|
|
2244
|
+
[Key in KeysOfUnion<Value>]: Value[Key];
|
|
2245
|
+
}, `${string}.${string}`>>;
|
|
2939
2246
|
/**
|
|
2940
2247
|
* Unsmush a smushed object _(turning dot notation keys into nested keys)_
|
|
2941
2248
|
*/
|
|
2942
|
-
export declare function unsmush<Value extends PlainObject>(
|
|
2943
|
-
value: Value,
|
|
2944
|
-
): Unsmushed<Value>;
|
|
2249
|
+
export declare function unsmush<Value extends PlainObject>(value: Value): Unsmushed<Value>;
|
|
2945
2250
|
/**
|
|
2946
2251
|
* Create a new object with only the specified keys
|
|
2947
2252
|
*/
|
|
2948
|
-
export declare function partial<
|
|
2949
|
-
Value extends PlainObject,
|
|
2950
|
-
Key extends keyof Value,
|
|
2951
|
-
>(value: Value, keys: Key[]): Pick<Value, Key>;
|
|
2253
|
+
export declare function partial<Value extends PlainObject, Key extends keyof Value>(value: Value, keys: Key[]): Pick<Value, Key>;
|
|
2952
2254
|
|
|
2953
2255
|
export {};
|