CoolFace
Apppublic

Pinsave/counterstrike

sourceHugging Faceupdated 3mo agoView on Hugging Face
1likes
lib.es2019.array.d.ts80 linesDownload Raw Back to lib
1/*! *****************************************************************************2Copyright (c) Microsoft Corporation. All rights reserved.3Licensed under the Apache License, Version 2.0 (the "License"); you may not use4this file except in compliance with the License. You may obtain a copy of the5License at http://www.apache.org/licenses/LICENSE-2.06 7THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY8KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED9WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,10MERCHANTABLITY OR NON-INFRINGEMENT.11 12See the Apache Version 2.0 License for specific language governing permissions13and limitations under the License.14***************************************************************************** */15 16 17/// <reference no-default-lib="true"/>18 19type FlatArray<Arr, Depth extends number> = {20    done: Arr;21    recur: Arr extends ReadonlyArray<infer InnerArr> ? FlatArray<InnerArr, [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20][Depth]>22        : Arr;23}[Depth extends -1 ? "done" : "recur"];24 25interface ReadonlyArray<T> {26    /**27     * Calls a defined callback function on each element of an array. Then, flattens the result into28     * a new array.29     * This is identical to a map followed by flat with depth 1.30     *31     * @param callback A function that accepts up to three arguments. The flatMap method calls the32     * callback function one time for each element in the array.33     * @param thisArg An object to which the this keyword can refer in the callback function. If34     * thisArg is omitted, undefined is used as the this value.35     */36    flatMap<U, This = undefined>(37        callback: (this: This, value: T, index: number, array: T[]) => U | ReadonlyArray<U>,38        thisArg?: This,39    ): U[];40 41    /**42     * Returns a new array with all sub-array elements concatenated into it recursively up to the43     * specified depth.44     *45     * @param depth The maximum recursion depth46     */47    flat<A, D extends number = 1>(48        this: A,49        depth?: D,50    ): FlatArray<A, D>[];51}52 53interface Array<T> {54    /**55     * Calls a defined callback function on each element of an array. Then, flattens the result into56     * a new array.57     * This is identical to a map followed by flat with depth 1.58     *59     * @param callback A function that accepts up to three arguments. The flatMap method calls the60     * callback function one time for each element in the array.61     * @param thisArg An object to which the this keyword can refer in the callback function. If62     * thisArg is omitted, undefined is used as the this value.63     */64    flatMap<U, This = undefined>(65        callback: (this: This, value: T, index: number, array: T[]) => U | ReadonlyArray<U>,66        thisArg?: This,67    ): U[];68 69    /**70     * Returns a new array with all sub-array elements concatenated into it recursively up to the71     * specified depth.72     *73     * @param depth The maximum recursion depth74     */75    flat<A, D extends number = 1>(76        this: A,77        depth?: D,78    ): FlatArray<A, D>[];79}80