diff --git a/.flowconfig b/.flowconfig index ff14bd9da5e..09c47785c59 100644 --- a/.flowconfig +++ b/.flowconfig @@ -37,6 +37,7 @@ module.use_strict=true babel_loose_array_spread=true experimental.const_params=true include_warnings=true +no_flowlib=true [version] ^0.142.0 diff --git a/.nycrc.yml b/.nycrc.yml index 91de70cb7bb..8d2d41e9016 100644 --- a/.nycrc.yml +++ b/.nycrc.yml @@ -2,7 +2,6 @@ all: true include: - 'src/' exclude: - - 'src/polyfills' - '**/*-fuzz.js' - '**/*.d.ts' clean: true diff --git a/.prettierignore b/.prettierignore index 475f5e22fd3..f15fd048380 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,5 @@ +/flow-typed + # Copied from '.gitignore', please keep it in sync. /.eslintcache /node_modules diff --git a/flow-typed/core.js b/flow-typed/core.js index 44ef9c1fd07..e7c0da6064a 100644 --- a/flow-typed/core.js +++ b/flow-typed/core.js @@ -1,5 +1,2564 @@ -// Various hacks to compensate for outdated Flow core definitions +// Various hacks applied to Flow core definitions +// All hacks are marked with '// graphql-js HACK' comment -declare class Symbol extends Symbol { - static asyncIterator: string; // polyfill '@@asyncIterator' +/* cSpell:disable */ + +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * Copyright (c) Microsoft Corporation. All rights reserved. + * Modifications copyright (C) Facebook, Inc. and its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at http://www.apache.org/licenses/LICENSE-2.0 + * THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED + * WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, + * MERCHANTABLITY OR NON-INFRINGEMENT. + * See the Apache Version 2.0 License for specific language governing permissions + * and limitations under the License. + */ +// @lint-ignore-every LICENSELINT + +declare var NaN: number; +declare var Infinity: number; +declare var undefined: void; + +/** + * Converts a string to an integer. + * @param string A string to convert into a number. + * @param radix A value between 2 and 36 that specifies the base of the number in numString. + * If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal. + * All other strings are considered decimal. + */ +declare function parseInt(string: mixed, radix?: number): number; +/** + * Converts a string to a floating-point number. + * @param string A string that contains a floating-point number. + */ +declare function parseFloat(string: mixed): number; + +/** + * Returns a boolean value that indicates whether a value is the reserved value NaN (not a number). + * @param number A numeric value. + */ +declare function isNaN(number: mixed): boolean; +/** + * Determines whether a supplied number is finite. + * @param number Any numeric value. + */ +declare function isFinite(number: mixed): boolean; +/** + * Gets the unencoded version of an encoded Uniform Resource Identifier (URI). + * @param encodedURI A value representing an encoded URI. + */ +declare function decodeURI(encodedURI: string): string; +/** + * Gets the unencoded version of an encoded component of a Uniform Resource Identifier (URI). + * @param encodedURIComponent A value representing an encoded URI component. + */ +declare function decodeURIComponent(encodedURIComponent: string): string; +/** + * Encodes a text string as a valid Uniform Resource Identifier (URI) + * @param uri A value representing an encoded URI. + */ +declare function encodeURI(uri: string): string; +/** + * Encodes a text string as a valid component of a Uniform Resource Identifier (URI). + * @param uriComponent A value representing an encoded URI component. + */ +declare function encodeURIComponent(uriComponent: string): string; + +type PropertyDescriptor = { + enumerable?: boolean, + configurable?: boolean, + writable?: boolean, + value?: T, + get?: () => T, + set?: (value: T) => void, + ... +}; + +type PropertyDescriptorMap = { [s: string]: PropertyDescriptor, ... } + +type $NotNullOrVoid = +| number +| string +| boolean +| {...} +| $ReadOnlyArray; + +declare class Object { + static (o: ?void): { [key: any]: any, ... }; + static (o: boolean): Boolean; + static (o: number): Number; + static (o: string): String; + static (o: T): T; + /** + * Copy the values of all of the enumerable own properties from one or more source objects to a + * target object. Returns the target object. + * @param target The target object to copy to. + * @param sources The source object from which to copy properties. + */ + static assign: Object$Assign; + /** + * Creates an object that has the specified prototype, and that optionally contains specified properties. + * @param o Object to use as a prototype. May be null + * @param properties JavaScript object that contains one or more property descriptors. + */ + static create(o: any, properties?: PropertyDescriptorMap): any; // compiler magic + /** + * Adds one or more properties to an object, and/or modifies attributes of existing properties. + * @param o Object on which to add or modify the properties. This can be a native JavaScript object or a DOM object. + * @param properties JavaScript object that contains one or more descriptor objects. Each descriptor object describes a data property or an accessor property. + */ + static defineProperties(o: any, properties: PropertyDescriptorMap): any; + /** + * Adds a property to an object, or modifies attributes of an existing property. + * @param o Object on which to add or modify the property. This can be a native JavaScript object (that is, a user-defined object or a built in object) or a DOM object. + * @param p The property name. + * @param attributes Descriptor for the property. It can be for a data property or an accessor property. + */ + static defineProperty(o: any, p: any, attributes: PropertyDescriptor): any; + /** + * Returns an array of key/values of the enumerable properties of an object + * @param object Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object. + */ + static entries(obj: { [key: string]: T, __proto__: null }): Array<[string, T]>; // graphql-js HACK + static entries(object: $NotNullOrVoid): Array<[string, mixed]>; + /** + * Prevents the modification of existing property attributes and values, and prevents the addition of new properties. + * @param o Object on which to lock the attributes. + */ + static freeze(o: T): T; + /** + * Returns an object created by key-value entries for properties and methods + * @param entries An iterable object that contains key-value entries for properties and methods. + */ + static fromEntries(entries: Iterable<[K, V] | { + '0': K, + '1': V, + ... + }>): { [K]: V, ... }; + + /** + * Gets the own property descriptor of the specified object. + * An own property descriptor is one that is defined directly on the object and is not inherited from the object's prototype. + * @param o Object that contains the property. + * @param p Name of the property. + */ + static getOwnPropertyDescriptor(o: $NotNullOrVoid, p: any): PropertyDescriptor | void; + /** + * Gets the own property descriptors of the specified object. + * An own property descriptor is one that is defined directly on the object and is not inherited from the object's prototype. + * @param o Object that contains the properties. + */ + static getOwnPropertyDescriptors(o: {...}): PropertyDescriptorMap; + // This is documentation only. Object.getOwnPropertyNames is implemented in OCaml code + // https://github.com/facebook/flow/blob/8ac01bc604a6827e6ee9a71b197bb974f8080049/src/typing/statement.ml#L6308 + /** + * Returns the names of the own properties of an object. The own properties of an object are those that are defined directly + * on that object, and are not inherited from the object's prototype. The properties of an object include both fields (objects) and functions. + * @param o Object that contains the own properties. + */ + static getOwnPropertyNames(o: $NotNullOrVoid): Array; + /** + * Returns an array of all symbol properties found directly on object o. + * @param o Object to retrieve the symbols from. + */ + static getOwnPropertySymbols(o: $NotNullOrVoid): Array; + /** + * Returns the prototype of an object. + * @param o The object that references the prototype. + */ + static getPrototypeOf: Object$GetPrototypeOf; + /** + * Returns true if the values are the same value, false otherwise. + * @param a The first value. + * @param b The second value. + */ + static is(a: T, b: T): boolean; + /** + * Returns a value that indicates whether new properties can be added to an object. + * @param o Object to test. + */ + static isExtensible(o: $NotNullOrVoid): boolean; + /** + * Returns true if existing property attributes and values cannot be modified in an object, and new properties cannot be added to the object. + * @param o Object to test. + */ + static isFrozen(o: $NotNullOrVoid): boolean; + static isSealed(o: $NotNullOrVoid): boolean; + // This is documentation only. Object.keys is implemented in OCaml code. + // https://github.com/facebook/flow/blob/8ac01bc604a6827e6ee9a71b197bb974f8080049/src/typing/statement.ml#L6308 + /** + * Returns the names of the enumerable string properties and methods of an object. + * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object. + */ + static keys(o: $NotNullOrVoid): Array; + /** + * Prevents the addition of new properties to an object. + * @param o Object to make non-extensible. + */ + static preventExtensions(o: T): T; + /** + * Prevents the modification of attributes of existing properties, and prevents the addition of new properties. + * @param o Object on which to lock the attributes. + */ + static seal(o: T): T; + /** + * Sets the prototype of a specified object o to object proto or null. Returns the object o. + * @param o The object to change its prototype. + * @param proto The value of the new prototype or null. + */ + static setPrototypeOf(o: T, proto: ?{...}): T; + /** + * Returns an array of values of the enumerable properties of an object + * @param object Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object. + */ + static values(obj: { [key: string]: T, __proto__: null }): Array; // graphql-js HACK + static values(object: $NotNullOrVoid): Array; + /** + * Determines whether an object has a property with the specified name. + * @param prop A property name. + */ + hasOwnProperty(prop: mixed): boolean; + /** + * Determines whether an object exists in another object's prototype chain. + * @param o Another object whose prototype chain is to be checked. + */ + isPrototypeOf(o: mixed): boolean; + /** + * Determines whether a specified property is enumerable. + * @param prop A property name. + */ + propertyIsEnumerable(prop: mixed): boolean; + /** Returns a date converted to a string using the current locale. */ + toLocaleString(): string; + /** Returns a string representation of an object. */ + toString(): string; + /** Returns the primitive value of the specified object. */ + valueOf(): mixed; +} + +// Well known Symbols. +declare opaque type $SymbolHasInstance: symbol; +declare opaque type $SymboIsConcatSpreadable: symbol; +declare opaque type $SymbolIterator: symbol; +declare opaque type $SymbolMatch: symbol; +declare opaque type $SymbolMatchAll: symbol; +declare opaque type $SymbolReplace: symbol; +declare opaque type $SymbolSearch: symbol; +declare opaque type $SymbolSpecies: symbol; +declare opaque type $SymbolSplit: symbol; +declare opaque type $SymbolToPrimitive: symbol; +declare opaque type $SymbolToStringTag: symbol; +declare opaque type $SymbolUnscopables: symbol; + +declare class Symbol { + static asyncIterator: string; // graphql-js HACK + + /** + * Returns a new unique Symbol value. + * @param value Description of the new Symbol object. + */ + static (value?:any): symbol; + /** + * Returns a Symbol object from the global symbol registry matching the given key if found. + * Otherwise, returns a new symbol with this key. + * @param key key to search for. + */ + static for(key: string): symbol; + /** + * Expose the [[Description]] internal slot of a symbol directly. + */ + +description: string | void; + /** + * A method that determines if a constructor object recognizes an object as one of the + * constructor's instances. Called by the semantics of the instanceof operator. + */ + static hasInstance: $SymbolHasInstance; + /** + * A Boolean value that if true indicates that an object should flatten to its array elements + * by Array.prototype.concat. + */ + static isConcatSpreadable: $SymboIsConcatSpreadable; + static iterator: string; // polyfill '@@iterator' + /** + * Returns a key from the global symbol registry matching the given Symbol if found. + * Otherwise, returns a undefined. + * @param sym Symbol to find the key for. + */ + static keyFor(sym: symbol): ?string; + static length: 0; + /** + * A regular expression method that matches the regular expression against a string. Called + * by the String.prototype.match method. + */ + static match: $SymbolMatch; + /** + * A regular expression method that matches the regular expression against a string. Called + * by the String.prototype.matchAll method. + */ + static matchAll: $SymbolMatchAll; + /** + * A regular expression method that replaces matched substrings of a string. Called by the + * String.prototype.replace method. + */ + static replace: $SymbolReplace; + /** + * A regular expression method that returns the index within a string that matches the + * regular expression. Called by the String.prototype.search method. + */ + static search: $SymbolSearch; + /** + * A function valued property that is the constructor function that is used to create + * derived objects. + */ + static species: $SymbolSpecies; + /** + * A regular expression method that splits a string at the indices that match the regular + * expression. Called by the String.prototype.split method. + */ + static split: $SymbolSplit; + /** + * A method that converts an object to a corresponding primitive value. + * Called by the ToPrimitive abstract operation. + */ + static toPrimitive: $SymbolToPrimitive; + /** + * A String value that is used in the creation of the default string description of an object. + * Called by the built-in method Object.prototype.toString. + */ + static toStringTag: $SymbolToStringTag; + /** + * An Object whose own property names are property names that are excluded from the 'with' + * environment bindings of the associated objects. + */ + static unscopables: $SymbolUnscopables; + toString(): string; + valueOf(): ?symbol; +} + +// TODO: instance, static +declare class Function { + proto apply: Function$Prototype$Apply; // (thisArg: any, argArray?: any) => any + proto bind: Function$Prototype$Bind; // (thisArg: any, ...argArray: Array) => any; + proto call: Function$Prototype$Call; // (thisArg: any, ...argArray: Array) => any + /** Returns a string representation of a function. */ + toString(): string; + arguments: any; + caller: any | null; + length: number; + /** + * Returns the name of the function. Function names are read-only and can not be changed. + */ + name: string; +} + +declare class Boolean { + constructor(value?: mixed): void; + static (value:mixed):boolean; + /** Returns the primitive value of the specified object. */ + valueOf(): boolean; + toString(): string; +} + +/** An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers. */ +declare class Number { + /** + * The value of Number.EPSILON is the difference between 1 and the smallest value greater than 1 + * that is representable as a Number value, which is approximately: + * 2.2204460492503130808472633361816 x 10^-16. + */ + static EPSILON: number; + /** + * The value of the largest integer n such that n and n + 1 are both exactly representable as + * a Number value. + * The value of Number.MAX_SAFE_INTEGER is 9007199254740991 2^53 - 1. + */ + static MAX_SAFE_INTEGER: number; + /** The largest number that can be represented in JavaScript. Equal to approximately 1.79E+308. */ + static MAX_VALUE: number; + /** + * The value of the smallest integer n such that n and n - 1 are both exactly representable as + * a Number value. + * The value of Number.MIN_SAFE_INTEGER is -9007199254740991 (-(2^53 - 1)). + */ + static MIN_SAFE_INTEGER: number; + /** The closest number to zero that can be represented in JavaScript. Equal to approximately 5.00E-324. */ + static MIN_VALUE: number; + /** + * A value that is not a number. + * In equality comparisons, NaN does not equal any value, including itself. To test whether a value is equivalent to NaN, use the isNaN function. + */ + static NaN: number; + /** + * A value that is less than the largest negative number that can be represented in JavaScript. + * JavaScript displays NEGATIVE_INFINITY values as -infinity. + */ + static NEGATIVE_INFINITY: number; + /** + * A value greater than the largest number that can be represented in JavaScript. + * JavaScript displays POSITIVE_INFINITY values as infinity. + */ + static POSITIVE_INFINITY: number; + static (value:mixed):number; + /** + * Returns true if passed value is finite. + * Unlike the global isFinite, Number.isFinite doesn't forcibly convert the parameter to a + * number. Only finite values of the type number, result in true. + * @param value A numeric value. + */ + static isFinite(value: mixed): boolean; + /** + * Returns true if the value passed is an integer, false otherwise. + * @param value A numeric value. + */ + static isInteger(value: mixed): boolean; + /** + * Returns a Boolean value that indicates whether a value is the reserved value NaN (not a + * number). Unlike the global isNaN(), Number.isNaN() doesn't forcefully convert the parameter + * to a number. Only values of the type number, that are also NaN, result in true. + * @param value A numeric value. + */ + static isNaN(value: mixed): boolean; + /** + * Returns true if the value passed is a safe integer. + * @param value A numeric value. + */ + static isSafeInteger(value: mixed): boolean; + /** + * Converts a string to a floating-point number. + * @param value A string that contains a floating-point number. + */ + static parseFloat(value: string): number; + /** + * Converts A string to an integer. + * @param value A string to convert into a number. + * @param radix A value between 2 and 36 that specifies the base of the number in numString. + * If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal. + * All other strings are considered decimal. + */ + static parseInt(value: string, radix?: number): number; + constructor(value?: mixed): void; + /** + * Returns a string containing a number represented in exponential notation. + * @param fractionDigits Number of digits after the decimal point. Must be in the range 0 - 20, inclusive. + */ + toExponential(fractionDigits?: number): string; + /** + * Returns a string representing a number in fixed-point notation. + * @param fractionDigits Number of digits after the decimal point. Must be in the range 0 - 20, inclusive. + */ + toFixed(fractionDigits?: number): string; + /** + * Converts a number to a string by using the current or specified locale. + * @param locales A locale string or array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. + * @param options An object that contains one or more properties that specify comparison options. + */ + toLocaleString(locales?: string | Array, options?: Intl$NumberFormatOptions): string; + /** + * Returns a string containing a number represented either in exponential or fixed-point notation with a specified number of digits. + * @param precision Number of significant digits. Must be in the range 1 - 21, inclusive. + */ + toPrecision(precision?: number): string; + /** + * Returns a string representation of an object. + * @param radix Specifies a radix for converting numeric values to strings. This value is only used for numbers. + */ + toString(radix?: number): string; + /** Returns the primitive value of the specified object. */ + valueOf(): number; +} + +/** An intrinsic object that provides basic mathematics functionality and constants. */ +declare var Math: { + /** The mathematical constant e. This is Euler's number, the base of natural logarithms. */ + E: number, + /** The natural logarithm of 10. */ + LN10: number, + /** The natural logarithm of 2. */ + LN2: number, + /** The base-10 logarithm of e. */ + LOG10E: number, + /** The base-2 logarithm of e. */ + LOG2E: number, + /** Pi. This is the ratio of the circumference of a circle to its diameter. */ + PI: number, + /** The square root of 0.5, or, equivalently, one divided by the square root of 2. */ + SQRT1_2: number, + /** The square root of 2. */ + SQRT2: number, + /** + * Returns the absolute value of a number (the value without regard to whether it is positive or negative). + * For example, the absolute value of -5 is the same as the absolute value of 5. + * @param x A numeric expression for which the absolute value is needed. + */ + abs(x: number): number, + /** + * Returns the arc cosine (or inverse cosine) of a number. + * @param x A numeric expression. + */ + acos(x: number): number, + /** + * Returns the inverse hyperbolic cosine of a number. + * @param x A numeric expression that contains an angle measured in radians. + */ + acosh(x: number): number, + /** + * Returns the arcsine of a number. + * @param x A numeric expression. + */ + asin(x: number): number, + /** + * Returns the inverse hyperbolic sine of a number. + * @param x A numeric expression that contains an angle measured in radians. + */ + asinh(x: number): number, + /** + * Returns the arctangent of a number. + * @param x A numeric expression for which the arctangent is needed. + */ + atan(x: number): number, + /** + * Returns the angle (in radians) from the X axis to a point. + * @param y A numeric expression representing the cartesian y-coordinate. + * @param x A numeric expression representing the cartesian x-coordinate. + */ + atan2(y: number, x: number): number, + /** + * Returns the inverse hyperbolic tangent of a number. + * @param x A numeric expression that contains an angle measured in radians. + */ + atanh(x: number): number, + /** + * Returns an implementation-dependent approximation to the cube root of number. + * @param x A numeric expression. + */ + cbrt(x: number): number, + /** + * Returns the smallest integer greater than or equal to its numeric argument. + * @param x A numeric expression. + */ + ceil(x: number): number, + /** + * Returns the number of leading zero bits in the 32-bit binary representation of a number. + * @param x A numeric expression. + */ + clz32(x: number): number, + /** + * Returns the cosine of a number. + * @param x A numeric expression that contains an angle measured in radians. + */ + cos(x: number): number, + /** + * Returns the hyperbolic cosine of a number. + * @param x A numeric expression that contains an angle measured in radians. + */ + cosh(x: number): number, + /** + * Returns e (the base of natural logarithms) raised to a power. + * @param x A numeric expression representing the power of e. + */ + exp(x: number): number, + /** + * Returns the result of (e^x - 1), which is an implementation-dependent approximation to + * subtracting 1 from the exponential function of x (e raised to the power of x, where e + * is the base of the natural logarithms). + * @param x A numeric expression. + */ + expm1(x: number): number, + /** + * Returns the greatest integer less than or equal to its numeric argument. + * @param x A numeric expression. + */ + floor(x: number): number, + /** + * Returns the nearest single precision float representation of a number. + * @param x A numeric expression. + */ + fround(x: number): number, + /** + * Returns the square root of the sum of squares of its arguments. + * @param values Values to compute the square root for. + * If no arguments are passed, the result is +0. + * If there is only one argument, the result is the absolute value. + * If any argument is +Infinity or -Infinity, the result is +Infinity. + * If any argument is NaN, the result is NaN. + * If all arguments are either +0 or -0, the result is +0. + */ + hypot(...values: Array): number, + /** + * Returns the result of 32-bit multiplication of two numbers. + * @param x First number + * @param y Second number + */ + imul(x: number, y: number): number, + /** + * Returns the natural logarithm (base e) of a number. + * @param x A numeric expression. + */ + log(x: number): number, + /** + * Returns the base 10 logarithm of a number. + * @param x A numeric expression. + */ + log10(x: number): number, + /** + * Returns the natural logarithm of 1 + x. + * @param x A numeric expression. + */ + log1p(x: number): number, + /** + * Returns the base 2 logarithm of a number. + * @param x A numeric expression. + */ + log2(x: number): number, + /** + * Returns the larger of a set of supplied numeric expressions. + * @param values Numeric expressions to be evaluated. + */ + max(...values: Array): number, + /** + * Returns the smaller of a set of supplied numeric expressions. + * @param values Numeric expressions to be evaluated. + */ + min(...values: Array): number, + /** + * Returns the value of a base expression taken to a specified power. + * @param x The base value of the expression. + * @param y The exponent value of the expression. + */ + pow(x: number, y: number): number, + /** Returns a pseudorandom number between 0 and 1. */ + random(): number, + /** + * Returns a supplied numeric expression rounded to the nearest integer. + * @param x The value to be rounded to the nearest integer. + */ + round(x: number): number, + /** + * Returns the sign of the x, indicating whether x is positive, negative or zero. + * @param x The numeric expression to test + */ + sign(x: number): number, + /** + * Returns the sine of a number. + * @param x A numeric expression that contains an angle measured in radians. + */ + sin(x: number): number, + /** + * Returns the hyperbolic sine of a number. + * @param x A numeric expression that contains an angle measured in radians. + */ + sinh(x: number): number, + /** + * Returns the square root of a number. + * @param x A numeric expression. + */ + sqrt(x: number): number, + /** + * Returns the tangent of a number. + * @param x A numeric expression that contains an angle measured in radians. + */ + tan(x: number): number, + /** + * Returns the hyperbolic tangent of a number. + * @param x A numeric expression that contains an angle measured in radians. + */ + tanh(x: number): number, + /** + * Returns the integral part of the a numeric expression, x, removing any fractional digits. + * If x is already an integer, the result is x. + * @param x A numeric expression. + */ + trunc(x: number): number, + ... +}; + +/** + * A class of Array methods and properties that don't mutate the array. + */ +declare class $ReadOnlyArray<+T> { + @@iterator(): Iterator; + /** + * Returns a string representation of an array. The elements are converted to string using their toLocalString methods. + */ + toLocaleString(): string; + // concat creates a new array + /** + * Combines two or more arrays. + * @param items Additional items to add to the end of array1. + */ + concat | S>(...items: Array): Array; + /** + * Returns an iterable of key, value pairs for every entry in the array + */ + entries(): Iterator<[number, T]>; + /** + * Determines whether all the members of an array satisfy the specified test. + * @param callbackfn A function that accepts up to three arguments. The every method calls + * the predicate function for each element in the array until the predicate returns a value + * which is coercible to the Boolean value false, or until the end of the array. + * @param thisArg An object to which the this keyword can refer in the predicate function. + * If thisArg is omitted, undefined is used as the this value. + */ + every(callbackfn: (value: T, index: number, array: $ReadOnlyArray) => mixed, thisArg?: mixed): boolean; + /** + * Returns the elements of an array that meet the condition specified in a callback function. + * @param callbackfn A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array. + */ + filter(callbackfn: typeof Boolean): Array<$NonMaybeType>; + /** + * Returns the elements of an array that meet the condition specified in a callback function. + * @param callbackfn A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value. + */ + filter(callbackfn: (value: T, index: number, array: $ReadOnlyArray) => mixed, thisArg?: mixed): Array; + /** + * Returns the value of the first element in the array where predicate is true, and undefined + * otherwise. + * @param callbackfn find calls predicate once for each element of the array, in ascending + * order, until it finds one where predicate returns true. If such an element is found, find + * immediately returns that element value. Otherwise, find returns undefined. + * @param thisArg If provided, it will be used as the this value for each invocation of + * predicate. If it is not provided, undefined is used instead. + */ + find(callbackfn: (value: T, index: number, array: $ReadOnlyArray) => mixed, thisArg?: mixed): T | void; + /** + * Returns the index of the first element in the array where predicate is true, and -1 + * otherwise. + * @param callbackfn find calls predicate once for each element of the array, in ascending + * order, until it finds one where predicate returns true. If such an element is found, + * findIndex immediately returns that element index. Otherwise, findIndex returns -1. + * @param thisArg If provided, it will be used as the this value for each invocation of + * predicate. If it is not provided, undefined is used instead. + */ + findIndex(callbackfn: (value: T, index: number, array: $ReadOnlyArray) => mixed, thisArg?: mixed): number; + /** + * Performs the specified action for each element in an array. + * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. + */ + forEach(callbackfn: (value: T, index: number, array: $ReadOnlyArray) => mixed, thisArg?: mixed): void; + /** + * Determines whether an array includes a certain element, returning true or false as appropriate. + * @param searchElement The element to search for. + * @param fromIndex The position in this array at which to begin searching for searchElement. + */ + includes(searchElement: mixed, fromIndex?: number): boolean; + /** + * Returns the index of the first occurrence of a value in an array. + * @param searchElement The value to locate in the array. + * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0. + */ + indexOf(searchElement: mixed, fromIndex?: number): number; + /** + * Adds all the elements of an array separated by the specified separator string. + * @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma. + */ + join(separator?: string): string; + /** + * Returns an iterable of keys in the array + */ + keys(): Iterator; + /** + * Returns the index of the last occurrence of a specified value in an array. + * @param searchElement The value to locate in the array. + * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array. + */ + lastIndexOf(searchElement: mixed, fromIndex?: number): number; + /** + * Calls a defined callback function on each element of an array, and returns an array that contains the results. + * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. + */ + map(callbackfn: (value: T, index: number, array: $ReadOnlyArray) => U, thisArg?: mixed): Array; + /** + * Calls a defined callback function on each element of an array. Then, flattens the result into + * a new array. + * This is identical to a map followed by flat with depth 1. + * + * @param callbackfn A function that accepts up to three arguments. The flatMap method calls the + * callback function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callback function. If + * thisArg is omitted, undefined is used as the this value. + */ + flatMap(callbackfn: (value: T, index: number, array: $ReadOnlyArray) => $ReadOnlyArray | U, thisArg?: mixed): Array; + /** + * Returns a new array with all sub-array elements concatenated into it recursively up to the + * specified depth. + * + * @param depth The maximum recursion depth + */ + flat(depth: 0): Array; + /** + * Returns a new array with all sub-array elements concatenated into it recursively up to the + * specified depth. + * + * @param depth The maximum recursion depth + */ + flat(depth: void | 1): Array<$Call<(($ReadOnlyArray) => X) & ((X) => X), T>>; + /** + * Returns a new array with all sub-array elements concatenated into it recursively up to the + * specified depth. + * + * @param depth The maximum recursion depth + */ + flat(depth: number): Array; + /** + * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. + */ + reduce( + callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: $ReadOnlyArray) => T, + ): T; + /** + * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. + */ + reduce( + callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: $ReadOnlyArray) => U, + initialValue: U + ): U; + /** + * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. + */ + reduceRight( + callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: $ReadOnlyArray) => T, + ): T; + /** + * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. + */ + reduceRight( + callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: $ReadOnlyArray) => U, + initialValue: U + ): U; + /** + * Returns a section of an array. + * @param start The beginning of the specified portion of the array. + * @param end The end of the specified portion of the array. This is exclusive of the element at the index 'end'. + */ + slice(start?: number, end?: number): Array; + /** + * Determines whether the specified callback function returns true for any element of an array. + * @param callbackfn A function that accepts up to three arguments. The some method calls + * the predicate function for each element in the array until the predicate returns a value + * which is coercible to the Boolean value true, or until the end of the array. + * @param thisArg An object to which the this keyword can refer in the predicate function. + * If thisArg is omitted, undefined is used as the this value. + */ + some(callbackfn: (value: T, index: number, array: $ReadOnlyArray) => mixed, thisArg?: mixed): boolean; + /** + * Returns an iterable of values in the array + */ + values(): Iterator; + +[key: number]: T; + /** + * Gets the length of the array. This is a number one higher than the highest element defined in an array. + */ + +length: number; +} + +declare class Array extends $ReadOnlyArray { + /** + * Returns the this object after copying a section of the array identified by start and end + * to the same array starting at position target + * @param target If target is negative, it is treated as length+target where length is the + * length of the array. + * @param start If start is negative, it is treated as length+start. If end is negative, it + * is treated as length+end. + * @param end If not specified, length of the this object is used as its default value. + */ + copyWithin(target: number, start: number, end?: number): T[]; + /** + * Determines whether all the members of an array satisfy the specified test. + * @param callbackfn A function that accepts up to three arguments. The every method calls + * the predicate function for each element in the array until the predicate returns a value + * which is coercible to the Boolean value false, or until the end of the array. + * @param thisArg An object to which the this keyword can refer in the predicate function. + * If thisArg is omitted, undefined is used as the this value. + */ + every(callbackfn: (value: T, index: number, array: Array) => mixed, thisArg?: mixed): boolean; + /** + * Returns the this object after filling the section identified by start and end with value + * @param value value to fill array section with + * @param begin index to start filling the array at. If start is negative, it is treated as + * length+start where length is the length of the array. + * @param end index to stop filling the array at. If end is negative, it is treated as + * length+end. + */ + fill(value: T, begin?: number, end?: number): Array; + /** + * Returns the elements of an array that meet the condition specified in a callback function. + * @param callbackfn A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array. + */ + filter(callbackfn: typeof Boolean): Array<$NonMaybeType>; + /** + * Returns the elements of an array that meet the condition specified in a callback function. + * @param callbackfn A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value. + */ + filter(callbackfn: (value: T, index: number, array: Array) => mixed, thisArg?: mixed): Array; + /** + * Returns the value of the first element in the array where predicate is true, and undefined + * otherwise. + * @param callbackfn find calls predicate once for each element of the array, in ascending + * order, until it finds one where predicate returns true. If such an element is found, find + * immediately returns that element value. Otherwise, find returns undefined. + * @param thisArg If provided, it will be used as the this value for each invocation of + * predicate. If it is not provided, undefined is used instead. + */ + find(callbackfn: (value: T, index: number, array: Array) => mixed, thisArg?: mixed): T | void; + /** + * Returns the index of the first element in the array where predicate is true, and -1 + * otherwise. + * @param callbackfn find calls predicate once for each element of the array, in ascending + * order, until it finds one where predicate returns true. If such an element is found, + * findIndex immediately returns that element index. Otherwise, findIndex returns -1. + * @param thisArg If provided, it will be used as the this value for each invocation of + * predicate. If it is not provided, undefined is used instead. + */ + findIndex(callbackfn: (value: T, index: number, array: Array) => mixed, thisArg?: mixed): number; + /** + * Performs the specified action for each element in an array. + * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. + */ + forEach(callbackfn: (value: T, index: number, array: Array) => mixed, thisArg?: mixed): void; + /** + * Calls a defined callback function on each element of an array, and returns an array that contains the results. + * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. + */ + map(callbackfn: (value: T, index: number, array: Array) => U, thisArg?: mixed): Array; + /** + * Calls a defined callback function on each element of an array. Then, flattens the result into + * a new array. + * This is identical to a map followed by flat with depth 1. + * + * @param callbackfn A function that accepts up to three arguments. The flatMap method calls the + * callback function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callback function. If + * thisArg is omitted, undefined is used as the this value. + */ + flatMap(callbackfn: (value: T, index: number, array: Array) => $ReadOnlyArray | U, thisArg?: mixed): Array; + /** + * Removes the last element from an array and returns it. + */ + pop(): T; + /** + * Appends new elements to an array, and returns the new length of the array. + * @param items New elements of the Array. + */ + push(...items: Array): number; + /** + * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. + */ + reduce( + callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: Array) => T, + ): T; + /** + * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. + */ + reduce( + callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: Array) => U, + initialValue: U + ): U; + /** + * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. + */ + reduceRight( + callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: Array) => T, + ): T; + /** + * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. + */ + reduceRight( + callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: Array) => U, + initialValue: U + ): U; + /** + * Reverses the elements in an Array. + */ + reverse(): Array; + /** + * Removes the first element from an array and returns it. + */ + shift(): T; + some(callbackfn: (value: T, index: number, array: Array) => mixed, thisArg?: mixed): boolean; + sort(compareFn?: (a: T, b: T) => number): Array; + splice(start: number, deleteCount?: number, ...items: Array): Array; + unshift(...items: Array): number; + + + [key: number]: T; + /** + * Gets or sets the length of the array. This is a number one higher than the highest element defined in an array. + */ + length: number; + static (...values:Array): Array; + static isArray(obj: mixed): bool; + /** + * Creates an array from an iterable object. + * @param iter An iterable object to convert to an array. + * @param mapFn A mapping function to call on every element of the array. + * @param thisArg Value of 'this' used to invoke the mapfn. + */ + static from(iter: Iterable, mapFn: (elem: A, index: number) => B, thisArg?: mixed): Array; + /** + * Creates an array from an iterable object. + * @param iter An iterable object to convert to an array. + */ + static from(iter: Iterable, mapFn: void): Array; + /** + * Creates an array from an iterable object. + * @param iter An iterable object to convert to an array. + * @param mapFn A mapping function to call on every element of the array. + * @param thisArg Value of 'this' used to invoke the mapfn. + */ + static from(iter: Iterator, mapFn: (elem: A, index: number) => B, thisArg?: mixed): Array; + /** + * Creates an array from an iterable object. + * @param iter An array-like object to convert to an array. + */ + static from(iter: Iterator, mapFn: void): Array; + /** + * Creates an array from an array-like object. + * @param arrayLike An array-like object to convert to an array. + * @param mapFn A mapping function to call on every element of the array. + * @param thisArg Value of 'this' used to invoke the mapfn. + */ + static from(arrayLike: { length: number, ... }, mapFn: (elem: void, index: number) => A, thisArg?: mixed): Array; + /** + * Creates an array from an array-like object. + * @param arrayLike An array-like object to convert to an array. + */ + static from(arrayLike: { length: number, ... }, mapFn: void): Array; + /** + * Returns a new array from a set of elements. + * @param values A set of elements to include in the new array object. + */ + static of(...values: Array): Array; +} + +type $ArrayLike = { + [indexer: number]: T, + length: number, + ... +} + +type RegExp$flags = $CharSet<"gimsuy">; +type RegExp$matchResult = Array & { + index: number, + input: string, + groups: ?{ [name: string]: string, ... }, + ... +}; + +/** + * Allows manipulation and formatting of text strings and determination and location of substrings within strings. + */ +declare class String { + @@iterator(): Iterator; + /** + * Returns an `` HTML anchor element and sets the name attribute to the text value + * @param name + */ + anchor(name: string): string; + /** + * Returns the character at the specified index. + * @param pos The zero-based index of the desired character. + */ + charAt(pos: number): string; + /** + * Returns the Unicode value of the character at the specified location. + * @param index The zero-based index of the desired character. If there is no character at the specified index, NaN is returned. + */ + charCodeAt(index: number): number; + /** + * Returns a nonnegative integer Number less than 1114112 (0x110000) that is the code point + * value of the UTF-16 encoded code point starting at the string element at position index in + * the String resulting from converting this object to a String. + * If there is no element at that position, the result is undefined. + * If a valid UTF-16 surrogate pair does not begin at index, the result is the code unit at index. + */ + codePointAt(index: number): number; + /** + * Returns a string that contains the concatenation of two or more strings. + * @param strings The strings to append to the end of the string. + */ + concat(...strings: Array): string; + constructor(value?: mixed): void; + /** + * Returns true if the sequence of elements of searchString converted to a String is the + * same as the corresponding elements of this object (converted to a String) starting at + * position - length(this). Otherwise returns false. + */ + endsWith(searchString: string, position?: number): boolean; + /** + * Returns true if searchString appears as a substring of the result of converting this + * object to a String, at one or more positions that are + * greater than or equal to position; otherwise, returns false. + * @param searchString search string + * @param position If position is undefined, 0 is assumed, so as to search all of the String. + */ + includes(searchString: string, position?: number): boolean; + /** + * Returns the position of the first occurrence of a substring. + * @param searchString The substring to search for in the string + * @param position The index at which to begin searching the String object. If omitted, search starts at the beginning of the string. + */ + indexOf(searchString: string, position?: number): number; + /** + * Returns the last occurrence of a substring in the string. + * @param searchString The substring to search for. + * @param position The index at which to begin searching. If omitted, the search begins at the end of the string. + */ + lastIndexOf(searchString: string, position?: number): number; + /** Returns an `` HTML element and sets the href attribute value */ + link(href: string): string; + /** + * Determines whether two strings are equivalent in the current or specified locale. + * @param that String to compare to target string + * @param locales A locale string or array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. This parameter must conform to BCP 47 standards; see the Intl.Collator object for details. + * @param options An object that contains one or more properties that specify comparison options. see the Intl.Collator object for details. + */ + localeCompare(that: string, locales?: string | Array, options?: Intl$CollatorOptions): number; + /** + * Matches a string with a regular expression, and returns an array containing the results of that search. + * @param regexp A variable name or string literal containing the regular expression pattern and flags. + */ + match(regexp: string | RegExp): RegExp$matchResult | null; + /** + * Matches a string with a regular expression, and returns an iterable of matches + * containing the results of that search. + * @param regexp A variable name or string literal containing the regular expression pattern and flags. + */ + matchAll(regexp: string | RegExp): Iterator; + /** + * Returns the String value result of normalizing the string into the normalization form + * named by form as specified in Unicode Standard Annex #15, Unicode Normalization Forms. + * @param format Applicable values: "NFC", "NFD", "NFKC", or "NFKD", If not specified default + * is "NFC" + */ + normalize(format?: string): string; + /** + * Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length. + * The padding is applied from the end (right) of the current string. + * + * @param targetLength The length of the resulting string once the current string has been padded. + * If this parameter is smaller than the current string's length, the current string will be returned as it is. + * + * @param padString The string to pad the current string with. + * If this string is too long, it will be truncated and the left-most part will be applied. + * The default value for this parameter is " " (U+0020). + */ + padEnd(targetLength: number, padString?: string): string; + /** + * Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length. + * The padding is applied from the start (left) of the current string. + * + * @param targetLength The length of the resulting string once the current string has been padded. + * If this parameter is smaller than the current string's length, the current string will be returned as it is. + * + * @param padString The string to pad the current string with. + * If this string is too long, it will be truncated and the left-most part will be applied. + * The default value for this parameter is " " (U+0020). + */ + padStart(targetLength: number, padString?: string): string; + /** + * Returns a String value that is made from count copies appended together. If count is 0, + * the empty string is returned. + * @param count number of copies to append + */ + repeat(count: number): string; + /** + * Replaces text in a string, using a regular expression or search string. + * @param searchValue A string to search for. + * @param replaceValue A string containing the text to replace for every successful match of searchValue in this string or a function that returns the replacement text. + */ + replace(searchValue: string | RegExp, replaceValue: string | (substring: string, ...args: Array) => string): string; + /** + * Finds the first substring match in a regular expression search. + * @param regexp The regular expression pattern and applicable flags. + */ + search(regexp: string | RegExp): number; + /** + * Returns a section of a string. + * @param start The index to the beginning of the specified portion of stringObj. + * @param end The index to the end of the specified portion of stringObj. The substring includes the characters up to, but not including, the character indicated by end. + * If this value is not specified, the substring continues to the end of stringObj. + */ + slice(start?: number, end?: number): string; + /** + * Split a string into substrings using the specified separator and return them as an array. + * @param separator A string that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned. + * @param limit A value used to limit the number of elements returned in the array. + */ + split(separator?: string | RegExp, limit?: number): Array; + /** + * Returns true if the sequence of elements of searchString converted to a String is the + * same as the corresponding elements of this object (converted to a String) starting at + * position. Otherwise returns false. + */ + startsWith(searchString: string, position?: number): boolean; + /** + * Gets a substring beginning at the specified location and having the specified length. + * @param from The starting position of the desired substring. The index of the first character in the string is zero. + * @param length The number of characters to include in the returned substring. + */ + substr(from: number, length?: number): string; + /** + * Returns the substring at the specified location within a String object. + * @param start The zero-based index number indicating the beginning of the substring. + * @param end Zero-based index number indicating the end of the substring. The substring includes the characters up to, but not including, the character indicated by end. + * If end is omitted, the characters from start through the end of the original string are returned. + */ + substring(start: number, end?: number): string; + /** Converts all alphabetic characters to lowercase, taking into account the host environment's current locale. */ + toLocaleLowerCase(locale?: string | Array): string; + /** Returns a string where all alphabetic characters have been converted to uppercase, taking into account the host environment's current locale. */ + toLocaleUpperCase(locale?: string | Array): string; + /** Converts all the alphabetic characters in a string to lowercase. */ + toLowerCase(): string; + /** Converts all the alphabetic characters in a string to uppercase. */ + toUpperCase(): string; + /** Removes the leading and trailing white space and line terminator characters from a string. */ + trim(): string; + /** Removes the trailing white space and line terminator characters from a string. */ + trimEnd(): string; + /** Removes the leading white space and line terminator characters from a string. */ + trimLeft(): string; + /** Removes the trailing white space and line terminator characters from a string. */ + trimRight(): string; + /** Removes the leading white space and line terminator characters from a string. */ + trimStart(): string; + /** Returns the primitive value of the specified object. */ + valueOf(): string; + /** Returns a string representation of a string. */ + toString(): string; + /** Returns the length of a String object. */ + length: number; + [key: number]: string; + static (value:mixed):string; + static fromCharCode(...codes: Array): string; + /** + * Return the String value whose elements are, in order, the elements in the List elements. + * If length is 0, the empty string is returned. + */ + static fromCodePoint(...codes: Array): string; + /** + * String.raw is intended for use as a tag function of a Tagged Template String. When called + * as such the first argument will be a well formed template call site object and the rest + * parameter will contain the substitution values. + * @param templateString A well-formed template string call site representation. + */ + static raw(templateString: string): string; + /** + * String.raw is intended for use as a tag function of a Tagged Template String. When called + * as such the first argument will be a well formed template call site object and the rest + * parameter will contain the substitution values. + * @param callSite A well-formed template string call site representation. + * @param substitutions A set of substitution values. + */ + static raw(callSite: $Shape<{ raw: string, ... }>, ...substitutions: any[]): string; +} + +declare class RegExp { + static (pattern: string | RegExp, flags?: RegExp$flags): RegExp; + compile(): RegExp; + constructor(pattern: string | RegExp, flags?: RegExp$flags): void; + /** + * Executes a search on a string using a regular expression pattern, and returns an array containing the results of that search. + * @param string The String object or string literal on which to perform the search. + */ + exec(string: string): RegExp$matchResult | null; + /** + * Returns a string indicating the flags of the regular expression in question. This field is read-only. + * The characters in this string are sequenced and concatenated in the following order: + * + * - "g" for global + * - "i" for ignoreCase + * - "m" for multiline + * - "u" for unicode + * - "y" for sticky + * + * If no flags are set, the value is the empty string. + */ + flags: string; + /** Returns a Boolean value indicating the state of the global flag (g) used with a regular expression. Default is false. Read-only. */ + global: boolean; + /** Returns a Boolean value indicating the state of the ignoreCase flag (i) used with a regular expression. Default is false. Read-only. */ + ignoreCase: boolean; + lastIndex: number; + /** Returns a Boolean value indicating the state of the multiline flag (m) used with a regular expression. Default is false. Read-only. */ + multiline: boolean; + /** Returns a copy of the text of the regular expression pattern. Read-only. The regExp argument is a Regular expression object. It can be a variable name or a literal. */ + source: string; + /** + * Returns a Boolean value indicating the state of the sticky flag (y) used with a regular + * expression. Default is false. Read-only. + */ + sticky: boolean; + /** + * Returns a Boolean value indicating the state of the Unicode flag (u) used with a regular + * expression. Default is false. Read-only. + */ + unicode: boolean; + /** + * Returns a Boolean value indicating the state of the dotAll flag (s) used with a regular expression. + * Default is false. Read-only. + */ + dotAll: boolean; + /** + * Returns a Boolean value that indicates whether or not a pattern exists in a searched string. + * @param string String on which to perform the search. + */ + test(string: string): boolean; + toString(): string; + +[key: $SymbolMatch | $SymbolMatchAll]: (str: string) => Iterator +} + +/** Enables basic storage and retrieval of dates and times. */ +declare class Date { + constructor(): void; + constructor(timestamp: number): void; + constructor(date: Date): void; + constructor(dateString: string): void; + constructor(year: number, month: number, day?: number, hour?: number, minute?: number, second?: number, millisecond?: number): void; + /** Gets the day-of-the-month, using local time. */ + getDate(): number; + /** Gets the day of the week, using local time. */ + getDay(): number; + /** Gets the year, using local time. */ + getFullYear(): number; + /** Gets the hours in a date, using local time. */ + getHours(): number; + /** Gets the milliseconds of a Date, using local time. */ + getMilliseconds(): number; + /** Gets the minutes of a Date object, using local time. */ + getMinutes(): number; + /** Gets the month, using local time. */ + getMonth(): number; + /** Gets the seconds of a Date object, using local time. */ + getSeconds(): number; + /** Gets the time value in milliseconds. */ + getTime(): number; + /** Gets the difference in minutes between the time on the local computer and Universal Coordinated Time (UTC). */ + getTimezoneOffset(): number; + /** Gets the day-of-the-month, using Universal Coordinated Time (UTC). */ + getUTCDate(): number; + /** Gets the day of the week using Universal Coordinated Time (UTC). */ + getUTCDay(): number; + /** Gets the year using Universal Coordinated Time (UTC). */ + getUTCFullYear(): number; + /** Gets the hours value in a Date object using Universal Coordinated Time (UTC). */ + getUTCHours(): number; + /** Gets the milliseconds of a Date object using Universal Coordinated Time (UTC). */ + getUTCMilliseconds(): number; + /** Gets the minutes of a Date object using Universal Coordinated Time (UTC). */ + getUTCMinutes(): number; + /** Gets the month of a Date object using Universal Coordinated Time (UTC). */ + getUTCMonth(): number; + /** Gets the seconds of a Date object using Universal Coordinated Time (UTC). */ + getUTCSeconds(): number; + /** + * Sets the numeric day-of-the-month value of the Date object using local time. + * @param date A numeric value equal to the day of the month. + */ + setDate(date: number): number; + /** + * Sets the year of the Date object using local time. + * @param year A numeric value for the year. + * @param month A zero-based numeric value for the month (0 for January, 11 for December). Must be specified if numDate is specified. + * @param date A numeric value equal for the day of the month. + */ + setFullYear(year: number, month?: number, date?: number): number; + /** + * Sets the hour value in the Date object using local time. + * @param hours A numeric value equal to the hours value. + * @param min A numeric value equal to the minutes value. + * @param sec A numeric value equal to the seconds value. + * @param ms A numeric value equal to the milliseconds value. + */ + setHours(hours: number, min?: number, sec?: number, ms?: number): number; + /** + * Sets the milliseconds value in the Date object using local time. + * @param ms A numeric value equal to the millisecond value. + */ + setMilliseconds(ms: number): number; + /** + * Sets the minutes value in the Date object using local time. + * @param min A numeric value equal to the minutes value. + * @param sec A numeric value equal to the seconds value. + * @param ms A numeric value equal to the milliseconds value. + */ + setMinutes(min: number, sec?: number, ms?: number): number; + /** + * Sets the month value in the Date object using local time. + * @param month A numeric value equal to the month. The value for January is 0, and other month values follow consecutively. + * @param date A numeric value representing the day of the month. If this value is not supplied, the value from a call to the getDate method is used. + */ + setMonth(month: number, date?: number): number; + /** + * Sets the seconds value in the Date object using local time. + * @param sec A numeric value equal to the seconds value. + * @param ms A numeric value equal to the milliseconds value. + */ + setSeconds(sec: number, ms?: number): number; + /** + * Sets the date and time value in the Date object. + * @param time A numeric value representing the number of elapsed milliseconds since midnight, January 1, 1970 GMT. + */ + setTime(time: number): number; + /** + * Sets the numeric day of the month in the Date object using Universal Coordinated Time (UTC). + * @param date A numeric value equal to the day of the month. + */ + setUTCDate(date: number): number; + /** + * Sets the year value in the Date object using Universal Coordinated Time (UTC). + * @param year A numeric value equal to the year. + * @param month A numeric value equal to the month. The value for January is 0, and other month values follow consecutively. Must be supplied if numDate is supplied. + * @param date A numeric value equal to the day of the month. + */ + setUTCFullYear(year: number, month?: number, date?: number): number; + /** + * Sets the hours value in the Date object using Universal Coordinated Time (UTC). + * @param hours A numeric value equal to the hours value. + * @param min A numeric value equal to the minutes value. + * @param sec A numeric value equal to the seconds value. + * @param ms A numeric value equal to the milliseconds value. + */ + setUTCHours(hours: number, min?: number, sec?: number, ms?: number): number; + /** + * Sets the milliseconds value in the Date object using Universal Coordinated Time (UTC). + * @param ms A numeric value equal to the millisecond value. + */ + setUTCMilliseconds(ms: number): number; + /** + * Sets the minutes value in the Date object using Universal Coordinated Time (UTC). + * @param min A numeric value equal to the minutes value. + * @param sec A numeric value equal to the seconds value. + * @param ms A numeric value equal to the milliseconds value. + */ + setUTCMinutes(min: number, sec?: number, ms?: number): number; + /** + * Sets the month value in the Date object using Universal Coordinated Time (UTC). + * @param month A numeric value equal to the month. The value for January is 0, and other month values follow consecutively. + * @param date A numeric value representing the day of the month. If it is not supplied, the value from a call to the getUTCDate method is used. + */ + setUTCMonth(month: number, date?: number): number; + /** + * Sets the seconds value in the Date object using Universal Coordinated Time (UTC). + * @param sec A numeric value equal to the seconds value. + * @param ms A numeric value equal to the milliseconds value. + */ + setUTCSeconds(sec: number, ms?: number): number; + /** Returns a date as a string value. */ + toDateString(): string; + /** Returns a date as a string value in ISO format. */ + toISOString(): string; + /** Used by the JSON.stringify method to enable the transformation of an object's data for JavaScript Object Notation (JSON) serialization. */ + toJSON(key?: mixed): string; + /** + * Converts a date to a string by using the current or specified locale. + * @param locales A locale string or array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. + * @param options An object that contains one or more properties that specify comparison options. + */ + toLocaleDateString(locales?: string | Array, options?: Intl$DateTimeFormatOptions): string; + /** + * Converts a date and time to a string by using the current or specified locale. + * @param locales A locale string or array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. + * @param options An object that contains one or more properties that specify comparison options. + */ + toLocaleString(locales?: string | Array, options?: Intl$DateTimeFormatOptions): string; + /** + * Converts a time to a string by using the current or specified locale. + * @param locales A locale string or array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. + * @param options An object that contains one or more properties that specify comparison options. + */ + toLocaleTimeString(locales?: string | Array, options?: Intl$DateTimeFormatOptions): string; + /** Returns a time as a string value. */ + toTimeString(): string; + /** Returns a date converted to a string using Universal Coordinated Time (UTC). */ + toUTCString(): string; + /** Returns the stored time value in milliseconds since midnight, January 1, 1970 UTC. */ + valueOf(): number; + + static ():string; + static now(): number; + /** + * Parses a string containing a date, and returns the number of milliseconds between that date and midnight, January 1, 1970. + * @param s A date string + */ + static parse(s: string): number; + /** + * Returns the number of milliseconds between midnight, January 1, 1970 Universal Coordinated Time (UTC) (or GMT) and the specified date. + * @param year The full year designation is required for cross-century date accuracy. If year is between 0 and 99 is used, then year is assumed to be 1900 + year. + * @param month The month as a number between 0 and 11 (January to December). + * @param date The date as a number between 1 and 31. + * @param hours Must be supplied if minutes is supplied. A number from 0 to 23 (midnight to 11pm) that specifies the hour. + * @param minutes Must be supplied if seconds is supplied. A number from 0 to 59 that specifies the minutes. + * @param seconds Must be supplied if milliseconds is supplied. A number from 0 to 59 that specifies the seconds. + * @param ms A number from 0 to 999 that specifies the milliseconds. + */ + 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(): ?((...any) => any); + 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: {[any] : any, ...}, constructor?: any): void; + + static stackTraceLimit: number; + static prepareStackTrace: (err: Error, stack: CallSite[]) => mixed; +} + +declare class EvalError extends Error { + static (message?:string):Error; +} + +declare class RangeError extends Error { + static (message?:string):Error; +} + +declare class ReferenceError extends Error { + static (message?:string):Error; +} + +declare class SyntaxError extends Error { + static (message?:string):Error; +} + +declare class TypeError extends Error { + static (message?:string):Error; +} + +declare class URIError extends Error { + static (message?:string):Error; +} + +/** + * An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format. + */ +declare class JSON { + /** + * Converts a JavaScript Object Notation (JSON) string into an object. + * @param text A valid JSON string. + * @param reviver A function that transforms the results. This function is called for each member of the object. + * If a member contains nested objects, the nested objects are transformed before the parent object is. + */ + static parse(text: string, reviver?: (key: any, value: any) => any): any; + /** + * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. + * @param value A JavaScript value, usually an object or array, to be converted. + * @param replacer A function that transforms the results or an array of strings and numbers that acts as a approved list for selecting the object properties that will be stringified. + * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. + */ + static stringify( + value: null | string | number | boolean | {...} | $ReadOnlyArray, + replacer?: ?((key: string, value: any) => any) | Array, + space?: string | number + ): string; + /** + * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. + * @param value A JavaScript value, usually an object or array, to be converted. + * @param replacer A function that transforms the results or an array of strings and numbers that acts as a approved list for selecting the object properties that will be stringified. + * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. + */ + static stringify( + value: mixed, + replacer?: ?((key: string, value: any) => any) | Array, + space?: string | number + ): string | void; +} + +/* Iterable/Iterator/Generator */ + +type IteratorResult<+Yield,+Return> = + | { + done: true, + +value?: Return, + ... +} + | { + done: false, + +value: Yield, + ... +}; + +interface $Iterator<+Yield,+Return,-Next> { + @@iterator(): $Iterator; + next(value?: Next): IteratorResult; +} +type Iterator<+T> = $Iterator; + +interface $Iterable<+Yield,+Return,-Next> { + @@iterator(): $Iterator; +} +type Iterable<+T> = $Iterable; + +interface Generator<+Yield,+Return,-Next> { + @@iterator(): $Iterator; + next(value?: Next): IteratorResult; + return(value: R): IteratorResult; + throw(error?: any): IteratorResult; +} + +declare function $iterate(p: Iterable): T; + +/* Async Iterable/Iterator/Generator */ + +interface $AsyncIterator<+Yield,+Return,-Next> { + @@asyncIterator(): $AsyncIterator; + next(value?: Next): Promise>; } +type AsyncIterator<+T> = $AsyncIterator; + +interface $AsyncIterable<+Yield,+Return,-Next> { + @@asyncIterator(): $AsyncIterator; +} +type AsyncIterable<+T> = $AsyncIterable; + +interface AsyncGenerator<+Yield,+Return,-Next> { + @@asyncIterator(): $AsyncIterator; + next(value?: Next): Promise>; + return(value: R): Promise>; + throw(error?: any): Promise>; +} + +declare function $asyncIterator(p: AsyncIterable): T; + +/* Maps and Sets */ + +declare class $ReadOnlyMap { + @@iterator(): Iterator<[K, V]>; + /** + * Returns an iterable of key, value pairs for every entry in the map. + */ + entries(): Iterator<[K, V]>; + forEach(callbackfn: (value: V, index: K, map: $ReadOnlyMap) => mixed, thisArg?: mixed): void; + get(key: K): V | void; + has(key: K): boolean; + /** + * Returns an iterable of keys in the map + */ + keys(): Iterator; + size: number; + /** + * Returns an iterable of values in the map + */ + values(): Iterator; +} + +declare class Map extends $ReadOnlyMap { + @@iterator(): Iterator<[K, V]>; + constructor(iterable: ?Iterable<[K, V]>): void; + clear(): void; + delete(key: K): boolean; + /** + * Returns an iterable of key, value pairs for every entry in the map. + */ + entries(): Iterator<[K, V]>; + forEach(callbackfn: (value: V, index: K, map: Map) => mixed, thisArg?: mixed): void; + get(key: K): V | void; + has(key: K): boolean; + /** + * Returns an iterable of keys in the map + */ + keys(): Iterator; + set(key: K, value: V): Map; + size: number; + /** + * Returns an iterable of values in the map + */ + values(): Iterator; + // Multiple Indexers not yet supported + +[key: $SymbolToStringTag]: any; + static +[key: $SymbolSpecies]: any; +} + +declare class $ReadOnlyWeakMap, +V> { + get(key: K): V | void; + has(key: K): boolean; +} + +declare class WeakMap, V> extends $ReadOnlyWeakMap { + 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; +} + +declare class $ReadOnlySet { + @@iterator(): Iterator; + /** + * Returns an iterable of [v,v] pairs for every value `v` in the set. + */ + entries(): Iterator<[T, T]>; + forEach(callbackfn: (value: T, index: T, set: $ReadOnlySet) => mixed, thisArg?: mixed): void; + has(value: T): boolean; + /** + * Despite its name, returns an iterable of the values in the set, + */ + keys(): Iterator; + size: number; + /** + * Returns an iterable of values in the set. + */ + values(): Iterator; +} + +declare class Set extends $ReadOnlySet { + @@iterator(): Iterator; + constructor(iterable: ?Iterable): void; + add(value: T): Set; + clear(): void; + delete(value: T): boolean; + /** + * Returns an iterable of [v,v] pairs for every value `v` in the set. + */ + entries(): Iterator<[T, T]>; + forEach(callbackfn: (value: T, index: T, set: Set) => mixed, thisArg?: mixed): void; + has(value: T): boolean; + /** + * Despite its name, returns an iterable of the values in the set, + */ + keys(): Iterator; + size: number; + /** + * Returns an iterable of values in the set. + */ + values(): Iterator; + +[key: $SymbolToStringTag]: (...any) => any; + static +[key: $SymbolSpecies]: (...any) => any; // This would the Set constructor, can't think of a way to correctly type this +} + +declare class $ReadOnlyWeakSet> { + has(value: T): boolean; +} + +declare class WeakSet> extends $ReadOnlyWeakSet { + constructor(iterable?: Iterable): void; + add(value: T): WeakSet; + delete(value: T): boolean; + has(value: T): boolean; +} + +/* Promises + cf. https://github.com/borisyankov/DefinitelyTyped/blob/master/es6-promises/es6-promises.d.ts +*/ +/** + * Represents the completion of an asynchronous operation + */ +declare class Promise<+R> { + constructor(callback: ( + resolve: (result: Promise | R) => void, + reject: (error: any) => void + ) => mixed): void; + + /** + * Attaches callbacks for the resolution and/or rejection of the Promise. + * @param onFulfill The callback to execute when the Promise is resolved. + * @param onReject The callback to execute when the Promise is rejected. + * @returns A Promise for the completion of which ever callback is executed. + */ + then(onFulfill: null | void, onReject: null | void): Promise; + /** + * Attaches callbacks for the resolution and/or rejection of the Promise. + * @param onFulfill The callback to execute when the Promise is resolved. + * @param onReject The callback to execute when the Promise is rejected. + * @returns A Promise for the completion of which ever callback is executed. + */ + then( + onFulfill: null | void, + onReject: (error: any) => Promise | U + ): Promise; + /** + * Attaches callbacks for the resolution and/or rejection of the Promise. + * @param onFulfill The callback to execute when the Promise is resolved. + * @param onReject The callback to execute when the Promise is rejected. + * @returns A Promise for the completion of which ever callback is executed. + */ + then( + onFulfill: (value: R) => Promise | U, + onReject: null | void | ((error: any) => Promise | U) + ): Promise; + + /** + * Attaches a callback for only the rejection of the Promise. + * @param onReject The callback to execute when the Promise is rejected. + * @returns A Promise for the completion of the callback. + */ + catch(onReject: null | void): Promise; + /** + * Attaches a callback for only the rejection of the Promise. + * @param onReject The callback to execute when the Promise is rejected. + * @returns A Promise for the completion of the callback. + */ + catch( + onReject: (error: any) => Promise | U + ): Promise; + + /** + * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The + * resolved value cannot be modified from the callback. + * @param onFinally The callback to execute when the Promise is settled (fulfilled or rejected). + * @returns A Promise for the completion of the callback. + */ + finally(onFinally: () => mixed): Promise; + + /** + * Creates a new resolved promise for the provided value. + * @param object A promise. + * @returns A promise whose internal state matches the provided promise. + */ + static resolve(object: Promise | T): Promise; + /** + * Creates a new rejected promise for the provided reason. + * @param error The reason the promise was rejected. + * @returns A new rejected Promise. + */ + static reject(error: any): Promise; + /** + * Creates a Promise that is resolved with an array of results when all of the provided Promises + * resolve, or rejected when any Promise is rejected. + * @param promises An iterable of Promises. + * @returns A new Promise. + */ + static all>(promises: T): Promise<$TupleMap>; + /** + * Creates a Promise that is resolved with an array of results when all + * of the provided Promises resolve or reject. + * @param promises An array of Promises. + * @returns A new Promise. + */ + static allSettled>(promises: T): Promise<$TupleMap(p: Promise | T) => $SettledPromiseResult>>; + /** + * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved + * or rejected. + * @param promises An iterable of Promises. + * @returns A new Promise. + */ + static race | T>(promises: Iterable): Promise; +} + +type $SettledPromiseResult<+T> = {| + +status: 'fulfilled', + +value: T, +|} | {| + +status: 'rejected', + +reason: any, +|}; + +// we use this signature when typing await expressions +declare function $await(p: Promise | T): T; + +/* Binary data */ + +declare class ArrayBuffer { + static isView(arg: mixed): boolean; + constructor(byteLength: number): void; + byteLength: number; + slice(begin: number, end?: number): this; + static +[key: $SymbolSpecies]: Class; +} + +// 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 { + /** + * The size in bytes of each element in the array. + */ + static BYTES_PER_ELEMENT: number; + static from(iterable: Iterable, mapFn?: (element: number) => number, thisArg?: mixed): this; + static of(...values: number[]): this; + + constructor(length: number): void; + constructor(typedArray: $TypedArray): void; + constructor(iterable: Iterable): void; + constructor(buffer: ArrayBuffer, byteOffset?: number, length?: number): void; + + [index: number]: number; + + @@iterator(): Iterator; + + /** + * The ArrayBuffer instance referenced by the array. + */ + buffer: ArrayBuffer; + /** + * The length in bytes of the array. + */ + byteLength: number; + /** + * The offset in bytes of the array. + */ + byteOffset: number; + /** + * The length of the array. + */ + length: number; + + /** + * Returns the this object after copying a section of the array identified by start and end + * to the same array starting at position target + * @param target If target is negative, it is treated as length+target where length is the + * length of the array. + * @param start If start is negative, it is treated as length+start. If end is negative, it + * is treated as length+end. + * @param end If not specified, length of the this object is used as its default value. + */ + copyWithin(target: number, start: number, end?: number): void; + /** + * Returns an array of key, value pairs for every entry in the array + */ + entries(): Iterator<[number, number]>; + /** + * Determines whether all the members of an array satisfy the specified test. + * @param callback A function that accepts up to three arguments. The every method calls + * the predicate function for each element in the array until the predicate returns a value + * which is coercible to the Boolean value false, or until the end of the array. + * @param thisArg An object to which the this keyword can refer in the predicate function. + * If thisArg is omitted, undefined is used as the this value. + */ + every(callback: (value: number, index: number, array: this) => mixed, thisArg?: mixed): boolean; + /** + * Returns the this object after filling the section identified by start and end with value + * @param value value to fill array section with + * @param start index to start filling the array at. If start is negative, it is treated as + * length+start where length is the length of the array. + * @param end index to stop filling the array at. If end is negative, it is treated as + * length+end. + */ + fill(value: number, start?: number, end?: number): this; + /** + * Returns the elements of an array that meet the condition specified in a callback function. + * @param callback A function that accepts up to three arguments. The filter method calls + * the predicate function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the predicate function. + * If thisArg is omitted, undefined is used as the this value. + */ + filter(callback: (value: number, index: number, array: this) => mixed, thisArg?: mixed): this; + /** + * Returns the value of the first element in the array where predicate is true, and undefined + * otherwise. + * @param callback find calls predicate once for each element of the array, in ascending + * order, until it finds one where predicate returns true. If such an element is found, find + * immediately returns that element value. Otherwise, find returns undefined. + * @param thisArg If provided, it will be used as the this value for each invocation of + * predicate. If it is not provided, undefined is used instead. + */ + find(callback: (value: number, index: number, array: this) => mixed, thisArg?: mixed): number | void; + /** + * Returns the index of the first element in the array where predicate is true, and -1 + * otherwise. + * @param callback find calls predicate once for each element of the array, in ascending + * order, until it finds one where predicate returns true. If such an element is found, + * findIndex immediately returns that element index. Otherwise, findIndex returns -1. + * @param thisArg If provided, it will be used as the this value for each invocation of + * predicate. If it is not provided, undefined is used instead. + */ + findIndex(callback: (value: number, index: number, array: this) => mixed, thisArg?: mixed): number; + /** + * Performs the specified action for each element in an array. + * @param callback A function that accepts up to three arguments. forEach calls the + * callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * If thisArg is omitted, undefined is used as the this value. + */ + forEach(callback: (value: number, index: number, array: this) => mixed, thisArg?: mixed): void; + /** + * Determines whether an array includes a certain element, returning true or false as appropriate. + * @param searchElement The element to search for. + * @param fromIndex The position in this array at which to begin searching for searchElement. + */ + includes(searchElement: number, fromIndex?: number): boolean; + /** + * Returns the index of the first occurrence of a value in an array. + * @param searchElement The value to locate in the array. + * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the + * search starts at index 0. + */ + indexOf(searchElement: number, fromIndex?: number): number; // -1 if not present + /** + * Adds all the elements of an array separated by the specified separator string. + * @param separator A string used to separate one element of an array from the next in the + * resulting String. If omitted, the array elements are separated with a comma. + */ + join(separator?: string): string; + /** + * Returns an list of keys in the array + */ + keys(): Iterator; + /** + * Returns the index of the last occurrence of a value in an array. + * @param searchElement The value to locate in the array. + * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the + * search starts at index 0. + */ + lastIndexOf(searchElement: number, fromIndex?: number): number; // -1 if not present + /** + * Calls a defined callback function on each element of an array, and returns an array that + * contains the results. + * @param callback A function that accepts up to three arguments. The map method calls the + * callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * If thisArg is omitted, undefined is used as the this value. + */ + map(callback: (currentValue: number, index: number, array: this) => number, thisArg?: mixed): this; + /** + * Calls the specified callback function for all the elements in an array. The return value of + * the callback function is the accumulated result, and is provided as an argument in the next + * call to the callback function. + * @param callback A function that accepts up to four arguments. The reduce method calls the + * callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an argument + * instead of an array value. + */ + reduce( + callback: (previousValue: number, currentValue: number, index: number, array: this) => number, + initialValue: void + ): number; + /** + * Calls the specified callback function for all the elements in an array. The return value of + * the callback function is the accumulated result, and is provided as an argument in the next + * call to the callback function. + * @param callback A function that accepts up to four arguments. The reduce method calls the + * callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an argument + * instead of an array value. + */ + reduce( + callback: (previousValue: U, currentValue: number, index: number, array: this) => U, + initialValue: U + ): U; + /** + * Calls the specified callback function for all the elements in an array, in descending order. + * The return value of the callback function is the accumulated result, and is provided as an + * argument in the next call to the callback function. + * @param callback A function that accepts up to four arguments. The reduceRight method calls + * the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an + * argument instead of an array value. + */ + reduceRight( + callback: (previousValue: number, currentValue: number, index: number, array: this) => number, + initialValue: void + ): number; + /** + * Calls the specified callback function for all the elements in an array, in descending order. + * The return value of the callback function is the accumulated result, and is provided as an + * argument in the next call to the callback function. + * @param callback A function that accepts up to four arguments. The reduceRight method calls + * the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an + * argument instead of an array value. + */ + reduceRight( + callback: (previousValue: U, currentValue: number, index: number, array: this) => U, + initialValue: U + ): U; + /** + * Reverses the elements in an Array. + */ + reverse(): this; + /** + * Sets a value or an array of values. + * @param array A typed or untyped array of values to set. + * @param offset The index in the current array at which the values are to be written. + */ + set(array: Array | $TypedArray, offset?: number): void; + /** + * Returns a section of an array. + * @param start The beginning of the specified portion of the array. + * @param end The end of the specified portion of the array. This is exclusive of the element at the index 'end'. + */ + slice(begin?: number, end?: number): this; + /** + * Determines whether the specified callback function returns true for any element of an array. + * @param callback A function that accepts up to three arguments. The some method calls + * the predicate function for each element in the array until the predicate returns a value + * which is coercible to the Boolean value true, or until the end of the array. + * @param thisArg An object to which the this keyword can refer in the predicate function. + * If thisArg is omitted, undefined is used as the this value. + */ + some(callback: (value: number, index: number, array: this) => mixed, thisArg?: mixed): boolean; + /** + * Sorts an array. + * @param compareFn Function used to determine the order of the elements. It is expected to return + * a negative value if first argument is less than second argument, zero if they're equal and a positive + * value otherwise. If omitted, the elements are sorted in ascending, ASCII character order. + * ```ts + * [11,2,22,1].sort((a, b) => a - b) + * ``` + */ + sort(compare?: (a: number, b: number) => number): void; + /** + * Gets a new Int8Array view of the ArrayBuffer store for this array, referencing the elements + * at begin, inclusive, up to end, exclusive. + * @param begin The index of the beginning of the array. + * @param end The index of the end of the array. + */ + subarray(begin?: number, end?: number): this; + /** + * Returns an list of values in the array + */ + values(): Iterator; +} + +/** + * A typed array of 8-bit integer values. The contents are initialized to 0. If the requested + * number of bytes could not be allocated an exception is raised. + */ +declare class Int8Array extends $TypedArray {} +/** + * A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the + * requested number of bytes could not be allocated an exception is raised. + */ +declare class Uint8Array extends $TypedArray {} +/** + * A typed array of 8-bit unsigned integer (clamped) values. The contents are initialized to 0. + * If the requested number of bytes could not be allocated an exception is raised. + */ +declare class Uint8ClampedArray extends $TypedArray {} +/** + * A typed array of 16-bit signed integer values. The contents are initialized to 0. If the + * requested number of bytes could not be allocated an exception is raised. + */ +declare class Int16Array extends $TypedArray {} +/** + * A typed array of 16-bit unsigned integer values. The contents are initialized to 0. If the + * requested number of bytes could not be allocated an exception is raised. + */ +declare class Uint16Array extends $TypedArray {} +/** + * A typed array of 32-bit signed integer values. The contents are initialized to 0. If the + * requested number of bytes could not be allocated an exception is raised. + */ +declare class Int32Array extends $TypedArray {} +/** + * A typed array of 32-bit unsigned integer values. The contents are initialized to 0. If the + * requested number of bytes could not be allocated an exception is raised. + */ +declare class Uint32Array extends $TypedArray {} +/** + * A typed array of 32-bit float values. The contents are initialized to 0. If the requested number + * of bytes could not be allocated an exception is raised. + */ +declare class Float32Array extends $TypedArray {} +/** + * A typed array of 64-bit float values. The contents are initialized to 0. If the requested + * number of bytes could not be allocated an exception is raised. + */ +declare class Float64Array extends $TypedArray {} + +declare class DataView { + constructor(buffer: ArrayBuffer, byteOffset?: number, length?: number): void; + buffer: ArrayBuffer; + byteLength: number; + byteOffset: number; + /** + * Gets the Int8 value at the specified byte offset from the start of the view. There is + * no alignment constraint; multi-byte values may be fetched from any offset. + * @param byteOffset The place in the buffer at which the value should be retrieved. + */ + getInt8(byteOffset: number): number; + /** + * Gets the Uint8 value at the specified byte offset from the start of the view. There is + * no alignment constraint; multi-byte values may be fetched from any offset. + * @param byteOffset The place in the buffer at which the value should be retrieved. + */ + getUint8(byteOffset: number): number; + /** + * Gets the Int16 value at the specified byte offset from the start of the view. There is + * no alignment constraint; multi-byte values may be fetched from any offset. + * @param byteOffset The place in the buffer at which the value should be retrieved. + */ + getInt16(byteOffset: number, littleEndian?: boolean): number; + /** + * Gets the Uint16 value at the specified byte offset from the start of the view. There is + * no alignment constraint; multi-byte values may be fetched from any offset. + * @param byteOffset The place in the buffer at which the value should be retrieved. + */ + getUint16(byteOffset: number, littleEndian?: boolean): number; + /** + * Gets the Int32 value at the specified byte offset from the start of the view. There is + * no alignment constraint; multi-byte values may be fetched from any offset. + * @param byteOffset The place in the buffer at which the value should be retrieved. + */ + getInt32(byteOffset: number, littleEndian?: boolean): number; + /** + * Gets the Uint32 value at the specified byte offset from the start of the view. There is + * no alignment constraint; multi-byte values may be fetched from any offset. + * @param byteOffset The place in the buffer at which the value should be retrieved. + */ + getUint32(byteOffset: number, littleEndian?: boolean): number; + /** + * Gets the Float32 value at the specified byte offset from the start of the view. There is + * no alignment constraint; multi-byte values may be fetched from any offset. + * @param byteOffset The place in the buffer at which the value should be retrieved. + */ + getFloat32(byteOffset: number, littleEndian?: boolean): number; + /** + * Gets the Float64 value at the specified byte offset from the start of the view. There is + * no alignment constraint; multi-byte values may be fetched from any offset. + * @param byteOffset The place in the buffer at which the value should be retrieved. + */ + getFloat64(byteOffset: number, littleEndian?: boolean): number; + /** + * Stores an Int8 value at the specified byte offset from the start of the view. + * @param byteOffset The place in the buffer at which the value should be set. + * @param value The value to set. + */ + setInt8(byteOffset: number, value: number): void; + /** + * Stores an Uint8 value at the specified byte offset from the start of the view. + * @param byteOffset The place in the buffer at which the value should be set. + * @param value The value to set. + */ + setUint8(byteOffset: number, value: number): void; + /** + * Stores an Int16 value at the specified byte offset from the start of the view. + * @param byteOffset The place in the buffer at which the value should be set. + * @param value The value to set. + * @param littleEndian If false or undefined, a big-endian value should be written, + * otherwise a little-endian value should be written. + */ + setInt16(byteOffset: number, value: number, littleEndian?: boolean): void; + /** + * Stores an Uint16 value at the specified byte offset from the start of the view. + * @param byteOffset The place in the buffer at which the value should be set. + * @param value The value to set. + * @param littleEndian If false or undefined, a big-endian value should be written, + * otherwise a little-endian value should be written. + */ + setUint16(byteOffset: number, value: number, littleEndian?: boolean): void; + /** + * Stores an Int32 value at the specified byte offset from the start of the view. + * @param byteOffset The place in the buffer at which the value should be set. + * @param value The value to set. + * @param littleEndian If false or undefined, a big-endian value should be written, + * otherwise a little-endian value should be written. + */ + setInt32(byteOffset: number, value: number, littleEndian?: boolean): void; + /** + * Stores an Uint32 value at the specified byte offset from the start of the view. + * @param byteOffset The place in the buffer at which the value should be set. + * @param value The value to set. + * @param littleEndian If false or undefined, a big-endian value should be written, + * otherwise a little-endian value should be written. + */ + setUint32(byteOffset: number, value: number, littleEndian?: boolean): void; + /** + * Stores an Float32 value at the specified byte offset from the start of the view. + * @param byteOffset The place in the buffer at which the value should be set. + * @param value The value to set. + * @param littleEndian If false or undefined, a big-endian value should be written, + * otherwise a little-endian value should be written. + */ + setFloat32(byteOffset: number, value: number, littleEndian?: boolean): void; + /** + * Stores an Float64 value at the specified byte offset from the start of the view. + * @param byteOffset The place in the buffer at which the value should be set. + * @param value The value to set. + * @param littleEndian If false or undefined, a big-endian value should be written, + * otherwise a little-endian value should be written. + */ + 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 opaque type TimeoutID; +declare opaque type IntervalID; +declare function clearInterval(intervalId: ?IntervalID): void; +declare function clearTimeout(timeoutId: ?TimeoutID): void; +declare function setTimeout>( + callback: (...args: TArguments) => mixed, + ms?: number, + ...args: TArguments +): TimeoutID; +declare function setInterval>( + callback: (...args: TArguments) => mixed, + ms?: number, + ...args: TArguments +): IntervalID; + +/* Reflect API */ + +declare var Reflect: { + apply(target: (...any) => any, thisArg?: any, argumentsList?: Array): any, + construct(target: (...any) => any, argumentsList?: Array, newTarget?: any): any, + defineProperty(o: any, p: any, attributes: any): boolean, + deleteProperty(o: any, p: any): boolean, + get(o: any, p: any, receiver?: any): any, + getOwnPropertyDescriptor(o: any, p: any): any, + getPrototypeOf: Object$GetPrototypeOf, + setPrototypeOf: Object$SetPrototypeOf, + has(o: any, p: any): boolean, + isExtensible(o: any): boolean, + ownKeys(o: any): Array, + preventExtensions(o: any): boolean, + set(o: any, p: any, value: any, receiver?: any): boolean, + ... +} + +/* Proxy */ + +type Proxy$traps = { + getPrototypeOf?: (target: T) => {[any] : any, ...} | null, + setPrototypeOf?: (target: T, prototype: {[any] : any, ...} | null) => boolean, + isExtensible?: (target: T) => boolean, + preventExtensions?: (target: T) => boolean, + getOwnPropertyDescriptor?: (target: T, property: string) => void | PropertyDescriptor, + defineProperty?: (target: T, property: string, descriptor: PropertyDescriptor) => boolean, + has?: (target: T, key: string) => boolean, + get?: (target: T, property: string, receiver: Proxy) => any, + set?: (target: T, property: string, value: any, receiver: Proxy) => boolean, + deleteProperty?: (target: T, property: string) => boolean, + ownKeys?: (target: T) => Array, + apply?: (target: T, context: any, args: Array) => any, + construct?: (target: T, args: Array, newTarget: (...any) => any) => {[any] : any, ...}, + ... +}; + +type Proxy$revocable = T & { revoke(): void, ... }; + +declare class Proxy { + constructor(target: T, handler: Proxy$traps): T; + + static revocable(target: T, handler: Proxy$traps): Proxy$revocable; +} + +/* CommonJS */ + +declare var global: any; + +declare var module: { + exports: any, + require(id: string): any, + id: string, + filename: string, + loaded: boolean, + parent: any, + children: Array, + builtinModules: Array, + ... +}; +declare var require: { + (id: string): any, + resolve: (id: string) => string, + cache: any, + main: typeof module, + ... +}; +declare var exports: any; + +/* Opaque type for module reference magic strings */ +declare opaque type $Flow$ModuleRef<+T>; + +/* Commonly available, shared between node and dom */ +declare var console: { + assert(condition: mixed, ...data: Array): void, + clear(): void, + count(label?: string): void, + countReset(label?: string): void, + debug(...data: Array): void, + dir(...data: Array): void, + dirxml(...data: Array): void, + error(...data: Array): void, + _exception(...data: Array): void, + group(...data: Array): void, + groupCollapsed(...data: Array): void, + groupEnd(): void, + info(...data: Array): void, + log(...data: Array): void, + profile(name?: string): void, + profileEnd(name?: string): void, + table(tabularData: { [key: string]: any, ... } | Array<{ [key: string]: any, ... }> | Array>): void, + time(label?: string): void, + timeEnd(label: string): void, + timeStamp(label?: string): void, + timeLog(label?: string, ...data?: Array): void, + trace(...data: Array): void, + warn(...data: Array): void, + ... +}; + +type $EnumProto = {| + cast(input: ?TRepresentation): void | TEnum, + isValid(input: ?TRepresentation): boolean, + members(): Iterable, + __proto__: null, +|} + +declare class SharedArrayBuffer { + constructor(byteLength: number): void; + + /** + * Read-only. The length of the ArrayBuffer (in bytes). + */ + +byteLength: number; + /** + * Returns a section of an SharedArrayBuffer. + */ + slice(begin?: number, end?: number): this; + + +[key: $SymbolToStringTag]: 'SharedArrayBuffer'; +} + +type $SharedIntegerTypedArray = + | Int8Array + | Uint8Array + | Int16Array + | Uint16Array + | Int32Array + | Uint32Array + +declare var Atomics: { + /** + * Adds a value to the value at the given position in the array, returning the original value. + * Until this atomic operation completes, any other read or write operation against the array + * will block. + */ + add(typedArray: $SharedIntegerTypedArray, index: number, value: number): number, + /** + * Stores the bitwise AND of a value with the value at the given position in the array, + * returning the original value. Until this atomic operation completes, any other read or + * write operation against the array will block. + */ + and(typedArray: $SharedIntegerTypedArray, index: number, value: number): number, + /** + * Replaces the value at the given position in the array if the original value equals the given + * expected value, returning the original value. Until this atomic operation completes, any + * other read or write operation against the array will block. + */ + compareExchange(typedArray: $SharedIntegerTypedArray, index: number, expectedValue: number, replacementValue: number): number, + /** + * Replaces the value at the given position in the array, returning the original value. Until + * this atomic operation completes, any other read or write operation against the array will + * block. + */ + exchange(typedArray: $SharedIntegerTypedArray, index: number, value: number): number, + /** + * Returns the value at the given position in the array. Until this atomic operation completes, + * any other read or write operation against the array will block. + */ + load(typedArray: $SharedIntegerTypedArray, index: number): number, + /** + * Stores the bitwise OR of a value with the value at the given position in the array, + * returning the original value. Until this atomic operation completes, any other read or write + * operation against the array will block. + */ + or(typedArray: $SharedIntegerTypedArray, index: number, value: number): number, + /** + * Stores a value at the given position in the array, returning the new value. Until this + * atomic operation completes, any other read or write operation against the array will block. + */ + store(typedArray: $SharedIntegerTypedArray, index: number, value: number): number, + /** + * Subtracts a value from the value at the given position in the array, returning the original + * value. Until this atomic operation completes, any other read or write operation against the + * array will block. + */ + sub(typedArray: $SharedIntegerTypedArray, index: number, value: number): number, + /** + * Stores the bitwise XOR of a value with the value at the given position in the array, + * returning the original value. Until this atomic operation completes, any other read or write + * operation against the array will block. + */ + xor(typedArray: $SharedIntegerTypedArray, index: number, value: number): number, + + /** + * Returns a value indicating whether high-performance algorithms can use atomic operations + * (`true`) or must use locks (`false`) for the given number of bytes-per-element of a typed + * array. + */ + isLockFree(size: number): boolean, + /** + * If the value at the given position in the array is equal to the provided value, the current + * agent is put to sleep causing execution to suspend until the timeout expires (returning + * `"timed-out"`) or until the agent is awoken (returning `"ok"`); otherwise, returns + * `"not-equal"`. + */ + wait(typedArray: Int32Array, index: number, value: number, timeout?: number): 'ok' | 'not-equal' | 'timed-out', + /** + * Wakes up sleeping agents that are waiting on the given index of the array, returning the + * number of agents that were awoken. + * @param typedArray A shared Int32Array. + * @param index The position in the typedArray to wake up on. + * @param count The number of sleeping agents to notify. Defaults to +Infinity. + */ + notify(typedArray: Int32Array, index: number, count: number): number, + + +[key: $SymbolToStringTag]: 'Atomics', + ... +}; diff --git a/flow-typed/node.js b/flow-typed/node.js new file mode 100644 index 00000000000..cd829503afc --- /dev/null +++ b/flow-typed/node.js @@ -0,0 +1,5 @@ +declare class Process extends events$EventEmitter { + env : { [key: string] : string | void, ... }; +} + +declare var process: Process; diff --git a/src/jsutils/mapValue.js b/src/jsutils/mapValue.js index 09e68784427..dee335b6648 100644 --- a/src/jsutils/mapValue.js +++ b/src/jsutils/mapValue.js @@ -1,5 +1,3 @@ -import { objectEntries } from '../polyfills/objectEntries'; - import type { ObjMap } from './ObjMap'; /** @@ -12,7 +10,7 @@ export function mapValue( ): ObjMap { const result = Object.create(null); - for (const [key, value] of objectEntries(map)) { + for (const [key, value] of Object.entries(map)) { result[key] = fn(value, key); } return result; diff --git a/src/jsutils/toObjMap.js b/src/jsutils/toObjMap.js index 5d618793abf..69ac0d06ad9 100644 --- a/src/jsutils/toObjMap.js +++ b/src/jsutils/toObjMap.js @@ -1,5 +1,3 @@ -import { objectEntries } from '../polyfills/objectEntries'; - import type { ObjMap, ObjMapLike, @@ -18,7 +16,7 @@ export function toObjMap(obj) { } const map = Object.create(null); - for (const [key, value] of objectEntries(obj)) { + for (const [key, value] of Object.entries(obj)) { map[key] = value; } return map; diff --git a/src/polyfills/README.md b/src/polyfills/README.md deleted file mode 100644 index 20c9f6ee586..00000000000 --- a/src/polyfills/README.md +++ /dev/null @@ -1,8 +0,0 @@ -## Polyfills - -This directory contains dependency-free polyfills for ES6 & ES7 functions used -throughout the codebase. - -Each polyfill should belong in its own file and be the default export. - -These functions are not part of the module interface and are subject to change. diff --git a/src/polyfills/objectEntries.js b/src/polyfills/objectEntries.js deleted file mode 100644 index 907ac00537a..00000000000 --- a/src/polyfills/objectEntries.js +++ /dev/null @@ -1,8 +0,0 @@ -import type { ObjMap } from '../jsutils/ObjMap'; - -declare function objectEntries(obj: ObjMap): Array<[string, T]>; - -/* eslint-disable no-redeclare */ -// $FlowFixMe[name-already-bound] workaround for: https://github.com/facebook/flow/issues/4441 -export const objectEntries = - Object.entries || ((obj) => Object.keys(obj).map((key) => [key, obj[key]])); diff --git a/src/polyfills/objectValues.js b/src/polyfills/objectValues.js deleted file mode 100644 index bcc363a24f3..00000000000 --- a/src/polyfills/objectValues.js +++ /dev/null @@ -1,8 +0,0 @@ -import type { ObjMap } from '../jsutils/ObjMap'; - -declare function objectValues(obj: ObjMap): Array; - -/* eslint-disable no-redeclare */ -// $FlowFixMe[name-already-bound] workaround for: https://github.com/facebook/flow/issues/4441 -export const objectValues = - Object.values || ((obj) => Object.keys(obj).map((key) => obj[key])); diff --git a/src/type/definition.js b/src/type/definition.js index 3bdfa16b846..4a7afed3cda 100644 --- a/src/type/definition.js +++ b/src/type/definition.js @@ -1,5 +1,3 @@ -import { objectEntries } from '../polyfills/objectEntries'; - import type { Path } from '../jsutils/Path'; import type { PromiseOrValue } from '../jsutils/PromiseOrValue'; import type { @@ -811,7 +809,7 @@ function defineFieldMap( `${config.name}.${fieldName} args must be an object with argument names as keys.`, ); - const args = objectEntries(argsConfig).map(([argName, argConfig]) => ({ + const args = Object.entries(argsConfig).map(([argName, argConfig]) => ({ name: argName, description: argConfig.description, type: argConfig.type, @@ -1388,7 +1386,7 @@ function defineEnumValues( isPlainObj(valueMap), `${typeName} values must be an object with value names as keys.`, ); - return objectEntries(valueMap).map(([valueName, valueConfig]) => { + return Object.entries(valueMap).map(([valueName, valueConfig]) => { devAssert( isPlainObj(valueConfig), `${typeName}.${valueName} must refer to an object with a "value" key ` + diff --git a/src/type/directives.js b/src/type/directives.js index af7a3ad2049..00b57ca1dd1 100644 --- a/src/type/directives.js +++ b/src/type/directives.js @@ -1,5 +1,3 @@ -import { objectEntries } from '../polyfills/objectEntries'; - import type { ReadOnlyObjMap, ReadOnlyObjMapLike } from '../jsutils/ObjMap'; import { inspect } from '../jsutils/inspect'; import { toObjMap } from '../jsutils/toObjMap'; @@ -71,7 +69,7 @@ export class GraphQLDirective { `@${config.name} args must be an object with argument names as keys.`, ); - this.args = objectEntries(args).map(([argName, argConfig]) => ({ + this.args = Object.entries(args).map(([argName, argConfig]) => ({ name: argName, description: argConfig.description, type: argConfig.type, diff --git a/src/type/introspection.js b/src/type/introspection.js index bbc5554d5aa..75e2d7f4746 100644 --- a/src/type/introspection.js +++ b/src/type/introspection.js @@ -1,5 +1,3 @@ -import { objectValues } from '../polyfills/objectValues'; - import { inspect } from '../jsutils/inspect'; import { invariant } from '../jsutils/invariant'; @@ -48,7 +46,7 @@ export const __Schema = new GraphQLObjectType({ description: 'A list of all types supported by this server.', type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(__Type))), resolve(schema) { - return objectValues(schema.getTypeMap()); + return Object.values(schema.getTypeMap()); }, }, queryType: { @@ -255,7 +253,7 @@ export const __Type = new GraphQLObjectType({ }, resolve(type, { includeDeprecated }) { if (isObjectType(type) || isInterfaceType(type)) { - const fields = objectValues(type.getFields()); + const fields = Object.values(type.getFields()); return includeDeprecated ? fields : fields.filter((field) => field.deprecationReason == null); @@ -302,7 +300,7 @@ export const __Type = new GraphQLObjectType({ }, resolve(type, { includeDeprecated }) { if (isInputObjectType(type)) { - const values = objectValues(type.getFields()); + const values = Object.values(type.getFields()); return includeDeprecated ? values : values.filter((field) => field.deprecationReason == null); diff --git a/src/type/schema.js b/src/type/schema.js index c7f1cc66083..326ddc9ee5e 100644 --- a/src/type/schema.js +++ b/src/type/schema.js @@ -1,5 +1,3 @@ -import { objectValues } from '../polyfills/objectValues'; - import type { ObjMap, ReadOnlyObjMap, @@ -335,7 +333,7 @@ export class GraphQLSchema { query: this.getQueryType(), mutation: this.getMutationType(), subscription: this.getSubscriptionType(), - types: objectValues(this.getTypeMap()), + types: Object.values(this.getTypeMap()), directives: this.getDirectives().slice(), extensions: this.extensions, astNode: this.astNode, @@ -406,14 +404,14 @@ function collectReferencedTypes( collectReferencedTypes(interfaceType, typeSet); } - for (const field of objectValues(namedType.getFields())) { + for (const field of Object.values(namedType.getFields())) { collectReferencedTypes(field.type, typeSet); for (const arg of field.args) { collectReferencedTypes(arg.type, typeSet); } } } else if (isInputObjectType(namedType)) { - for (const field of objectValues(namedType.getFields())) { + for (const field of Object.values(namedType.getFields())) { collectReferencedTypes(field.type, typeSet); } } diff --git a/src/type/validate.js b/src/type/validate.js index 800a54860eb..664c57332a5 100644 --- a/src/type/validate.js +++ b/src/type/validate.js @@ -1,5 +1,3 @@ -import { objectValues } from '../polyfills/objectValues'; - import { inspect } from '../jsutils/inspect'; import { GraphQLError } from '../error/GraphQLError'; @@ -214,7 +212,7 @@ function validateTypes(context: SchemaValidationContext): void { context, ); const typeMap = context.schema.getTypeMap(); - for (const type of objectValues(typeMap)) { + for (const type of Object.values(typeMap)) { // Ensure all provided types are in fact GraphQL type. if (!isNamedType(type)) { context.reportError( @@ -261,7 +259,7 @@ function validateFields( context: SchemaValidationContext, type: GraphQLObjectType | GraphQLInterfaceType, ): void { - const fields = objectValues(type.getFields()); + const fields = Object.values(type.getFields()); // Objects and Interfaces both must define one or more fields. if (fields.length === 0) { @@ -360,7 +358,7 @@ function validateTypeImplementsInterface( const typeFieldMap = type.getFields(); // Assert each interface field is implemented. - for (const ifaceField of objectValues(iface.getFields())) { + for (const ifaceField of Object.values(iface.getFields())) { const fieldName = ifaceField.name; const typeField = typeFieldMap[fieldName]; @@ -523,7 +521,7 @@ function validateInputFields( context: SchemaValidationContext, inputObj: GraphQLInputObjectType, ): void { - const fields = objectValues(inputObj.getFields()); + const fields = Object.values(inputObj.getFields()); if (fields.length === 0) { context.reportError( @@ -586,7 +584,7 @@ function createInputObjectCircularRefsValidator( visitedTypes[inputObj.name] = true; fieldPathIndexByTypeName[inputObj.name] = fieldPath.length; - const fields = objectValues(inputObj.getFields()); + const fields = Object.values(inputObj.getFields()); for (const field of fields) { if (isNonNullType(field.type) && isInputObjectType(field.type.ofType)) { const fieldType = field.type.ofType; diff --git a/src/utilities/astFromValue.js b/src/utilities/astFromValue.js index 0c95bfef3f7..b1d06a7cbfd 100644 --- a/src/utilities/astFromValue.js +++ b/src/utilities/astFromValue.js @@ -1,5 +1,3 @@ -import { objectValues } from '../polyfills/objectValues'; - import { inspect } from '../jsutils/inspect'; import { invariant } from '../jsutils/invariant'; import { isObjectLike } from '../jsutils/isObjectLike'; @@ -84,7 +82,7 @@ export function astFromValue(value: mixed, type: GraphQLInputType): ?ValueNode { return null; } const fieldNodes = []; - for (const field of objectValues(type.getFields())) { + for (const field of Object.values(type.getFields())) { const fieldValue = astFromValue(value[field.name], field.type); if (fieldValue) { fieldNodes.push({ diff --git a/src/utilities/buildClientSchema.js b/src/utilities/buildClientSchema.js index d799e1eb6e2..dd03316a458 100644 --- a/src/utilities/buildClientSchema.js +++ b/src/utilities/buildClientSchema.js @@ -1,5 +1,3 @@ -import { objectValues } from '../polyfills/objectValues'; - import { inspect } from '../jsutils/inspect'; import { devAssert } from '../jsutils/devAssert'; import { keyValMap } from '../jsutils/keyValMap'; @@ -116,7 +114,7 @@ export function buildClientSchema( query: queryType, mutation: mutationType, subscription: subscriptionType, - types: objectValues(typeMap), + types: Object.values(typeMap), directives, assumeValid: options?.assumeValid, }); diff --git a/src/utilities/coerceInputValue.js b/src/utilities/coerceInputValue.js index fb2a598ab92..9b0529c53c5 100644 --- a/src/utilities/coerceInputValue.js +++ b/src/utilities/coerceInputValue.js @@ -1,5 +1,3 @@ -import { objectValues } from '../polyfills/objectValues'; - import type { Path } from '../jsutils/Path'; import { inspect } from '../jsutils/inspect'; import { invariant } from '../jsutils/invariant'; @@ -100,7 +98,7 @@ function coerceInputValueImpl( const coercedValue = {}; const fieldDefs = type.getFields(); - for (const field of objectValues(fieldDefs)) { + for (const field of Object.values(fieldDefs)) { const fieldValue = inputValue[field.name]; if (fieldValue === undefined) { diff --git a/src/utilities/extendSchema.js b/src/utilities/extendSchema.js index 0d197490bba..ba79e9645f6 100644 --- a/src/utilities/extendSchema.js +++ b/src/utilities/extendSchema.js @@ -1,5 +1,3 @@ -import { objectValues } from '../polyfills/objectValues'; - import { keyMap } from '../jsutils/keyMap'; import { inspect } from '../jsutils/inspect'; import { mapValue } from '../jsutils/mapValue'; @@ -205,7 +203,7 @@ export function extendSchemaImpl( return { description: schemaDef?.description?.value, ...operationTypes, - types: objectValues(typeMap), + types: Object.values(typeMap), directives: [ ...schemaConfig.directives.map(replaceDirective), ...directiveDefs.map(buildDirective), diff --git a/src/utilities/findBreakingChanges.js b/src/utilities/findBreakingChanges.js index 9000cc63c32..8fb29c87c13 100644 --- a/src/utilities/findBreakingChanges.js +++ b/src/utilities/findBreakingChanges.js @@ -1,5 +1,3 @@ -import { objectValues } from '../polyfills/objectValues'; - import { keyMap } from '../jsutils/keyMap'; import { inspect } from '../jsutils/inspect'; import { invariant } from '../jsutils/invariant'; @@ -177,8 +175,8 @@ function findTypeChanges( const schemaChanges = []; const typesDiff = diff( - objectValues(oldSchema.getTypeMap()), - objectValues(newSchema.getTypeMap()), + Object.values(oldSchema.getTypeMap()), + Object.values(newSchema.getTypeMap()), ); for (const oldType of typesDiff.removed) { @@ -226,8 +224,8 @@ function findInputObjectTypeChanges( ): Array { const schemaChanges = []; const fieldsDiff = diff( - objectValues(oldType.getFields()), - objectValues(newType.getFields()), + Object.values(oldType.getFields()), + Object.values(newType.getFields()), ); for (const newField of fieldsDiff.added) { @@ -347,8 +345,8 @@ function findFieldChanges( ): Array { const schemaChanges = []; const fieldsDiff = diff( - objectValues(oldType.getFields()), - objectValues(newType.getFields()), + Object.values(oldType.getFields()), + Object.values(newType.getFields()), ); for (const oldField of fieldsDiff.removed) { diff --git a/src/utilities/lexicographicSortSchema.js b/src/utilities/lexicographicSortSchema.js index 8dd6acd5d45..ea15603147e 100644 --- a/src/utilities/lexicographicSortSchema.js +++ b/src/utilities/lexicographicSortSchema.js @@ -1,5 +1,3 @@ -import { objectValues } from '../polyfills/objectValues'; - import type { ObjMap } from '../jsutils/ObjMap'; import { inspect } from '../jsutils/inspect'; import { invariant } from '../jsutils/invariant'; @@ -49,7 +47,7 @@ export function lexicographicSortSchema(schema: GraphQLSchema): GraphQLSchema { return new GraphQLSchema({ ...schemaConfig, - types: objectValues(typeMap), + types: Object.values(typeMap), directives: sortByName(schemaConfig.directives).map(sortDirective), query: replaceMaybeType(schemaConfig.query), mutation: replaceMaybeType(schemaConfig.mutation), diff --git a/src/utilities/printSchema.js b/src/utilities/printSchema.js index 205f80f5ca6..456af5fa679 100644 --- a/src/utilities/printSchema.js +++ b/src/utilities/printSchema.js @@ -1,5 +1,3 @@ -import { objectValues } from '../polyfills/objectValues'; - import { inspect } from '../jsutils/inspect'; import { invariant } from '../jsutils/invariant'; @@ -58,7 +56,7 @@ function printFilteredSchema( typeFilter: (type: GraphQLNamedType) => boolean, ): string { const directives = schema.getDirectives().filter(directiveFilter); - const types = objectValues(schema.getTypeMap()).filter(typeFilter); + const types = Object.values(schema.getTypeMap()).filter(typeFilter); return ( [printSchemaDefinition(schema)] @@ -206,14 +204,14 @@ function printEnum(type: GraphQLEnumType): string { } function printInputObject(type: GraphQLInputObjectType): string { - const fields = objectValues(type.getFields()).map( + const fields = Object.values(type.getFields()).map( (f, i) => printDescription(f, ' ', !i) + ' ' + printInputValue(f), ); return printDescription(type) + `input ${type.name}` + printBlock(fields); } function printFields(type: GraphQLObjectType | GraphQLInterfaceType): string { - const fields = objectValues(type.getFields()).map( + const fields = Object.values(type.getFields()).map( (f, i) => printDescription(f, ' ', !i) + ' ' + diff --git a/src/utilities/valueFromAST.js b/src/utilities/valueFromAST.js index abf1e6526bf..258976462b9 100644 --- a/src/utilities/valueFromAST.js +++ b/src/utilities/valueFromAST.js @@ -1,5 +1,3 @@ -import { objectValues } from '../polyfills/objectValues'; - import type { ObjMap } from '../jsutils/ObjMap'; import { keyMap } from '../jsutils/keyMap'; import { inspect } from '../jsutils/inspect'; @@ -110,7 +108,7 @@ export function valueFromAST( } const coercedObj = Object.create(null); const fieldNodes = keyMap(valueNode.fields, (field) => field.name.value); - for (const field of objectValues(type.getFields())) { + for (const field of Object.values(type.getFields())) { const fieldNode = fieldNodes[field.name]; if (!fieldNode || isMissingVariable(fieldNode.value, variables)) { if (field.defaultValue !== undefined) { diff --git a/src/validation/rules/OverlappingFieldsCanBeMergedRule.js b/src/validation/rules/OverlappingFieldsCanBeMergedRule.js index 2aa25715eaa..830c4098a69 100644 --- a/src/validation/rules/OverlappingFieldsCanBeMergedRule.js +++ b/src/validation/rules/OverlappingFieldsCanBeMergedRule.js @@ -1,5 +1,3 @@ -import { objectEntries } from '../../polyfills/objectEntries'; - import type { ObjMap } from '../../jsutils/ObjMap'; import { inspect } from '../../jsutils/inspect'; @@ -463,7 +461,7 @@ function collectConflictsWithin( // name and the value at that key is a list of all fields which provide that // response name. For every response name, if there are multiple fields, they // must be compared to find a potential conflict. - for (const [responseName, fields] of objectEntries(fieldMap)) { + for (const [responseName, fields] of Object.entries(fieldMap)) { // This compares every field in the list to every other field in this list // (except to itself). If the list only has one item, nothing needs to // be compared. diff --git a/src/validation/rules/ValuesOfCorrectTypeRule.js b/src/validation/rules/ValuesOfCorrectTypeRule.js index d02d58ce1da..6d5dc5c1ca8 100644 --- a/src/validation/rules/ValuesOfCorrectTypeRule.js +++ b/src/validation/rules/ValuesOfCorrectTypeRule.js @@ -1,5 +1,3 @@ -import { objectValues } from '../../polyfills/objectValues'; - import { keyMap } from '../../jsutils/keyMap'; import { inspect } from '../../jsutils/inspect'; import { didYouMean } from '../../jsutils/didYouMean'; @@ -50,7 +48,7 @@ export function ValuesOfCorrectTypeRule( } // Ensure every required field exists. const fieldNodeMap = keyMap(node.fields, (field) => field.name.value); - for (const fieldDef of objectValues(type.getFields())) { + for (const fieldDef of Object.values(type.getFields())) { const fieldNode = fieldNodeMap[fieldDef.name]; if (!fieldNode && isRequiredInputField(fieldDef)) { const typeStr = inspect(fieldDef.type);