UNPKG

@eclipse-scout/core

Version:
210 lines 10.4 kB
export declare const arrays: { /** * Ensures the given parameter is an array. */ ensure<T>(array: T[] | T): T[]; /** * Creates an array with the given length and initializes each value with the given initValue. */ init<T_1>(length: number, initValue: T_1): T_1[]; /** * Removes the first occurrence of the specified element from the array. * If the array does not contain the element, it stays unchanged. * * @returns true if an element was removed */ remove<T_2>(arr: T_2[], element: T_2): boolean; /** * Removes the first array element that matches the given predicate. * If no element matches the given predicate, the array stays unchanged. * * @returns true if an element was removed */ removeByPredicate<T_3>(arr: T_3[], predicate: (elem: T_3, index: number, arr: T_3[]) => boolean, thisArg?: any): boolean; /** * Removes every given element from the array * * @returns true if the array contained at least one of the specified elements */ removeAll<T_4>(arr: T_4[], elements: T_4[]): boolean; /** * @returns the index of the replaced element */ replace<T_5>(arr: T_5[], element: T_5, replacement: T_5): number; /** * Inserts the given element at the specified index. * <p> * This function uses {@link insertAll} which relies on Array.prototype.splice(). Check its js-doc for details. */ insert<T_6>(arr: T_6[], element: T_6, index: number): void; /** * Inserts all elements of the given array at the specified index. * * This function is based on Array.prototype.splice(). * Thus, if the 'index' is greater than the length of the array, 'elements' will be added to the end of the array 'arr'. * This may cause unexpected behavior on accessing arr[index] after insertion. * * The caller must ensure the size of the array. */ insertAll<T_7>(arr: T_7[], elements: T_7 | T_7[], index: number): void; /** * Inserts the given element into the array according to the sort order indicated by the given comparison function. * * All arguments are mandatory. */ insertSorted<T_8>(arr: T_8[], element: T_8, compareFunc: (a: T_8, b: T_8) => number): void; /** * Inserts to given element into the array directly BEFORE the first array element that matches the given predicate. * If no such element can be found, the new element is inserted at the BEGINNING of the array. * * @param thisArg optional "this" binding for predicate function */ insertBefore<T_9>(arr: T_9[], elementToInsert: T_9, predicate: (elem: T_9, index: number, arr: T_9[]) => boolean, thisArg?: any): void; /** * Inserts to given element into the array directly AFTER the first array element that matches the given predicate. * If no such element can be found, the new element is inserted at the END of the array. */ insertAfter<T_10>(arr: T_10[], elementToInsert: T_10, predicate: (elem: T_10, index: number, arr: T_10[]) => boolean): void; /** * Moves the element at fromIndex to toIndex. * * This function uses {@link insert} which relies on Array.prototype.splice(). Check its js-doc for details. */ move<T_11>(arr: T_11[], fromIndex: number, toIndex: number): void; /** * Moves the given element before the sibling and returns the array with the new order. */ moveBefore<T_12>(arr: T_12[], elementToMove: T_12, sibling: T_12): T_12[]; /** * Moves the given element after the sibling and returns the array with the new order. */ moveAfter<T_13>(arr: T_13[], elementToMove: T_13, sibling: T_13): T_13[]; /** * Moves the given element to the position returns the array with the new order. */ moveTo<T_14>(arr: T_14[], elementToMove: T_14, position: number): T_14[]; contains<T_15>(haystack: T_15[], needle: T_15): boolean; containsAny<T_16>(haystack: T_16 | T_16[], needles: T_16 | T_16[]): boolean; containsAll<T_17>(haystack: T_17 | T_17[], needles: T_17 | T_17[]): boolean; first<T_18>(arr: T_18[]): T_18; last<T_19>(arr: T_19[]): T_19; /** * @returns true if the given argument is an array and has a length > 0, false in any other case. */ hasElements<T_20>(arr: T_20 | T_20[]): boolean; /** * @returns true if the given argument is not an array or the length of the array is 0, false in any other case. */ empty<T_21>(arr: T_21 | T_21[]): boolean; /** * @returns the size of the array, or 0 if the argument is not an array */ length<T_22>(arr: T_22 | T_22[]): number; pushAll<T_23>(arr: T_23[], arr2: T_23 | T_23[]): void; /** * Merges the two given arrays and removes duplicate entries in O(n). * If the arrays contain objects instead of primitives, it uses their id to check for equality. */ union<T_24 extends string | number | { id: string; }>(array1: T_24[], array2: T_24[]): T_24[]; equalsIgnoreOrder(arr: any[], arr2: any[]): boolean; equals(arr: ArrayLike<any>, arr2: ArrayLike<any>): boolean; greater(arr: [], arr2: []): boolean; eachSibling<T_25>(arr: ArrayLike<T_25>, element: T_25, func: (elem: T_25, index: number) => void): void; /** * Alternative implementation of Array.findIndex(callback [, thisArg]), which is supported by most browsers. * See Array.findIndex for a detailed description. * * @param optional "this" binding for predicate function */ findIndex<T_26>(arr: ArrayLike<T_26>, predicate: (elem: T_26, index: number, arr: T_26[]) => boolean, thisArg?: any): number; /** * * @param thisArg optional "this" binding for predicate function */ find<T_27>(arr: ArrayLike<T_27>, predicate: (elem: T_27, index: number, arr: T_27[]) => boolean, thisArg?: any): T_27; findFrom<T_28>(arr: ArrayLike<T_28>, startIndex: number, predicate: (elem: T_28, index: number) => boolean, reverse?: boolean): T_28; findIndexFrom<T_29>(arr: ArrayLike<T_29>, startIndex: number, predicate: (elem: T_29, index: number) => boolean, reverse?: boolean): number; findFromForward<T_30>(arr: ArrayLike<T_30>, startIndex: number, predicate: (elem: T_30, index: number) => boolean): T_30; findIndexFromForward<T_31>(arr: ArrayLike<T_31>, startIndex: number, predicate: (elem: T_31, index: number) => boolean): number; findFromReverse<T_32>(arr: ArrayLike<T_32>, startIndex: number, predicate: (elem: T_32, index: number) => boolean): T_32; findIndexFromReverse<T_33>(arr: ArrayLike<T_33>, startIndex: number, predicate: (elem: T_33, index: number) => boolean): number; /** * Pushes all elements to the given array that are not null or undefined. */ pushIfDefined<T_34>(arr: T_34[], ...elements: T_34[]): void; /** * Pushes the given element if it does not already exist in the array and the element is truthy. Thus, the array is like a Set where every element * can only be added once to the collection. Note: the comparison is done with the === operator. */ pushSet<T_35>(arr: T_35[], element: T_35): void; /** * Creates a string containing all elements in the array separated by the given delimiter. * @param encodeHtml true to encode the elements, false if not. Default is false */ format(arr: ArrayLike<string>, delimiter?: string, encodeHtml?: boolean): string; formatEncoded(arr: ArrayLike<string>, delimiter?: string): string; max(arr: number[]): number; min(arr: number[]): number; /** * @returns all elements of the first array which are not in the second array */ diff<T_36>(arr1: T_36[], arr2: T_36[]): T_36[]; flatMap<T_37, R>(arr: T_37 | T_37[], func?: (T: any) => R | R[]): R[]; /** * Returns a flat array of all elements and their recursive child elements. * * @param arr The top-level list of all elements * @param childrenAccessor Function than extracts a list of child elements from a given element. Used to traverse the object structure. */ flattenRec<T_38>(arr: T_38[], childrenAccessor: (T: any) => T_38[]): T_38[]; /** * Replacement for indexOf() that works for arrays of jQuery objects (compares DOM nodes). * * @returns the first index of `$element` in `arr` or -1 if the element could not be found. */ $indexOf(arr: JQuery[], $element: JQuery): number; /** * Replacement for remove() that works for arrays of jQuery objects (compares DOM nodes). * * @returns true if the element was removed, false otherwise. */ $remove(arr: JQuery[], $element: JQuery): boolean; randomElement<T_39>(array: T_39[]): T_39; /** * Converts the given array to a map. For each element, key and value is determined by the given functions. * If no function is provided, the element itself is used. * * @param array array of elements * @param keyMapper function that maps each element to the target key * @param valueExtractor function that maps each element to the target value */ toMap<T_40>(array: T_40[], keyMapper?: (el: T_40) => PropertyKey, valueMapper?: (el: T_40) => any): any; /** * If the argument is an empty array, null is returned. Otherwise, the argument is returned unchanged. */ nullIfEmpty<T_41>(array: T_41[]): T_41[]; /** * Clears the content of an array <i>in-place</i>. All elements are removed from the array and the * length will be set to 0. If the given argument is not an array, nothing happens. * * This is a more readable version of `array.splice(0, a.length)`. * * The return value is an array of all deleted elements (never null). */ clear<T_42>(array: T_42[]): T_42[]; /** * Swaps the two elements in the array. * Does nothing if array is null or undefined or one of the element is not part of the array. */ swap<T_43>(array: T_43[], element1: T_43, element2: T_43): void; /** * Sorts the given array _in place_ according to the order of the template array. * Does nothing, if the array is null or undefined. * * @returns the given array which is now in order. */ sortBy<T_44>(array: T_44[], template: T_44[], direction?: 'asc' | 'desc'): T_44[]; }; //# sourceMappingURL=arrays.d.ts.map