-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.d.ts
4199 lines (3715 loc) · 111 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
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
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
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
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
* V4Fire Core
* https://github.com/V4Fire/Core
*
* Released under the MIT license
* https://github.com/V4Fire/Core/blob/master/LICENSE
*/
/* eslint-disable max-lines, @typescript-eslint/unified-signatures */
/**
* [[include:core/prelude/README.md]]
* @packageDocumentation
*/
declare namespace TB {
type Cast<X, Y> = X extends Y ? X : Y;
type Type<A extends any, ID extends string> = A & {
[K in 'symbol']: ID;
};
type Length<T extends any[]> = T['length'];
type Head<T extends any[]> = T extends [infer H, ...any[]] ?
H : never;
type Tail<T extends any[]> = T extends [any, ...infer TT] ?
TT : [];
type HasTail<T extends any[]> = Length<T> extends 0 | 1 ?
false : true;
type Last<T extends any[]> = HasTail<T> extends true ?
Last<Tail<T>> : Head<T>;
type Prepend<E, T extends any[]> = [E, ...T];
type Drop<N extends number, T extends any[], I extends any[] = []> = Length<I> extends N ?
T : Drop<N, Tail<T>, Prepend<any, I>>;
type Pos<I extends any[]> = Length<I>;
type Next<I extends any[]> = Prepend<any, I>;
type Prev<I extends any[]> = Tail<I>;
type Reverse<T extends any[], R extends any[] = [], I extends any[] = []> = Pos<I> extends Length<T> ?
R : Reverse<T, Prepend<T[Pos<I>], R>, Next<I>>;
type Concat<T1 extends any[], T2 extends any[]> = Reverse<Cast<Reverse<T1>, any[]>, T2>;
type Append<E, T extends any[]> = Concat<T, [E]>;
type __ = Type<{}, 'x'>;
type GapOf<T1 extends any[], T2 extends any[], TN extends any[], I extends any[]> =
T1[Pos<I>] extends __ ? Append<T2[Pos<I>], TN> : TN;
type GapsOf<T1 extends any[], T2 extends any[], TN extends any[] = [], I extends any[] = []> =
Pos<I> extends Length<T1> ?
Concat<TN, Cast<Drop<Pos<I>, T2>, any[]>> :
GapsOf<T1, T2, Cast<GapOf<T1, T2, TN, I>, any[]>, Next<I>>;
type PartialGaps<T extends any[]> = {
[K in keyof T]?: T[K] | __;
};
type CleanedGaps<T extends any[]> = {
[K in keyof T]: NonNullable<T[K]>;
};
type Gaps<T extends any[]> = CleanedGaps<PartialGaps<T>> extends [...infer A] ?
A : never;
type Curry<F extends ((...args: any) => any)> =
<T extends any[]>(...args: Cast<T, Gaps<Parameters<F>>>) =>
GapsOf<T, Parameters<F>> extends [any, ...any[]] ?
Curry<(...args: Cast<GapsOf<T, Parameters<F>>, any[]>) => ReturnType<F>> :
ReturnType<F>;
}
declare const DEBUG: boolean;
declare const IS_PROD: boolean;
declare const APP_NAME: string;
declare const API_URL: CanUndef<string>;
declare const LOCALE: Language;
declare const REGION: CanUndef<Region>;
type Language =
'be' | 'en' | 'kk' |
'ru' | 'tr' | 'tt' |
'uk' | 'id' | 'uz' |
'es' | 'de' | 'hy' |
'ka' | 'ky' | 'sr' |
'fr' | 'lv' | 'lt' |
'ro' | 'fi' | 'az' |
'zh' | 'he' | 'et' |
'no' | 'sv' | 'pt' |
'ar' | 'sw';
/**
* ISO 3166-1
* @see https://en.wikipedia.org/wiki/ISO_3166-1
*/
type Region =
'AD' | 'AE' | 'AF' | 'AG' | 'AI' | 'AL' | 'AM' |
'AO' | 'AQ' | 'AR' | 'AS' | 'AT' | 'AU' | 'AW' |
'AX' | 'AZ' | 'BA' | 'BB' | 'BD' | 'BE' | 'BF' |
'BG' | 'BH' | 'BI' | 'BJ' | 'BL' | 'BM' | 'BN' |
'BO' | 'BQ' | 'BR' | 'BS' | 'BT' | 'BV' | 'BW' |
'BY' | 'BZ' | 'CA' | 'CC' | 'CD' | 'CF' | 'CG' |
'CH' | 'CI' | 'CK' | 'CL' | 'CM' | 'CN' | 'CO' |
'CR' | 'CU' | 'CV' | 'CW' | 'CX' | 'CY' | 'CZ' |
'DE' | 'DJ' | 'DK' | 'DM' | 'DO' | 'DZ' | 'EC' |
'EE' | 'EG' | 'EH' | 'ER' | 'ES' | 'ET' | 'FI' |
'FJ' | 'FK' | 'FM' | 'FO' | 'FR' | 'GA' | 'GB' |
'GD' | 'GE' | 'GF' | 'GG' | 'GH' | 'GI' | 'GL' |
'GM' | 'GN' | 'GP' | 'GQ' | 'GR' | 'GS' | 'GT' |
'GU' | 'GW' | 'GY' | 'HK' | 'HM' | 'HN' | 'HR' |
'HT' | 'HU' | 'ID' | 'IE' | 'IL' | 'IM' | 'IN' |
'IO' | 'IQ' | 'IR' | 'IS' | 'IT' | 'JE' | 'JM' |
'JO' | 'JP' | 'KE' | 'KG' | 'KH' | 'KI' | 'KM' |
'KN' | 'KP' | 'KR' | 'KW' | 'KY' | 'KZ' | 'LA' |
'LB' | 'LC' | 'LI' | 'LK' | 'LR' | 'LS' | 'LT' |
'LU' | 'LV' | 'LY' | 'MA' | 'MC' | 'MD' | 'ME' |
'MF' | 'MG' | 'MH' | 'MK' | 'ML' | 'MM' | 'MN' |
'MO' | 'MP' | 'MQ' | 'MR' | 'MS' | 'MT' | 'MU' |
'MV' | 'MW' | 'MX' | 'MY' | 'MZ' | 'NA' | 'NC' |
'NE' | 'NF' | 'NG' | 'NI' | 'NL' | 'NO' | 'NP' |
'NR' | 'NU' | 'NZ' | 'OM' | 'PA' | 'PE' | 'PF' |
'PG' | 'PH' | 'PK' | 'PL' | 'PM' | 'PN' | 'PR' |
'PS' | 'PT' | 'PW' | 'PY' | 'QA' | 'RE' | 'RO' |
'RS' | 'RU' | 'RW' | 'SA' | 'SB' | 'SC' | 'SD' |
'SE' | 'SG' | 'SH' | 'SI' | 'SJ' | 'SK' | 'SL' |
'SM' | 'SN' | 'SO' | 'SR' | 'SS' | 'ST' | 'SV' |
'SX' | 'SY' | 'SZ' | 'TC' | 'TD' | 'TF' | 'TG' |
'TH' | 'TJ' | 'TK' | 'TL' | 'TM' | 'TN' | 'TO' |
'TR' | 'TT' | 'TV' | 'TW' | 'TZ' | 'UA' | 'UG' |
'UM' | 'US' | 'UY' | 'UZ' | 'VA' | 'VC' | 'VE' |
'VG' | 'VI' | 'VN' | 'VU' | 'WF' | 'WS' | 'YE' |
'YT' | 'ZA' | 'ZM' | 'ZW';
/**
* Converts the specified unknown value to any
* @param obj
*/
declare function Any(obj: any): any;
/**
* STDERR wrapper
* @param err
*/
declare function stderr(err: any): void;
/**
* Creates a function to internationalize strings in an application based on the given locale and keyset.
* Keyset allows you to share the same keys in different contexts.
* For example, the key "Next" may have a different value in different components of the application, therefore,
* we can use the name of the component as a keyset value.
*
* @param keysetNameOrNames - the name of keyset or array with names of keysets to use.
* If passed as an array, the priority of the cases will be arranged in the order of the elements,
* the first one will have the highest priority.
*
* @param [customLocale] - the locale used to search for translations (the default is taken from
* the application settings)
*/
declare function i18n(
keysetNameOrNames: CanArray<string>, customLocale?: Language
): (key: string | TemplateStringsArray, params?: I18nParams) => string;
/**
* Parameters for the internationalization function
*/
type I18nParams = {count?: number | StringPluralizationForms} & {
[key: string]: string | number;
};
/**
* String pluralization constants that can be used instead of numbers
*/
type StringPluralizationForms = 'one' | 'some' | 'many' | 'none';
declare function setImmediate(fn: AnyFunction): number;
declare function clearImmediate(id: number): void;
declare function structuredClone<T>(obj: T): T;
interface Headers {
keys(): IterableIterator<string>;
values(): IterableIterator<string>;
entries(): IterableIterator<[string, string]>;
[Symbol.iterator]: IterableIterator<[string, string]>;
}
type Primitive =
string |
symbol |
number |
bigint |
boolean |
undefined |
null;
type JSONLikeValue =
string |
number |
boolean |
null |
JSONLikeValue[] |
Dictionary<JSONLikeValue>;
type CanPromise<T> = T | Promise<T>;
type CanPromiseLike<T> = T | PromiseLike<T>;
type CanArray<T> = T | T[];
type CanUndef<T> = T | undefined;
type Nullable<T> = T | null | undefined;
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
type CanVoid<T> = T | void;
type AnyToIgnore = any;
type AnyToBoolean = any;
interface AnyFunction<ARGS extends any[] = any[], R = any> extends Function {
(...args: ARGS): R;
}
interface AnyOneArgFunction<ARG = any, R = any> extends Function {
(arg: ARG): R;
}
type ClassConstructor<ARGS extends any[] = any[], R = any> = new (...args: ARGS) => R;
interface StrictDictionary<T = unknown> {
[key: PropertyKey]: T;
}
interface Dictionary<T = unknown> {
[key: PropertyKey]: CanUndef<T>;
}
interface Maybe<T = unknown> extends Promise<T> {
readonly type: 'Maybe';
}
interface Either<T = unknown> extends Promise<T> {
readonly type: 'Either';
}
type NewPromise<K, V> = K extends Maybe ?
Maybe<V> : K extends Either ?
Either<V> : Promise<V>;
type PromiseType<T> =
T extends Maybe<infer V> ?
NonNullable<V> : T extends Promise<infer V> ? V : T;
/**
* Wraps the specified function to return a value as Promise
*
* @typeparam T - any function
*
* @example
* ```typescript
* type A = typeof () => null;
*
* // () => Promise<null>
* type B = ReturnPromise<A>;
* ```
*/
type ReturnPromise<T extends AnyFunction<any[], unknown>> = (...args: Parameters<T>) => Promise<ReturnType<T>>;
type DictionaryType<T extends Dictionary> = T extends Dictionary<infer V> ? NonNullable<V> : T;
type AnyIterable<T = unknown> = Iterable<T> | AsyncIterable<T>;
type IterableType<T extends Iterable<any> | AsyncIterable<any>> =
T extends Iterable<infer V> ?
V :
T extends AsyncIterable<infer V> ? V : T;
/**
* Creates an interface based on the specified type or interface but every property can be edited
*/
type Writable<T> = {
-readonly [K in keyof T]: T[K];
};
/**
* Overrides properties of the specified type or interface.
* Don't use this helper if you simply extend one type from another, i.e. without overriding properties.
*
* @template T - original type
* @template U - type with the overridden properties
*
* @example
* ```typescript
* type A = {
* x: number;
* y: number;
* };
*
* // {x:number; y: string}
* type B = Overwrite<A, {y: string}>;
* ```
*/
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
/**
* Returns a new non-abstract class from the specified abstract class where methods can have the default implementation.
* The default implementations are taken from the static methods that match by names with the class's methods.
*
* @example
* ```typescript
* abstract class iFoo {
* static bar(self: object): string {
* return self.bla.toString();
* }
*
* bar(): string {
* return Object.throw();
* }
*
* abstract bar(): number;
* }
*
* // class { bar(): string; }
* Trait<typeof bFoo>
* ```
*/
type Trait<C extends Function, I extends C['prototype'] = C['prototype']> = {
[K in Extract<keyof C, keyof I>]: I[K];
};
/**
* Returns a new function based on the specified with adding as the first parameter the passed object
*
* @example
* ```typescript
* // (self: bFoo, a: number) => string
* AddSelf<(a: number) => string, bFoo>
* ```
*/
type AddSelf<M extends Function, S extends object> = M extends (...args: infer A) => infer R ?
(self: S, ...args: A) => R :
never;
interface JSONCb {
(key: string, value: unknown): unknown;
}
interface FastCloneOptions {
/**
* Replacer function for `JSON.stringify`
* @see [[JSON.stringify]]
*/
replacer?: JSONCb;
/**
* Reviver function for `JSON.parse`
* @see [[JSON.parse]]
*/
reviver?: JSONCb;
/**
* If false the object freeze/seal state won't be copy
* @default `true`
*/
freezable?: boolean;
}
interface ObjectMixinOptions<V = unknown, K = unknown, D = unknown> {
/**
* If true, then object properties are copied recursively.
* Also, this mode enables copying properties from a prototype.
*
* @default `false`
* @example
* ```js
* // {a: {c: 2}}
* Object.mixin({deep: false}, {a: {b: 1}}, {a: {c: 2}});
*
* // {a: {b: 1, c: 2}}
* Object.mixin({deep: true}, {a: {b: 1}}, {a: {c: 2}});
*
* // {a: {c: 2}}
* Object.mixin({deep: true}, {}, {__proto__: {a: {c: 2}}});
* ```
*/
deep?: boolean;
/**
* Strategy to resolve collisions of properties when merging:
* 1. `'all'` - all properties are merged in spite of possible collisions (by default)
* 2. `'new'` - properties with collisions aren't merged
* 3. `'exist'` - properties without collisions aren't merged
*
* @default `'all'`
* @example
* ```js
* // {a: 2, b: 3}
* Object.mixin({propsToCopy: 'all'}, {a: 1}, {a: 2, b: 3});
*
* // {a: 1, b: 3}
* Object.mixin({propsToCopy: 'new'}, {a: 1}, {a: 2, b: 3});
*
* // {a: 2}
* Object.mixin({propsToCopy: 'exist'}, {a: 1}, {a: 2, b: 3});
* ```
*/
propsToCopy?: 'new' | 'exist' | 'all';
/**
* Function to filter values that shouldn't be copied
*
* @param el - element value
* @param key - element key
* @param data - element container
*
* @example
* ```js
* // {a: 1, b: 2}
* Object.mixin({deep: true}, {a: 1}, {b: 2});
*
* // {a: 1}
* Object.mixin({deep: true, filter: (el, key) => key !== 'b'}, {a: 1}, {b: 2});
* ```
*/
filter?(el: V, key: K, data: D): AnyToBoolean;
/**
* Function to filter values that support deep extending
* (works only with the `deep` mode)
*
* @param el - element value
* @param key - element key
* @param data - element container
*
* @example
* ```js
* // {a: {a: 1, b: 2}}
* Object.mixin({deep: true}, {a: {a: 1}}, {a: {b: 2}});
*
* // {a: {b: 2}}
* Object.mixin({deep: true, extendFilter: (el) => !el.b}, {a: {a: 1}}, {a: {b: 2}});
* ```
*/
extendFilter?(el: unknown, key: K, data: V): AnyToBoolean;
/**
* If true, all properties with undefined value aren't copied
*
* @default `true`
* @example
* ```js
* // {a: 1}
* Object.mixin({skipUndefs: true}, {a: 1}, {a: undefined});
*
* // {a: undefined}
* Object.mixin({skipUndefs: false}, {a: 1}, {a: undefined});
* ```
*/
skipUndefs?: boolean;
/**
* If true, the function will merge all object properties, but not only enumerable.
* Non-enumerable properties from a prototype are ignored.
*
* @default `false`
* @example
* ```js
* const obj = {a: 1};
*
* Object.defineProperty(obj, 'b', {value: 2});
*
* // {a: 1, b: 2}
* Object.mixin({withNonEnumerables: true}, {}, obj);
* ```
*/
withNonEnumerables?: boolean;
/**
* Should or shouldn't copy property descriptors too.
* If passed `onlyAccessors`, the descriptor properties like `enumerable` or `configurable` are ignored.
*
* @default `false`
*/
withDescriptors?: boolean | 'onlyAccessors';
/**
* If true, then merging preserve prototypes of properties
* (works only with the `deep` mode)
*
* @default `false`
* @example
* ```js
* const proto = {
* a: {
* b: 2
* },
*
* c: 3
* };
*
* const obj = Object.create(proto);
* Object.mixin({deep: true, withProto: false}, obj, {c: 2, a: {d: 4}});
*
* // 2
* // 4
* // 2
* // true
* // true
* console.log(
* obj.c,
* obj.a.d,
* obj.a.b,
* obj.a.hasOwnProperty('d'),
* obj.a.hasOwnProperty('b')
* );
*
* const obj2 = Object.create(proto);
* Object.mixin({deep: true, withProto: true}, obj2, {c: 2, a: {d: 4}});
*
* // 2
* // 4
* // 2
* // true
* // false
* console.log(
* obj2.c,
* obj2.a.d,
* obj2.a.b,
* obj2.a.hasOwnProperty('d'),
* obj2.a.hasOwnProperty('b')
* );
* ```
*/
withProto?: boolean;
/**
* If true, then to merge two arrays will be used a concatenation strategy (works only with the `deep` mode).
* Also, the parameter can be passed as a function to concatenate arrays.
*
* @default `false`
* @example
* ```js
* // {a: [2]}
* Object.mixin({deep: true, concatArrays: false}, {a: [1]}, {a: [2]});
*
* // {a: [1, 2]}
* Object.mixin({deep: true, concatArrays: true}, {a: [1]}, {a: [2]});
*
* // {a: [1, 1, 2]}
* Object.mixin({deep: true, concatArrays: true}, {a: [1]}, {a: [1, 2]});
*
* // {a: [1, 2]}
* Object.mixin({deep: true, concatArrays: (a, b) => a.union(b)}, {a: [1]}, {a: [1, 2]});
* ```
*/
concatArrays?: boolean | ((a: unknown[], b: unknown[], key: K) => unknown[]);
/**
* @deprecated
* @see [[ObjectMixinOptions.concatArrays]]
*/
concatArray?: boolean;
/**
* @deprecated
* @see [[ObjectMixinOptions.concatArrays]]
*/
concatFn?(a: unknown[], b: unknown[], key: K): unknown[];
/**
* @deprecated
* @see [[ObjectMixinOptions.propsToCopy]]
*/
onlyNew?: boolean | -1;
/**
* @deprecated
* @see [[ObjectMixinOptions.propsToCopy]]
*/
traits?: boolean | -1;
/**
* @deprecated
* @see [[ObjectMixinOptions.skipUndefs]]
*/
withUndef?: boolean;
/**
* @deprecated
* @see [[ObjectMixinOptions.withDescriptors]]
*/
withDescriptor?: boolean;
/**
* @deprecated
* @see [[ObjectMixinOptions.withDescriptors]]
*/
withAccessors?: boolean;
}
interface ObjectGetOptions {
/**
* Character to declare the path
*
* @example
* ```js
* Object.get({a: {b: 1}}, 'a:b', {separator: ':'})
* ```
*/
separator?: string;
}
interface ObjectSetOptions extends ObjectGetOptions {
/**
* If true, then a new value will be concatenated with the old
*
* @example
* ```js
* const obj = {a: {b: 1}};
* Object.set(obj, 'a.b', 2, {concat: true})
* console.log(obj); // [1, 2]
* ```
*/
concat?: boolean;
/**
* Function to set a value
*
* @param obj
* @param key
* @param value
*/
setter?(obj: unknown, key: unknown, value: unknown);
}
interface ObjectForEachOptions {
/**
* If true, then the callback function takes an element descriptor instead of a value
*
* @default `false`
* @example
* ```js
* Object.forEach({a: 1}, {showDescriptor: true}, (el) => {
* // {configurable: true, enumerable: true, writable: true, value: 1}
* console.log(el);
* });
* ```
*/
passDescriptor?: boolean;
/**
* Strategy to iterate object properties:
* 1. `'own'` - the object iterates only own properties (by default)
* 2. `'inherited'` - the object iterates only inherited properties
* (for-in with the negative `hasOwnProperty` check)
*
* 3. `'all'` - the object iterates inherited properties too (for-in without the `hasOwnProperty` check)
*
* @example
* ```js
* const obj = {a: 1, __proto__: {b: 2}};
*
* Object.forEach(obj, (el) => {
* console.log(el); // 1
* });
*
* Object.forEach(obj, {propsToIterate: 'all'}, (el) => {
* console.log(el); // 1 2
* });
*
* Object.forEach(obj, {propsToIterate: 'inherited'}, (el) => {
* console.log(el); // 2
* });
* ```
*/
propsToIterate?: 'own' | 'inherited' | 'all';
/**
* If true, the function will iterate all object properties, but not only enumerable.
* Non-enumerable properties from a prototype are ignored.
*
* @default `false`
* @example
* ```js
* const obj = {a: 1};
*
* Object.defineProperty(obj, 'b', {value: 2});
*
* // 1
* // 2
* Object.forEach(obj, {withNonEnumerables: true}, (el) => {
* console.log(el);
* });
* ```
*/
withNonEnumerables?: boolean;
/**
* @deprecated
* @see [[ObjectForEachOptions.passDescriptor]]
*/
withDescriptor?: boolean;
/**
* @deprecated
* @see [[ObjectForEachOptions.propsToIterate]]
*/
notOwn?: boolean | -1;
}
interface ObjectForEachPropertyDescriptor<V = unknown> {
configurable?: boolean;
enumerable?: boolean;
value?: V;
writable?: boolean;
get?(): unknown;
set?(v: unknown): void;
}
interface ObjectFromArrayOptions<T = boolean> {
/**
* Function that returns a key value
*
* @param el - element value
* @param i - element index
*/
key?(el: unknown, i: number): PropertyKey;
/**
* @deprecated
* @see [[ObjectFromArrayOptions.key]]
*/
keyConverter?(i: number, el: unknown): PropertyKey;
/**
* Function that returns an element value
*
* @param el - element value
* @param i - element index
*/
value?(el: unknown, i: number): T;
/**
* @deprecated
* @see [[ObjectFromArrayOptions.value]]
*/
valueConverter?(el: unknown, i: number): T;
}
type ObjectPropertyPath =
string |
any[];
interface ObjectPropertyFilter<K = string, V = unknown> {
(key: K, el: V): AnyToBoolean;
}
interface ObjectConstructor {
/**
* Returns a value from the passed object by the specified path.
* Returns undefined if the specified path doesn't exist in the object.
* The method can access properties through promises.
*
* @param obj
* @param path
* @param [opts] - additional options
*/
get<T = unknown>(obj: any, path: ObjectPropertyPath, opts?: ObjectGetOptions): CanUndef<T>;
/**
* Returns a function that returns a value from the passed object, which the function takes, by the specified path.
* The function returns undefined if the specified path doesn't exist in the object.
*
* @param path
* @param [opts] - additional options
*/
get<T = unknown>(path: ObjectPropertyPath, opts?: ObjectGetOptions): (obj: any) => CanUndef<T>;
/**
* Returns a function that returns a value from the specified object by a path that the function takes.
* The function returns undefined if the specified path doesn't exist in the object.
*
* @param obj
* @param [opts] - additional options
*/
get<T = unknown>(obj: any, opts?: ObjectGetOptions): (path: ObjectPropertyPath) => CanUndef<T>;
/**
* Returns true if an object has a property by the specified path
*
* @param obj
* @param path
* @param [opts] - additional options
*/
has(obj: any, path: ObjectPropertyPath, opts?: ObjectGetOptions): boolean;
/**
* Returns a function that returns true if an object, which the function takes, has a value by the specified path
*
* @param path
* @param [opts] - additional options
*/
has(path: ObjectPropertyPath, opts?: ObjectGetOptions): (obj: any) => boolean;
/**
* Returns a function that returns true if the specified object has a value by a path that the function takes
*
* @param obj
* @param [opts] - additional options
*/
has(obj: any, opts?: ObjectGetOptions): (path: ObjectPropertyPath) => boolean;
/**
* Returns a function that returns true if the passed object, which the function takes,
* has own property by the specified key
*
* @param key
*/
hasOwnProperty(key: PropertyKey): (obj: any) => boolean;
/**
* Returns a function that returns true if the specified object has own property by a key that the function takes
* @param obj
*/
hasOwnProperty(obj: any): (key: PropertyKey) => boolean;
/**
* Returns true if the passed object has an own property by the specified key
*
* @param obj
* @param key
*/
hasOwnProperty(obj: any, key: PropertyKey): boolean;
/**
* Sets the passed symbol property to the given object.
* The character is set as non-enumerable to avoid implicit copying when using the spread operation.
*
* @param obj
* @param symbol
* @param value
* */
defineSymbol<T>(obj: T, symbol: symbol, value: any): T;
/**
* Sets a value to the passed object by the specified path.
* The final function returns a value that was added.
*
* @param obj
* @param path
* @param value
* @param [opts] - additional options
*/
set<T>(obj: any, path: ObjectPropertyPath, value: T, opts?: ObjectSetOptions): CanUndef<T>;
/**
* Returns a function that sets a value to an object, which the function takes, by the specified path.
* The final function returns a link to the object.
*
* @param path
* @param [opts] - additional options
* @param [value]
*/
set(path: ObjectPropertyPath, opts?: ObjectSetOptions, value?: any): <T>(obj: T, value?: any) => CanUndef<T>;
/**
* Returns a function that sets a value to the specified object by a path that the function takes.
* The final function returns a link to the object.
*
* @param obj
* @param [opts] - additional options
* @param [value]
*/
set<T>(obj: T, opts?: ObjectSetOptions, value?: any): (path: ObjectPropertyPath, value?: any) => CanUndef<T>;
/**
* Deletes a value from an object by the specified path
*
* @param obj
* @param path
* @param [opts] - additional options
*/
delete(obj: any, path: ObjectPropertyPath, opts?: ObjectGetOptions): boolean;
/**
* Returns a function that deletes a value from an object, which the function takes, by the specified path
*
* @param path
* @param [opts] - additional options
*/
delete(path: ObjectPropertyPath, opts?: ObjectGetOptions): (obj: any) => boolean;
/**
* Returns a function that deletes a value from the specified object by a path that the function takes
*
* @param obj
* @param [opts] - additional options
*/
delete(obj: any, opts?: ObjectGetOptions): (path: ObjectPropertyPath) => boolean;
/**
* Returns size/length of the specified object
*
* @param obj
*
* @example
* ```js
* // 1
* Object.size({a: 1});
*
* // 2
* Object.size([1, 2]);
*
* // 2
* Object.size(new Set([1, 2]));
*
* // 2
* Object.size((a, b) => a + b));
*
* // 1
* Object.size(1);
*
* // 0
* Object.size(NaN);
* Object.size(null);
* Object.size(undefined);
* ```
*/
size(obj: any): number;
/**
* Returns true if size/length of the specified entity is 0.
* The algorithm for determining whether the entity is empty depends on the type of the entity.
* - For Objects: The method counts the number of enumerable properties in the object. If the count is 0, the method considers the object as empty.
* - For Arrays and Strings: The method uses the length property of the array or string. If the length is 0, the method considers the array or string as empty.
* - For Maps and Sets: The method uses the size property of the map or set. If the size is 0, the method considers the map or set as empty.
* - For Numbers: The method uses the value of the number. If the value is 0, the method considers the number as empty.
*
* @param obj
*
* @example
* ```js
* // true
* Object.isEmpty({});
*
* // false
* Object.isEmpty({a: 1});
*
* // true
* Object.isEmpty(new Set());
*
* // false
* Object.isEmpty(new Set([1, 2]));
*
* // false
* Object.isEmpty(1);
*
* // true
* Object.isEmpty(0);
* Object.isEmpty(NaN);
* Object.isEmpty(null);
* Object.isEmpty(undefined);
* ```
*/
isEmpty(obj: any): boolean;
/**
* Iterates over the specified dictionary
*
* @param obj - object to iterate
* @param opts - additional options
* @param cb - callback function that is called on each of object elements
*/
forEach<V>(
obj: Dictionary<V>,
opts: ObjectForEachOptions & {withDescriptors: true},
cb: (el: ObjectForEachPropertyDescriptor<V>, key: string, data: Dictionary<V>) => any
): void;
/**
* Iterates over the specified dictionary
*
* @param obj - object to iterate
* @param opts - additional options
* @param cb - callback function that is called on each of object elements
*/
forEach<V>(
obj: Dictionary<V>,
opts: ObjectForEachOptions & ({propsToIterate: 'all' | 'notOwn'} | {withDescriptors: false}),
cb: (el: V, key: string, data: Dictionary<V>) => any
): void;
/**
* Iterates over the specified Map object