-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
core.js
882 lines (802 loc) · 32.3 KB
/
core.js
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
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the "flow" directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
/* JS primitives
cf. http://typescript.codeplex.com/sourcecontrol/latest#typings/lib.d.ts
*/
declare var NaN: number;
declare var Infinity: number;
declare var undefined: void;
declare function parseInt(string: mixed, radix?: number): number;
declare function parseFloat(string: mixed): number;
declare function isNaN(number: mixed): boolean;
declare function isFinite(number: mixed): boolean;
declare function decodeURI(encodedURI: string): string;
declare function decodeURIComponent(encodedURIComponent: string): string;
declare function encodeURI(uri: string): string;
declare function encodeURIComponent(uriComponent: string): string;
// TODO: instance
declare class Object {
static (o: ?void): {[key: any]: any};
static (o: boolean): Boolean;
static (o: number): Number;
static (o: string): String;
static <T: Object>(o: T): T;
static assign: Object$Assign;
static create(o: any, properties?: any): any; // compiler magic
static defineProperties(o: any, properties: any): any;
static defineProperty(o: any, p: any, attributes: any): any;
static entries(object: any): Array<[string, mixed]>;
static freeze<T>(o: T): T;
static getOwnPropertyDescriptor(o: any, p: any): any;
static getOwnPropertyNames(o: any): Array<string>;
static getOwnPropertySymbols(o: any): Symbol[];
static getPrototypeOf: Object$GetPrototypeOf;
static is(a: any, b: any): boolean;
static isExtensible(o: any): boolean;
static isFrozen(o: any): boolean;
static isSealed(o: any): boolean;
static keys(o: any): Array<string>;
static preventExtensions(o: any): any;
static seal(o: any): any;
static setPrototypeOf(o: any, proto: ?Object): bool;
static values(object: any): Array<mixed>;
hasOwnProperty(prop: any): boolean;
isPrototypeOf(o: any): boolean;
propertyIsEnumerable(prop: any): boolean;
toLocaleString(): string;
toString(): string;
valueOf(): Object;
[key:any]: any;
}
// Well known Symbols.
declare class $SymbolHasInstance mixins Symbol {}
declare class $SymboIsConcatSpreadable mixins Symbol {}
declare class $SymbolIterator mixins Symbol {}
declare class $SymbolMatch mixins Symbol {}
declare class $SymbolReplace mixins Symbol {}
declare class $SymbolSearch mixins Symbol {}
declare class $SymbolSpecies mixins Symbol {}
declare class $SymbolSplit mixins Symbol {}
declare class $SymbolToPrimitive mixins Symbol {}
declare class $SymbolToStringTag mixins Symbol {}
declare class $SymbolUnscopables mixins Symbol {}
declare class Symbol {
static (value?:any): Symbol;
static for(key: string): Symbol;
static hasInstance: $SymbolHasInstance;
static isConcatSpreadable: $SymboIsConcatSpreadable;
static iterator: string; // polyfill '@@iterator'
static keyFor(sym: Symbol): ?string;
static length: 0;
static match: $SymbolMatch;
static replace: $SymbolReplace;
static search: $SymbolSearch;
static species: $SymbolSpecies;
static split: $SymbolSplit;
static toPrimitive: $SymbolToPrimitive;
static toStringTag: $SymbolToStringTag;
static unscopables: $SymbolUnscopables;
toString(): string;
valueOf(): ?Symbol;
}
// TODO: instance, static
declare class Function {
apply: Function$Prototype$Apply; // (thisArg: any, argArray?: any) => any
bind: Function$Prototype$Bind; // (thisArg: any, ...argArray: Array<any>) => any;
call: Function$Prototype$Call; // (thisArg: any, ...argArray: Array<any>) => any
arguments: any;
caller: Function | null;
length: number;
name: string;
}
declare class Boolean {
constructor(value?: mixed): void;
static (value:any):boolean;
valueOf(): boolean;
toString(): string;
}
declare class Number {
static EPSILON: number;
static MAX_SAFE_INTEGER: number;
static MAX_VALUE: number;
static MIN_SAFE_INTEGER: number;
static MIN_VALUE: number;
static NaN: number;
static NEGATIVE_INFINITY: number;
static POSITIVE_INFINITY: number;
static (value:any):number;
static isFinite(value: any): boolean;
static isInteger(value: any): boolean;
static isNaN(value: any): boolean;
static isSafeInteger(value: any): boolean;
static parseFloat(value: string): number;
static parseInt(value: string, radix?: number): number;
constructor(value?: mixed): void;
toExponential(fractionDigits?: number): string;
toFixed(fractionDigits?: number): string;
toPrecision(precision?: number): string;
toString(radix?: number): string;
valueOf(): number;
}
declare var Math: {
E: number;
LN10: number;
LN2: number;
LOG10E: number;
LOG2E: number;
PI: number;
SQRT1_2: number;
SQRT2: number;
abs(x: number): number;
acos(x: number): number;
acosh(x: number): number;
asin(x: number): number;
asinh(x: number): number;
atan(x: number): number;
atan2(y: number, x: number): number;
atanh(x: number): number;
cbrt(x: number): number;
ceil(x: number): number;
clz32(x: number): number;
cos(x: number): number;
cosh(x: number): number;
exp(x: number): number;
expm1(x: number): number;
floor(x: number): number;
fround(x: number): number;
hypot(...values: Array<number>): number;
imul(y: number, x: number): number;
log(x: number): number;
log10(x: number): number;
log1p(x: number): number;
log2(x: number): number;
max(...values: Array<number>): number;
min(...values: Array<number>): number;
pow(x: number, y: number): number;
random(): number;
round(x: number): number;
sign(x: number): number;
sin(x: number): number;
sinh(x: number): number;
sqrt(x: number): number;
tan(x: number): number;
tanh(x: number): number;
trunc(x: number): number;
};
/* All the Array.prototype methods and properties that don't mutate the array.
*/
declare class $ReadOnlyArray<+T> {
@@iterator(): Iterator<T>;
toLocaleString(): string;
// concat creates a new array
concat<S, Item: $ReadOnlyArray<S> | S>(...items: Array<Item>): Array<T | S>;
entries(): Iterator<[number, T]>;
every(callbackfn: (value: T, index: number, array: $ReadOnlyArray<T>) => any, thisArg?: any): boolean;
filter(callbackfn: typeof Boolean): Array<$NonMaybeType<T>>;
filter(callbackfn: (value: T, index: number, array: $ReadOnlyArray<T>) => any, thisArg?: any): Array<T>;
find(callbackfn: (value: T, index: number, array: $ReadOnlyArray<T>) => any, thisArg?: any): T | void;
findIndex(callbackfn: (value: T, index: number, array: $ReadOnlyArray<T>) => any, thisArg?: any): number;
forEach(callbackfn: (value: T, index: number, array: $ReadOnlyArray<T>) => any, thisArg?: any): void;
includes(searchElement: T, fromIndex?: number): boolean;
indexOf(searchElement: T, fromIndex?: number): number;
join(separator?: string): string;
keys(): Iterator<number>;
lastIndexOf(searchElement: T, fromIndex?: number): number;
map<U>(callbackfn: (value: T, index: number, array: $ReadOnlyArray<T>) => U, thisArg?: any): Array<U>;
reduce(
callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: $ReadOnlyArray<T>) => T,
initialValue: void
): T;
reduce<U>(
callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: $ReadOnlyArray<T>) => U,
initialValue: U
): U;
reduceRight(
callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: $ReadOnlyArray<T>) => T,
initialValue: void
): T;
reduceRight<U>(
callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: $ReadOnlyArray<T>) => U,
initialValue: U
): U;
slice(start?: number, end?: number): Array<T>;
some(callbackfn: (value: T, index: number, array: $ReadOnlyArray<T>) => any, thisArg?: any): boolean;
values(): Iterator<T>;
+[key: number]: T;
length: number;
}
declare class Array<T> extends $ReadOnlyArray<T> {
copyWithin(target: number, start: number, end?: number): T[];
every(callbackfn: (value: T, index: number, array: Array<T>) => any, thisArg?: any): boolean;
fill(value: T, begin?: number, end?: number): Array<T>;
filter(callbackfn: typeof Boolean): Array<$NonMaybeType<T>>;
filter(callbackfn: (value: T, index: number, array: Array<T>) => any, thisArg?: any): Array<T>;
find(callbackfn: (value: T, index: number, array: Array<T>) => any, thisArg?: any): T | void;
findIndex(callbackfn: (value: T, index: number, array: Array<T>) => any, thisArg?: any): number;
forEach(callbackfn: (value: T, index: number, array: Array<T>) => any, thisArg?: any): void;
map<U>(callbackfn: (value: T, index: number, array: Array<T>) => U, thisArg?: any): Array<U>;
pop(): T;
push(...items: Array<T>): number;
reduce(
callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: Array<T>) => T,
initialValue: void
): T;
reduce<U>(
callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: Array<T>) => U,
initialValue: U
): U;
reduceRight(
callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: Array<T>) => T,
initialValue: void
): T;
reduceRight<U>(
callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: Array<T>) => U,
initialValue: U
): U;
reverse(): Array<T>;
shift(): T;
some(callbackfn: (value: T, index: number, array: Array<T>) => any, thisArg?: any): boolean;
sort(compareFn?: (a: T, b: T) => number): Array<T>;
splice(start: number, deleteCount?: number, ...items: Array<T>): Array<T>;
unshift(...items: Array<T>): number;
[key: number]: T;
static (...values:Array<any>): Array<any>;
static isArray(obj: any): bool;
static from<A, B>(iter: Iterable<A>, mapFn: (elem: A, index: number) => B, thisArg?: any): Array<B>;
static from<A>(iter: Iterable<A>, mapFn: void): Array<A>;
static from<A, B>(iter: Iterator<A>, mapFn: (elem: A, index: number) => B, thisArg?: any): Array<B>;
static from<A>(iter: Iterator<A>, mapFn: void): Array<A>;
static from<A>(arrayLike: {length: number}, mapFn: (elem: void, index: number) => A, thisArg?: any): Array<A>;
static from(arrayLike: {length: number}, mapFn: void): Array<void>;
static of(...values: any[]): any[];
}
declare class String {
@@iterator(): Iterator<string>;
anchor(name: string): string;
charAt(pos: number): string;
charCodeAt(index: number): number;
codePointAt(index: number): number;
concat(...strings: Array<string>): string;
constructor(value?: mixed): void;
endsWith(searchString: string, position?: number): boolean;
includes(searchString: string, position?: number): boolean;
indexOf(searchString: string, position?: number): number;
lastIndexOf(searchString: string, position?: number): number;
link(href: string): string;
localeCompare(that: string): number;
match(regexp: string | RegExp): ?Array<string>;
normalize(format?: string): string;
padEnd(targetLength: number, padString?: string): string;
padStart(targetLength: number, padString?: string): string;
repeat(count: number): string;
replace(searchValue: string | RegExp, replaceValue: string | (substring: string, ...args: Array<any>) => string): string;
search(regexp: string | RegExp): number;
slice(start?: number, end?: number): string;
split(separator?: string | RegExp, limit?: number): Array<string>;
startsWith(searchString: string, position?: number): boolean;
substr(from: number, length?: number): string;
substring(start: number, end?: number): string;
toLocaleLowerCase(): string;
toLocaleUpperCase(): string;
toLowerCase(): string;
toUpperCase(): string;
trim(): string;
trimLeft(): string;
trimRight(): string;
valueOf(): string;
toString(): string;
length: number;
static (value:any):string;
static fromCharCode(...codes: Array<number>): string;
static fromCodePoint(...codes: Array<number>): string;
static raw(templateString: string): string;
static raw(callSite: $Shape<{raw: string}>, ...substitutions: any[]): string;
}
type RegExp$flags =
'i' | 'g' | 'm' | 'u' | 'y' |
'ig' | 'im' | 'iu' | 'iy' |
'gi' | 'gm' | 'gu' | 'gy' |
'mi' | 'mg' | 'mu' | 'my' |
'ui' | 'ug' | 'um' | 'uy' |
'yi' | 'yg' | 'ym' | 'yu' |
'igm' | 'igu' | 'igy' |
'img' | 'imu' | 'imy' |
'iug' | 'ium' | 'iuy' |
'iyg' | 'iym' | 'iyu' |
'giy' | 'gim' | 'giu' |
'gmy' | 'gmi' | 'gmu' |
'guy' | 'gui' | 'gum' |
'gyu' | 'gyi' | 'gym' |
'miu' | 'miy' | 'mig' |
'mgu' | 'mgy' | 'mgi' |
'mug' | 'muy' | 'mui' |
'myg' | 'myu' | 'myi' |
'uig' | 'uim' | 'uiy' |
'ugi' | 'ugm' | 'ugy' |
'umi' | 'umg' | 'umy' |
'uyi' | 'uyg' | 'uym' |
'yiu' | 'yig' | 'yim' |
'ygu' | 'ygi' | 'ygm' |
'ymu' | 'ymi' | 'ymg' |
'yum' | 'yui' | 'yug' |
'igmu' | 'igmy' | 'igum' | 'iguy' | 'igym' | 'igyu' |
'imgy' | 'imgu' | 'imuy' | 'imug' | 'imyu' | 'imyg' |
'iugm' | 'iugy' | 'iumg' | 'iumy' | 'iuyg' | 'iuym' |
'iygu' | 'iygm' | 'iymu' | 'iymg' | 'iyum' | 'iyug' |
'giym' | 'giyu' | 'gimy' | 'gimu' | 'giuy' | 'gium' |
'gmyu' | 'gmyi' | 'gmiu' | 'gmiy' | 'gmui' | 'gmuy' |
'guyi' | 'guym' | 'guiy' | 'guim' | 'gumy' | 'gumi' |
'gyum' | 'gyui' | 'gyim' | 'gyiu' | 'gymi' | 'gymu' |
'miuy' | 'miug' | 'miyu' | 'miyg' | 'migu' | 'migy' |
'mgui' | 'mguy' | 'mgyi' | 'mgyu' | 'mgiy' | 'mgiu' |
'mugy' | 'mugi' | 'muyg' | 'muyi' | 'muig' | 'muiy' |
'mygi' | 'mygu' | 'myui' | 'myug' | 'myiu' | 'myig' |
'uigm' | 'uigy' | 'uimg' | 'uimy' | 'uiyg' | 'uiym' |
'ugiy' | 'ugim' | 'ugmy' | 'ugmi' | 'ugym' | 'ugyi' |
'umig' | 'umiy' | 'umgi' | 'umgy' | 'umyi' | 'umyg' |
'uyim' | 'uyig' | 'uygm' | 'uygi' | 'uymg' | 'uymi' |
'yiug' | 'yium' | 'yigu' | 'yigm' | 'yimu' | 'yimg' |
'ygum' | 'ygui' | 'ygim' | 'ygiu' | 'ygmi' | 'ygmu' |
'ymui' | 'ymug' | 'ymiu' | 'ymig' | 'ymgu' | 'ymgi' |
'yumg' | 'yumi' | 'yuig' | 'yuim' | 'yugi' | 'yugm' |
'igmuy' | 'igmyu' | 'igumy' | 'iguym' | 'igymu' | 'igyum' |
'imgyu' | 'imguy' | 'imuyg' | 'imugy' | 'imyug' | 'imygu' |
'iugmy' | 'iugym' | 'iumgy' | 'iumyg' | 'iuygm' | 'iuymg' |
'iygum' | 'iygmu' | 'iymug' | 'iymgu' | 'iyumg' | 'iyugm' |
'giymu' | 'giyum' | 'gimyu' | 'gimuy' | 'giuym' | 'giumy' |
'gmyui' | 'gmyiu' | 'gmiuy' | 'gmiyu' | 'gmuiy' | 'gmuyi' |
'guyim' | 'guymi' | 'guiym' | 'guimy' | 'gumyi' | 'gumiy' |
'gyumi' | 'gyuim' | 'gyimu' | 'gyium' | 'gymiu' | 'gymui' |
'miuyg' | 'miugy' | 'miyug' | 'miygu' | 'miguy' | 'migyu' |
'mguiy' | 'mguyi' | 'mgyiu' | 'mgyui' | 'mgiyu' | 'mgiuy' |
'mugyi' | 'mugiy' | 'muygi' | 'muyig' | 'muigy' | 'muiyg' |
'mygiu' | 'mygui' | 'myuig' | 'myugi' | 'myiug' | 'myigu' |
'uigmy' | 'uigym' | 'uimgy' | 'uimyg' | 'uiygm' | 'uiymg' |
'ugiym' | 'ugimy' | 'ugmyi' | 'ugmiy' | 'ugymi' | 'ugyim' |
'umigy' | 'umiyg' | 'umgiy' | 'umgyi' | 'umyig' | 'umygi' |
'uyimg' | 'uyigm' | 'uygmi' | 'uygim' | 'uymgi' | 'uymig' |
'yiugm' | 'yiumg' | 'yigum' | 'yigmu' | 'yimug' | 'yimgu' |
'ygumi' | 'yguim' | 'ygimu' | 'ygium' | 'ygmiu' | 'ygmui' |
'ymuig' | 'ymugi' | 'ymiug' | 'ymigu' | 'ymgui' | 'ymgiu' |
'yumgi' | 'yumig' | 'yuigm' | 'yuimg' | 'yugim' | 'yugmi';
declare class RegExp {
static (pattern: string | RegExp, flags?: RegExp$flags): RegExp;
compile(): RegExp;
constructor(pattern: string | RegExp, flags?: RegExp$flags): RegExp;
exec(string: string): any;
flags: string;
global: boolean;
ignoreCase: boolean;
lastIndex: number;
multiline: boolean;
source: string;
sticky: bool;
unicode: bool;
test(string: string): boolean;
toString(): string;
}
type Date$LocaleOptions = {
localeMatcher?: string,
timeZone?: string,
hour12?: boolean,
formatMatcher?: string,
weekday?: string,
era?: string,
year?: string,
month?: string,
day?: string,
hour?: string,
minute?: string,
second?: string,
timeZoneName?: string,
};
declare class Date {
// new Date();
// new Date(timestamp);
// new Date(dateString);
// new Date(year, month[, day[, hour[, minute[, second[, millisecond]]]]]);
// TODO: This should specify an overloaded constructor once they're
// supported, instead of a union type for the first argument.
constructor(value?: number | string, month?: number, day?: number, hour?: number, minute?: number, second?: number, millisecond?: number): void;
getDate(): number;
getDay(): number;
getFullYear(): number;
getHours(): number;
getMilliseconds(): number;
getMinutes(): number;
getMonth(): number;
getSeconds(): number;
getTime(): number;
getTimezoneOffset(): number;
getUTCDate(): number;
getUTCDay(): number;
getUTCFullYear(): number;
getUTCHours(): number;
getUTCMilliseconds(): number;
getUTCMinutes(): number;
getUTCMonth(): number;
getUTCSeconds(): number;
setDate(date: number): number;
setFullYear(year: number, month?: number, date?: number): number;
setHours(hours: number, min?: number, sec?: number, ms?: number): number;
setMilliseconds(ms: number): number;
setMinutes(min: number, sec?: number, ms?: number): number;
setMonth(month: number, date?: number): number;
setSeconds(sec: number, ms?: number): number;
setTime(time: number): number;
setUTCDate(date: number): number;
setUTCFullYear(year: number, month?: number, date?: number): number;
setUTCHours(hours: number, min?: number, sec?: number, ms?: number): number;
setUTCMilliseconds(ms: number): number;
setUTCMinutes(min: number, sec?: number, ms?: number): number;
setUTCMonth(month: number, date?: number): number;
setUTCSeconds(sec: number, ms?: number): number;
toDateString(): string;
toISOString(): string;
toJSON(key?: any): string;
toLocaleDateString(locales?: string, options?: Date$LocaleOptions): string;
toLocaleString(locales?: string, options?: Date$LocaleOptions): string;
toLocaleTimeString(locales?: string, options?: Date$LocaleOptions): string;
toTimeString(): string;
toUTCString(): string;
valueOf(): number;
static ():string;
static now(): number;
static parse(s: string): number;
static UTC(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): number;
// multiple indexers not yet supported
[key: $SymbolToPrimitive]: (hint: 'string' | 'default' | 'number') => string | number;
}
declare class CallSite {
getThis(): any;
getTypeName(): string;
getFunction(): ?Function;
getFunctionName(): string;
getMethodName(): string;
getFileName(): ?string;
getLineNumber(): ?number;
getColumnNumber(): ?number;
getEvalOrigin(): ?CallSite;
getScriptNameOrSourceURL(): ?string;
isToplevel(): bool;
isEval(): bool;
isNative(): bool;
isConstructor(): bool;
toString(): string;
}
declare class Error {
static (message?:string):Error;
constructor (message?: mixed): void;
name: string;
message: string;
stack: string;
toString(): string;
// note: microsoft only
description?: string;
number?: number;
// note: mozilla only
fileName?: string;
lineNumber?: number;
columnNumber?: number;
// note: v8 only (node/chrome)
static captureStackTrace(target: Object, constructor?: Function): void;
static stackTraceLimit: number;
static prepareStackTrace: (err: Error, stack: CallSite[]) => mixed;
}
declare class EvalError extends Error {
}
declare class RangeError extends Error {
}
declare class ReferenceError extends Error {
}
declare class SyntaxError extends Error {
}
declare class TypeError extends Error {
}
declare class URIError extends Error {
}
declare class JSON {
static parse(text: string, reviver?: (key: any, value: any) => any): any;
static stringify(
value: any,
replacer?: ?((key: string, value: any) => any) | Array<any>,
space?: string | number
): string;
}
/* Iterable/Iterator/Generator */
type IteratorResult<Yield,Return> =
| { done: true, value?: Return }
| { done: false, value: Yield };
interface $Iterator<+Yield,+Return,-Next> {
@@iterator(): $Iterator<Yield,Return,Next>;
next(value?: Next): IteratorResult<Yield,Return>;
}
type Iterator<+T> = $Iterator<T,void,void>;
interface $Iterable<+Yield,+Return,-Next> {
@@iterator(): $Iterator<Yield,Return,Next>;
}
type Iterable<+T> = $Iterable<T,void,void>;
interface Generator<+Yield,+Return,-Next> {
@@iterator(): $Iterator<Yield,Return,Next>;
next(value?: Next): IteratorResult<Yield,Return>;
return<R>(value: R): IteratorResult<Yield,R|Return>;
throw(error?: any): IteratorResult<Yield,Return>;
}
declare function $iterate<T>(p: Iterable<T>): T;
/* Async Iterable/Iterator/Generator */
interface $AsyncIterator<+Yield,+Return,-Next> {
@@asyncIterator(): $AsyncIterator<Yield,Return,Next>;
next(value?: Next): Promise<IteratorResult<Yield,Return>>;
}
type AsyncIterator<+T> = $AsyncIterator<T,void,void>;
interface $AsyncIterable<+Yield,+Return,-Next> {
@@asyncIterator(): $AsyncIterator<Yield,Return,Next>;
}
type AsyncIterable<+T> = $AsyncIterable<T,void,void>;
interface AsyncGenerator<+Yield,+Return,-Next> {
@@asyncIterator(): $AsyncIterator<Yield,Return,Next>;
next(value?: Next): Promise<IteratorResult<Yield,Return>>;
return<R>(value: R): Promise<IteratorResult<Yield,R|Return>>;
throw(error?: any): Promise<IteratorResult<Yield,Return>>;
}
declare function $asyncIterator<T>(p: AsyncIterable<T>): T;
/* Maps and Sets */
declare class Map<K, V> {
@@iterator(): Iterator<[K, V]>;
constructor(iterable: ?Iterable<[K, V]>): void;
clear(): void;
delete(key: K): boolean;
entries(): Iterator<[K, V]>;
forEach(callbackfn: (value: V, index: K, map: Map<K, V>) => mixed, thisArg?: any): void;
get(key: K): V | void;
has(key: K): boolean;
keys(): Iterator<K>;
set(key: K, value: V): Map<K, V>;
size: number;
values(): Iterator<V>;
// Multiple Indexers not yet supported
[key: $SymbolToStringTag | $SymbolSpecies]: Function;
}
declare class WeakMap<K, V> {
constructor(iterable: ?Iterable<[K, V]>): void;
delete(key: K): boolean;
get(key: K): V | void;
has(key: K): boolean;
set(key: K, value: V): WeakMap<K, V>;
}
declare class Set<T> {
@@iterator(): Iterator<T>;
constructor(iterable: ?Iterable<T>): void;
add(value: T): Set<T>;
clear(): void;
delete(value: T): boolean;
entries(): Iterator<[T, T]>;
forEach(callbackfn: (value: T, index: T, set: Set<T>) => mixed, thisArg?: any): void;
has(value: T): boolean;
keys(): Iterator<T>;
size: number;
values(): Iterator<T>;
[key: $SymbolSpecies]: Function; // This would the Set constructor, can't think of a way to correctly type this
}
declare class WeakSet<T: Object> {
constructor(iterable?: Iterable<T>): void;
add(value: T): WeakSet<T>;
delete(value: T): boolean;
has(value: T): boolean;
}
/* Promises
cf. https://github.com/borisyankov/DefinitelyTyped/blob/master/es6-promises/es6-promises.d.ts
*/
declare class Promise<+R> {
constructor(callback: (
resolve: (result: Promise<R> | R) => void,
reject: (error: any) => void
) => mixed): void;
then<U>(
onFulfill?: (value: R) => Promise<U> | U,
onReject?: (error: any) => Promise<U> | U
): Promise<U>;
catch<U>(
onReject?: (error: any) => Promise<U> | U
): Promise<R | U>;
static resolve<T>(object: Promise<T> | T): Promise<T>;
static reject<T>(error?: any): Promise<T>;
static all<Elem, T:Iterable<Elem>>(promises: T): Promise<$TupleMap<T, typeof $await>>;
static race<T, Elem: Promise<T> | T>(promises: Array<Elem>): Promise<T>;
}
// we use this signature when typing await expressions
declare function $await<T>(p: Promise<T> | T): T;
/* Binary data */
declare class ArrayBuffer {
static isView(arg: mixed): boolean;
constructor(byteLength: number): void;
byteLength: number;
slice(begin: number, end?: number): this;
[key: $SymbolSpecies]: Function; // This would be the constructor, can't think of a way to correctly type this
}
// This is a helper type to simplify the specification, it isn't an interface
// and there are no objects implementing it.
// https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView
type $ArrayBufferView = $TypedArray | DataView;
// The TypedArray intrinsic object is a constructor function, but does not have
// a global name or appear as a property of the global object.
// http://www.ecma-international.org/ecma-262/6.0/#sec-%typedarray%-intrinsic-object
declare class $TypedArray {
static BYTES_PER_ELEMENT: number;
static from(iterable: Iterable<number>, mapFn?: (element: number) => number, thisArg?: any): this;
static of(...values: number[]): this;
constructor(length: number): void;
constructor(typedArray: $TypedArray): void;
constructor(iterable: Iterable<number>): void;
constructor(buffer: ArrayBuffer, byteOffset?: number, length?: number): void;
[index: number]: number;
@@iterator(): Iterator<number>;
buffer: ArrayBuffer;
byteLength: number;
byteOffset: number;
length: number;
copyWithin(target: number, start: number, end?: number): void;
entries(): Iterator<[number, number]>;
every(callback: (value: number, index: number, array: this) => mixed, thisArg?: any): boolean;
fill(value: number, start?: number, end?: number): this;
filter(callback: (value: number, index: number, array: this) => mixed, thisArg?: any): this;
find(callback: (value: number, index: number, array: this) => mixed, thisArg?: any): number | void;
findIndex(callback: (value: number, index: number, array: this) => mixed, thisArg?: any): number;
forEach(callback: (value: number, index: number, array: this) => mixed, thisArg?: any): void;
includes(searchElement: number, fromIndex?: number): boolean;
indexOf(searchElement: number, fromIndex?: number): number; // -1 if not present
join(separator?: string): string;
keys(): Iterator<number>;
lastIndexOf(searchElement: number, fromIndex?: number): number; // -1 if not present
map(callback: (currentValue: number, index: number, array: this) => number, thisArg?: any): this;
reduce(
callback: (previousValue: number, currentValue: number, index: number, array: this) => number,
initialValue: void
): number;
reduce<U>(
callback: (previousValue: U, currentValue: number, index: number, array: this) => U,
initialValue: U
): U;
reduceRight(
callback: (previousValue: number, currentValue: number, index: number, array: this) => number,
initialValue: void
): number;
reduceRight<U>(
callback: (previousValue: U, currentValue: number, index: number, array: this) => U,
initialValue: U
): U;
reverse(): this;
set(array: Array<number> | $TypedArray, offset?: number): void;
slice(begin?: number, end?: number): this;
some(callback: (value: number, index: number, array: this) => mixed, thisArg?: any): boolean;
sort(compare?: (a: number, b: number) => number): void;
subarray(begin?: number, end?: number): this;
values(): Iterator<number>;
}
declare class Int8Array extends $TypedArray {}
declare class Uint8Array extends $TypedArray {}
declare class Uint8ClampedArray extends $TypedArray {}
declare class Int16Array extends $TypedArray {}
declare class Uint16Array extends $TypedArray {}
declare class Int32Array extends $TypedArray {}
declare class Uint32Array extends $TypedArray {}
declare class Float32Array extends $TypedArray {}
declare class Float64Array extends $TypedArray {}
declare class DataView {
constructor(buffer: ArrayBuffer, byteOffset?: number, length?: number): void;
buffer: ArrayBuffer;
byteLength: number;
byteOffset: number;
getInt8(byteOffset: number): number;
getUint8(byteOffset: number): number;
getInt16(byteOffset: number, littleEndian?: boolean): number;
getUint16(byteOffset: number, littleEndian?: boolean): number;
getInt32(byteOffset: number, littleEndian?: boolean): number;
getUint32(byteOffset: number, littleEndian?: boolean): number;
getFloat32(byteOffset: number, littleEndian?: boolean): number;
getFloat64(byteOffset: number, littleEndian?: boolean): number;
setInt8(byteOffset: number, value: number): void;
setUint8(byteOffset: number, value: number): void;
setInt16(byteOffset: number, value: number, littleEndian?: boolean): void;
setUint16(byteOffset: number, value: number, littleEndian?: boolean): void;
setInt32(byteOffset: number, value: number, littleEndian?: boolean): void;
setUint32(byteOffset: number, value: number, littleEndian?: boolean): void;
setFloat32(byteOffset: number, value: number, littleEndian?: boolean): void;
setFloat64(byteOffset: number, value: number, littleEndian?: boolean): void;
}
declare function btoa(rawString: string): string;
declare function atob(encodedString: string): string;
declare function escape(str: string): string;
declare function unescape(str: string): string;
declare function clearInterval(intervalId?: number): void;
declare function clearTimeout(timeoutId?: any): void;
declare function setTimeout(callback: any, ms?: number, ...args: Array<any>): number;
declare function setInterval(callback: any, ms?: number, ...args: Array<any>): number;
/* Reflect API */
declare class Reflect {
static apply(target: Function, thisArg?: any, argumentsList?: Array<any>): any;
static construct(target: Function, argumentsList?: Array<any>, newTarget?: Function): any;
static defineProperty(o: any, p: any, attributes: any): boolean;
static deleteProperty(o: any, p: any): boolean;
static get(o: any, p: any, receiver?: any): any;
static getOwnPropertyDescriptor(o: any, p: any): any;
static getPrototypeOf(o: any): any;
static has(o: any, p: any): boolean;
static isExtensible(o: any): boolean;
static ownKeys(o: any): Array<any>;
static preventExtensions(o: any): boolean;
static set(o: any, p: any, value: any, receiver?: any): boolean;
static setPrototypeOf(o: any, prototype: any): boolean;
}
/* Proxy */
type Proxy$traps<T> = {
getPrototypeOf?: (target: T) => ?Object;
setPrototypeOf?: (target: T, prototype: ?Object) => boolean;
isExtensible?: (target: T) => boolean;
preventExtensions?: (target: T) => boolean;
getOwnPropertyDescriptor?: (target: T, property: string) => void | Object;
defineProperty?: (target: T, property: string, descriptor: Object) => boolean;
has?: (target: T, key: string) => boolean;
get?: (target: T, property: string, receiver: Proxy<T>) => any;
set?: (target: T, property: string, value: any, receiver: Proxy<T>) => boolean;
deleteProperty?: (target: T, property: string) => boolean;
ownKeys?: (target: T) => Array<string>;
apply?: (target: T, context: any, args: Array<any>) => any;
construct?: (target: T, args: Array<any>, newTarget: Function) => Object;
};
type Proxy$revocable<T> = T & {
revoke(): void;
};
declare class Proxy<T> {
constructor(target: T, handler: Proxy$traps<T>): T;
static revocable(target: T, handler: Proxy$traps<T>): Proxy$revocable<T>;
}
/* CommonJS */
declare var global: any;
declare var module: {
exports: any;
require(id: string): any;
id: string;
filename: string;
loaded: boolean;
parent: any;
children: Array<any>;
};
declare var require: {
(id: string): any;
resolve: (id: string) => string;
cache: any;
main: typeof module;
};
declare var exports: any;
/* Commonly available, shared between node and dom */
declare var console: {
assert(condition: mixed, ...data: Array<any>): void;
clear(): void;
count(label: string): void;
debug(...data: Array<any>): void;
dir(...data: Array<any>): void;
dirxml(...data: Array<any>): void;
error(...data: Array<any>): void;
_exception(...data: Array<any>): void;
group(...data: Array<any>): void;
groupCollapsed(...data: Array<any>): void;
groupEnd(): void;
info(...data: Array<any>): void;
log(...data: Array<any>): void;
profile(name: string): void;
profileEnd(): void;
table(tabularData: { [key: string]: any } | Array<{ [key: string]: any }> | Array<Array<any>>): void;
time(label: string): void;
timeEnd(label: string): void;
timeStamp(label?: string): void;
trace(...data: Array<any>): void;
warn(...data: Array<any>): void;
};