UNPKG

@averagehelper/corde

Version:

A simple library for Discord bot tests. (Republished fork to demonstrate a bugfix)

113 lines (112 loc) 4.09 kB
/** * List is an extension of [Array](https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/Array). * It's contains some others functions that are no present in Array itself * While provide access direct to main Array functions. * * The main goal is to reduce the access to no relevant functions provided by Array and * specialize this class in iteration addition, reduction and search of elements. * @deprecated */ export declare class List<T> extends Array<T> { /** * Static function to create a new list based on an array. * Can also be used to create a empty list. * @param array Collection to be in list. */ static fromArray<U extends any>(array?: U[]): List<U>; /** * Initialize a new List. * @param values Initial values of the list */ constructor(...values: T[]); /** * Converts a array to List. * It do not modify the current values of the list. * * @param data Array with values to be converted. * @returns A new instance of List. (The list has no references this instance). */ toList<U extends any>(data: U[]): List<U>; /** * Get the first elements that match with the predicate. * Does the same of [Array.find](https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/Array/find). * @param predicate Comparator to find the element. * @returns The first element of the list that match with the predicate, * or null. */ single(predicate: (value: T) => boolean): T; /** * Picks the **first** element of the list, or null if no element exists. * @returns The first element or undefined if no element exists. */ first(): T | undefined; /** * Picks the **last** element of the list, or undefined if no element exists. * @returns The last element of the list of undefined if no element exists. */ last(): T | undefined; /** * Removes all elements of the list. * @returns This instance. */ clear(): List<T>; /** * Copy all elements of the list to a new List. * @returns The cloned list. */ clone(): List<T>; /** * Select all properties informed in parameter that are contained in * the List object. * * @param keys Properties of T to be picked. * * @returns All picked properties of T in a new List. * Returns an empty list of no element was found. * * @see [Pick](https://www.typescriptlang.org/docs/handbook/utility-types.html#picktype-keys) */ pick<K extends keyof T>(...keys: K[]): List<Pick<T, K>>; /** * Checks if the list has at least one element. * @returns True if there are elements in list, false if don't. */ any(): boolean; /** * Removes a element from the list. * @param data Element to be removed. * @returns This instance. */ remove(data: T): List<T>; /** * Removes an array of elements from the list. * @param data Array of elements. * @returns This instance. */ remove(data: T[]): List<T>; /** * Removes an list of elements from the list. * @param data List of elements. * @returns This instance. */ remove(data: List<T>): List<T>; /** * Get a element based on its **index**. * @param index Position in list of the element * @returns The element in the position informed. */ get(index: number): T; /** * Get a list of elements based in their **index**. * @param index Position of each element in list. * @returns A list with each element informed in array. * No existing elements will be ignored in addition on list. */ get(index: number[]): List<T>; has(element: T): boolean; map<U>(callbackfn: (value: T, index: number, array: T[]) => U, arg?: any): List<U>; take(from?: number, amount?: number): List<T>; forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): this; private _removeItem; private _isArray; }