UNPKG

24.3 kBTypeScriptView Raw
1// Type definitions for es6-shim v0.31.2
2// Project: https://github.com/paulmillr/es6-shim
3// Definitions by: Ron Buckton <https://github.com/rbuckton>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
6interface IteratorResult<T> {
7 done: boolean;
8 value?: T | undefined;
9}
10
11interface IterableShim<T> {
12 /**
13 * Shim for an ES6 iterable. Not intended for direct use by user code.
14 */
15 "_es6-shim iterator_"(): Iterator<T>;
16}
17
18interface Iterator<T> {
19 next(value?: any): IteratorResult<T>;
20 return?(value?: any): IteratorResult<T>;
21 throw?(e?: any): IteratorResult<T>;
22}
23
24interface IterableIteratorShim<T> extends IterableShim<T>, Iterator<T> {
25 /**
26 * Shim for an ES6 iterable iterator. Not intended for direct use by user code.
27 */
28 "_es6-shim iterator_"(): IterableIteratorShim<T>;
29}
30
31interface StringConstructor {
32 /**
33 * Return the String value whose elements are, in order, the elements in the List elements.
34 * If length is 0, the empty string is returned.
35 */
36 fromCodePoint(...codePoints: number[]): string;
37
38 /**
39 * String.raw is intended for use as a tag function of a Tagged Template String. When called
40 * as such the first argument will be a well formed template call site object and the rest
41 * parameter will contain the substitution values.
42 * @param template A well-formed template string call site representation.
43 * @param substitutions A set of substitution values.
44 */
45 raw(template: TemplateStringsArray, ...substitutions: any[]): string;
46}
47
48interface String {
49 /**
50 * Returns a nonnegative integer Number less than 1114112 (0x110000) that is the code point
51 * value of the UTF-16 encoded code point starting at the string element at position pos in
52 * the String resulting from converting this object to a String.
53 * If there is no element at that position, the result is undefined.
54 * If a valid UTF-16 surrogate pair does not begin at pos, the result is the code unit at pos.
55 */
56 codePointAt(pos: number): number;
57
58 /**
59 * Returns true if searchString appears as a substring of the result of converting this
60 * object to a String, at one or more positions that are
61 * greater than or equal to position; otherwise, returns false.
62 * @param searchString search string
63 * @param position If position is undefined, 0 is assumed, so as to search all of the String.
64 */
65 includes(searchString: string, position?: number): boolean;
66
67 /**
68 * Returns true if the sequence of elements of searchString converted to a String is the
69 * same as the corresponding elements of this object (converted to a String) starting at
70 * endPosition – length(this). Otherwise returns false.
71 */
72 endsWith(searchString: string, endPosition?: number): boolean;
73
74 /**
75 * Returns a String value that is made from count copies appended together. If count is 0,
76 * T is the empty String is returned.
77 * @param count number of copies to append
78 */
79 repeat(count: number): string;
80
81 /**
82 * Returns true if the sequence of elements of searchString converted to a String is the
83 * same as the corresponding elements of this object (converted to a String) starting at
84 * position. Otherwise returns false.
85 */
86 startsWith(searchString: string, position?: number): boolean;
87
88 /**
89 * Returns an <a> HTML anchor element and sets the name attribute to the text value
90 * @param name
91 */
92 anchor(name: string): string;
93
94 /** Returns a <big> HTML element */
95 big(): string;
96
97 /** Returns a <blink> HTML element */
98 blink(): string;
99
100 /** Returns a <b> HTML element */
101 bold(): string;
102
103 /** Returns a <tt> HTML element */
104 fixed(): string;
105
106 /** Returns a <font> HTML element and sets the color attribute value */
107 fontcolor(color: string): string;
108
109 /** Returns a <font> HTML element and sets the size attribute value */
110 fontsize(size: number): string;
111
112 /** Returns a <font> HTML element and sets the size attribute value */
113 fontsize(size: string): string;
114
115 /** Returns an <i> HTML element */
116 italics(): string;
117
118 /** Returns an <a> HTML element and sets the href attribute value */
119 link(url: string): string;
120
121 /** Returns a <small> HTML element */
122 small(): string;
123
124 /** Returns a <strike> HTML element */
125 strike(): string;
126
127 /** Returns a <sub> HTML element */
128 sub(): string;
129
130 /** Returns a <sup> HTML element */
131 sup(): string;
132
133 /**
134 * Shim for an ES6 iterable. Not intended for direct use by user code.
135 */
136 "_es6-shim iterator_"(): IterableIteratorShim<string>;
137}
138
139interface ArrayConstructor {
140 /**
141 * Creates an array from an array-like object.
142 * @param arrayLike An array-like object to convert to an array.
143 * @param mapfn A mapping function to call on every element of the array.
144 * @param thisArg Value of 'this' used to invoke the mapfn.
145 */
146 from<T, U>(arrayLike: ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[];
147
148 /**
149 * Creates an array from an iterable object.
150 * @param iterable An iterable object to convert to an array.
151 * @param mapfn A mapping function to call on every element of the array.
152 * @param thisArg Value of 'this' used to invoke the mapfn.
153 */
154 from<T, U>(iterable: IterableShim<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[];
155
156 /**
157 * Creates an array from an array-like object.
158 * @param arrayLike An array-like object to convert to an array.
159 */
160 from<T>(arrayLike: ArrayLike<T>): T[];
161
162 /**
163 * Creates an array from an iterable object.
164 * @param iterable An iterable object to convert to an array.
165 */
166 from<T>(iterable: IterableShim<T>): T[];
167
168 /**
169 * Returns a new array from a set of elements.
170 * @param items A set of elements to include in the new array object.
171 */
172 of<T>(...items: T[]): T[];
173}
174
175interface Array<T> {
176 /**
177 * Returns the value of the first element in the array where predicate is true, and undefined
178 * otherwise.
179 * @param predicate find calls predicate once for each element of the array, in ascending
180 * order, until it finds one where predicate returns true. If such an element is found, find
181 * immediately returns that element value. Otherwise, find returns undefined.
182 * @param thisArg If provided, it will be used as the this value for each invocation of
183 * predicate. If it is not provided, undefined is used instead.
184 */
185 find(predicate: (value: T, index: number, obj: T[]) => boolean, thisArg?: any): T | undefined;
186
187 /**
188 * Returns the index of the first element in the array where predicate is true, and -1 otherwise.
189 * @param predicate find calls predicate once for each element of the array, in ascending
190 * order, until it finds one where predicate returns true. If such an element is found, find
191 * immediately returns that element value. Otherwise, find returns undefined.
192 * @param thisArg If provided, it will be used as the this value for each invocation of
193 * predicate. If it is not provided, undefined is used instead.
194 */
195 findIndex(predicate: (value: T) => boolean, thisArg?: any): number;
196
197 /**
198 * Returns the this object after filling the section identified by start and end with value
199 * @param value value to fill array section with
200 * @param start index to start filling the array at. If start is negative, it is treated as
201 * length+start where length is the length of the array.
202 * @param end index to stop filling the array at. If end is negative, it is treated as
203 * length+end.
204 */
205 fill(value: T, start?: number, end?: number): T[];
206
207 /**
208 * Returns the this object after copying a section of the array identified by start and end
209 * to the same array starting at position target
210 * @param target If target is negative, it is treated as length+target where length is the
211 * length of the array.
212 * @param start If start is negative, it is treated as length+start. If end is negative, it
213 * is treated as length+end.
214 * @param end If not specified, length of the this object is used as its default value.
215 */
216 copyWithin(target: number, start: number, end?: number): T[];
217
218 /**
219 * Returns an array of key, value pairs for every entry in the array
220 */
221 entries(): IterableIteratorShim<[number, T]>;
222
223 /**
224 * Returns an list of keys in the array
225 */
226 keys(): IterableIteratorShim<number>;
227
228 /**
229 * Returns an list of values in the array
230 */
231 values(): IterableIteratorShim<T>;
232
233 /**
234 * Shim for an ES6 iterable. Not intended for direct use by user code.
235 */
236 "_es6-shim iterator_"(): IterableIteratorShim<T>;
237}
238
239interface NumberConstructor {
240 /**
241 * The value of Number.EPSILON is the difference between 1 and the smallest value greater than 1
242 * that is representable as a Number value, which is approximately:
243 * 2.2204460492503130808472633361816 x 10‍−‍16.
244 */
245 EPSILON: number;
246
247 /**
248 * Returns true if passed value is finite.
249 * Unlike the global isFininte, Number.isFinite doesn't forcibly convert the parameter to a
250 * number. Only finite values of the type number, result in true.
251 * @param number A numeric value.
252 */
253 isFinite(number: number): boolean;
254
255 /**
256 * Returns true if the value passed is an integer, false otherwise.
257 * @param number A numeric value.
258 */
259 isInteger(number: number): boolean;
260
261 /**
262 * Returns a Boolean value that indicates whether a value is the reserved value NaN (not a
263 * number). Unlike the global isNaN(), Number.isNaN() doesn't forcefully convert the parameter
264 * to a number. Only values of the type number, that are also NaN, result in true.
265 * @param number A numeric value.
266 */
267 isNaN(number: number): boolean;
268
269 /**
270 * Returns true if the value passed is a safe integer.
271 * @param number A numeric value.
272 */
273 isSafeInteger(number: number): boolean;
274
275 /**
276 * The value of the largest integer n such that n and n + 1 are both exactly representable as
277 * a Number value.
278 * The value of Number.MIN_SAFE_INTEGER is 9007199254740991 2^53 − 1.
279 */
280 MAX_SAFE_INTEGER: number;
281
282 /**
283 * The value of the smallest integer n such that n and n − 1 are both exactly representable as
284 * a Number value.
285 * The value of Number.MIN_SAFE_INTEGER is −9007199254740991 (−(2^53 − 1)).
286 */
287 MIN_SAFE_INTEGER: number;
288
289 /**
290 * Converts a string to a floating-point number.
291 * @param string A string that contains a floating-point number.
292 */
293 parseFloat(string: string): number;
294
295 /**
296 * Converts A string to an integer.
297 * @param s A string to convert into a number.
298 * @param radix A value between 2 and 36 that specifies the base of the number in numString.
299 * If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal.
300 * All other strings are considered decimal.
301 */
302 parseInt(string: string, radix?: number): number;
303}
304
305interface ObjectConstructor {
306 /**
307 * Copy the values of all of the enumerable own properties from one or more source objects to a
308 * target object. Returns the target object.
309 * @param target The target object to copy to.
310 * @param sources One or more source objects to copy properties from.
311 */
312 assign(target: any, ...sources: any[]): any;
313
314 /**
315 * Returns true if the values are the same value, false otherwise.
316 * @param value1 The first value.
317 * @param value2 The second value.
318 */
319 is(value1: any, value2: any): boolean;
320
321 /**
322 * Sets the prototype of a specified object o to object proto or null. Returns the object o.
323 * @param o The object to change its prototype.
324 * @param proto The value of the new prototype or null.
325 * @remarks Requires `__proto__` support.
326 */
327 setPrototypeOf(o: any, proto: any): any;
328}
329
330interface RegExp {
331 /**
332 * Returns a string indicating the flags of the regular expression in question. This field is read-only.
333 * The characters in this string are sequenced and concatenated in the following order:
334 *
335 * - "g" for global
336 * - "i" for ignoreCase
337 * - "m" for multiline
338 * - "u" for unicode
339 * - "y" for sticky
340 *
341 * If no flags are set, the value is the empty string.
342 */
343 flags: string;
344}
345
346interface Math {
347 /**
348 * Returns the number of leading zero bits in the 32-bit binary representation of a number.
349 * @param x A numeric expression.
350 */
351 clz32(x: number): number;
352
353 /**
354 * Returns the result of 32-bit multiplication of two numbers.
355 * @param x First number
356 * @param y Second number
357 */
358 imul(x: number, y: number): number;
359
360 /**
361 * Returns the sign of the x, indicating whether x is positive, negative or zero.
362 * @param x The numeric expression to test
363 */
364 sign(x: number): number;
365
366 /**
367 * Returns the base 10 logarithm of a number.
368 * @param x A numeric expression.
369 */
370 log10(x: number): number;
371
372 /**
373 * Returns the base 2 logarithm of a number.
374 * @param x A numeric expression.
375 */
376 log2(x: number): number;
377
378 /**
379 * Returns the natural logarithm of 1 + x.
380 * @param x A numeric expression.
381 */
382 log1p(x: number): number;
383
384 /**
385 * Returns the result of (e^x - 1) of x (e raised to the power of x, where e is the base of
386 * the natural logarithms).
387 * @param x A numeric expression.
388 */
389 expm1(x: number): number;
390
391 /**
392 * Returns the hyperbolic cosine of a number.
393 * @param x A numeric expression that contains an angle measured in radians.
394 */
395 cosh(x: number): number;
396
397 /**
398 * Returns the hyperbolic sine of a number.
399 * @param x A numeric expression that contains an angle measured in radians.
400 */
401 sinh(x: number): number;
402
403 /**
404 * Returns the hyperbolic tangent of a number.
405 * @param x A numeric expression that contains an angle measured in radians.
406 */
407 tanh(x: number): number;
408
409 /**
410 * Returns the inverse hyperbolic cosine of a number.
411 * @param x A numeric expression that contains an angle measured in radians.
412 */
413 acosh(x: number): number;
414
415 /**
416 * Returns the inverse hyperbolic sine of a number.
417 * @param x A numeric expression that contains an angle measured in radians.
418 */
419 asinh(x: number): number;
420
421 /**
422 * Returns the inverse hyperbolic tangent of a number.
423 * @param x A numeric expression that contains an angle measured in radians.
424 */
425 atanh(x: number): number;
426
427 /**
428 * Returns the square root of the sum of squares of its arguments.
429 * @param values Values to compute the square root for.
430 * If no arguments are passed, the result is +0.
431 * If there is only one argument, the result is the absolute value.
432 * If any argument is +Infinity or -Infinity, the result is +Infinity.
433 * If any argument is NaN, the result is NaN.
434 * If all arguments are either +0 or −0, the result is +0.
435 */
436 hypot(...values: number[]): number;
437
438 /**
439 * Returns the integral part of the a numeric expression, x, removing any fractional digits.
440 * If x is already an integer, the result is x.
441 * @param x A numeric expression.
442 */
443 trunc(x: number): number;
444
445 /**
446 * Returns the nearest single precision float representation of a number.
447 * @param x A numeric expression.
448 */
449 fround(x: number): number;
450
451 /**
452 * Returns an implementation-dependent approximation to the cube root of number.
453 * @param x A numeric expression.
454 */
455 cbrt(x: number): number;
456}
457
458interface PromiseLike<T> {
459 /**
460 * Attaches callbacks for the resolution and/or rejection of the Promise.
461 * @param onfulfilled The callback to execute when the Promise is resolved.
462 * @param onrejected The callback to execute when the Promise is rejected.
463 * @returns A Promise for the completion of which ever callback is executed.
464 */
465 then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): PromiseLike<TResult>;
466 then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): PromiseLike<TResult>;
467}
468
469/**
470 * Represents the completion of an asynchronous operation
471 */
472interface Promise<T> {
473 /**
474 * Attaches callbacks for the resolution and/or rejection of the Promise.
475 * @param onfulfilled The callback to execute when the Promise is resolved.
476 * @param onrejected The callback to execute when the Promise is rejected.
477 * @returns A Promise for the completion of which ever callback is executed.
478 */
479 then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): Promise<TResult>;
480 then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): Promise<TResult>;
481
482 /**
483 * Attaches a callback for only the rejection of the Promise.
484 * @param onrejected The callback to execute when the Promise is rejected.
485 * @returns A Promise for the completion of the callback.
486 */
487 catch(onrejected?: (reason: any) => T | PromiseLike<T>): Promise<T>;
488 catch(onrejected?: (reason: any) => void): Promise<T>;
489}
490
491interface PromiseConstructor {
492 /**
493 * A reference to the prototype.
494 */
495 prototype: Promise<any>;
496
497 /**
498 * Creates a new Promise.
499 * @param executor A callback used to initialize the promise. This callback is passed two arguments:
500 * a resolve callback used to resolve the promise with a value or the result of another promise,
501 * and a reject callback used to reject the promise with a provided reason or error.
502 */
503 new <T>(executor: (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
504
505 /**
506 * Creates a Promise that is resolved with an array of results when all of the provided Promises
507 * resolve, or rejected when any Promise is rejected.
508 * @param values An array of Promises.
509 * @returns A new Promise.
510 */
511 all<T>(values: IterableShim<T | PromiseLike<T>>): Promise<T[]>;
512
513 /**
514 * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
515 * or rejected.
516 * @param values An array of Promises.
517 * @returns A new Promise.
518 */
519 race<T>(values: IterableShim<T | PromiseLike<T>>): Promise<T>;
520
521 /**
522 * Creates a new rejected promise for the provided reason.
523 * @param reason The reason the promise was rejected.
524 * @returns A new rejected Promise.
525 */
526 reject(reason: any): Promise<void>;
527
528 /**
529 * Creates a new rejected promise for the provided reason.
530 * @param reason The reason the promise was rejected.
531 * @returns A new rejected Promise.
532 */
533 reject<T>(reason: any): Promise<T>;
534
535 /**
536 * Creates a new resolved promise for the provided value.
537 * @param value A promise.
538 * @returns A promise whose internal state matches the provided promise.
539 */
540 resolve<T>(value: T | PromiseLike<T>): Promise<T>;
541
542 /**
543 * Creates a new resolved promise .
544 * @returns A resolved promise.
545 */
546 resolve(): Promise<void>;
547}
548
549declare var Promise: PromiseConstructor;
550
551interface Map<K, V> {
552 clear(): void;
553 delete(key: K): boolean;
554 forEach(callbackfn: (value: V, index: K, map: Map<K, V>) => void, thisArg?: any): void;
555 get(key: K): V | undefined;
556 has(key: K): boolean;
557 set(key: K, value: V): Map<K, V>;
558 size: number;
559 entries(): IterableIteratorShim<[K, V]>;
560 keys(): IterableIteratorShim<K>;
561 values(): IterableIteratorShim<V>;
562}
563
564interface MapConstructor {
565 new <K, V>(): Map<K, V>;
566 new <K, V>(iterable: IterableShim<[K, V]>): Map<K, V>;
567 prototype: Map<any, any>;
568}
569
570declare var Map: MapConstructor;
571
572interface Set<T> {
573 add(value: T): Set<T>;
574 clear(): void;
575 delete(value: T): boolean;
576 forEach(callbackfn: (value: T, index: T, set: Set<T>) => void, thisArg?: any): void;
577 has(value: T): boolean;
578 size: number;
579 entries(): IterableIteratorShim<[T, T]>;
580 keys(): IterableIteratorShim<T>;
581 values(): IterableIteratorShim<T>;
582 '_es6-shim iterator_'(): IterableIteratorShim<T>;
583}
584
585interface SetConstructor {
586 new <T>(): Set<T>;
587 new <T>(iterable: IterableShim<T>): Set<T>;
588 prototype: Set<any>;
589}
590
591declare var Set: SetConstructor;
592
593interface WeakMap<K extends object, V> {
594 delete(key: K): boolean;
595 get(key: K): V | undefined;
596 has(key: K): boolean;
597 set(key: K, value: V): WeakMap<K, V>;
598}
599
600interface WeakMapConstructor {
601 new <K extends object, V>(): WeakMap<K, V>;
602 new <K extends object, V>(iterable: IterableShim<[K, V]>): WeakMap<K, V>;
603 prototype: WeakMap<any, any>;
604}
605
606declare var WeakMap: WeakMapConstructor;
607
608interface WeakSet<T> {
609 add(value: T): WeakSet<T>;
610 delete(value: T): boolean;
611 has(value: T): boolean;
612}
613
614interface WeakSetConstructor {
615 new <T>(): WeakSet<T>;
616 new <T>(iterable: IterableShim<T>): WeakSet<T>;
617 prototype: WeakSet<any>;
618}
619
620declare var WeakSet: WeakSetConstructor;
621
622declare namespace Reflect {
623 function apply(target: Function, thisArgument: any, argumentsList: ArrayLike<any>): any;
624 function construct(target: Function, argumentsList: ArrayLike<any>): any;
625 function defineProperty(target: any, propertyKey: PropertyKey, attributes: PropertyDescriptor): boolean;
626 function deleteProperty(target: any, propertyKey: PropertyKey): boolean;
627 function enumerate(target: any): IterableIteratorShim<any>;
628 function get(target: any, propertyKey: PropertyKey, receiver?: any): any;
629 function getOwnPropertyDescriptor(target: any, propertyKey: PropertyKey): PropertyDescriptor;
630 function getPrototypeOf(target: any): any;
631 function has(target: any, propertyKey: PropertyKey): boolean;
632 function isExtensible(target: any): boolean;
633 function ownKeys(target: any): PropertyKey[];
634 function preventExtensions(target: any): boolean;
635 function set(target: any, propertyKey: PropertyKey, value: any, receiver?: any): boolean;
636 function setPrototypeOf(target: any, proto: any): boolean;
637}
638
639declare module "es6-shim" {
640 var String: StringConstructor;
641 var Array: ArrayConstructor;
642 var Number: NumberConstructor;
643 var Math: Math;
644 var Object: ObjectConstructor;
645 var Map: MapConstructor;
646 var Set: SetConstructor;
647 var WeakMap: WeakMapConstructor;
648 var WeakSet: WeakSetConstructor;
649 var Promise: PromiseConstructor;
650 namespace Reflect {
651 function apply(target: Function, thisArgument: any, argumentsList: ArrayLike<any>): any;
652 function construct(target: Function, argumentsList: ArrayLike<any>): any;
653 function defineProperty(target: any, propertyKey: PropertyKey, attributes: PropertyDescriptor): boolean;
654 function deleteProperty(target: any, propertyKey: PropertyKey): boolean;
655 function enumerate(target: any): Iterator<any>;
656 function get(target: any, propertyKey: PropertyKey, receiver?: any): any;
657 function getOwnPropertyDescriptor(target: any, propertyKey: PropertyKey): PropertyDescriptor;
658 function getPrototypeOf(target: any): any;
659 function has(target: any, propertyKey: PropertyKey): boolean;
660 function isExtensible(target: any): boolean;
661 function ownKeys(target: any): PropertyKey[];
662 function preventExtensions(target: any): boolean;
663 function set(target: any, propertyKey: PropertyKey, value: any, receiver?: any): boolean;
664 function setPrototypeOf(target: any, proto: any): boolean;
665 }
666}
667
\No newline at end of file