export declare const arrays: { /** * Ensures the given parameter is an array. */ ensure(array: T[] | T): T[]; /** * Creates an array with the given length and initializes each value with the given initValue. */ init(length: number, initValue: T): T[]; /** * 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(arr: T[], element: T): 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(arr: T[], predicate: (elem: T, index: number, arr: T[]) => 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(arr: T[], elements: T[]): boolean; /** * @returns the index of the replaced element */ replace(arr: T[], element: T, replacement: T): number; /** * Inserts the given element at the specified index. *

* This function uses {@link insertAll} which relies on Array.prototype.splice(). Check its js-doc for details. */ insert(arr: T[], element: T, index: number): void; /** * Inserts all elements of the `source` at the specified index into the `target`. * * If many elements are passed, they are inserted as chunks of 100'000 to prevent maximum call stack errors. * (Chrome throws a Maximum call stack size exceeded when using spread operator at around 125'000 items, Firefox can handle around 500'000). * * 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(target: T[], source: T | T[], 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(arr: T[], element: T, compareFunc: (a: T, b: T) => 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(arr: T[], elementToInsert: T, predicate: (elem: T, index: number, arr: T[]) => 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(arr: T[], elementToInsert: T, predicate: (elem: T, index: number, arr: T[]) => 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(arr: T[], fromIndex: number, toIndex: number): void; /** * Moves the given element before the sibling and returns the array with the new order. */ moveBefore(arr: T[], elementToMove: T, sibling: T): T[]; /** * Moves the given element after the sibling and returns the array with the new order. */ moveAfter(arr: T[], elementToMove: T, sibling: T): T[]; /** * Moves the given element to the position returns the array with the new order. */ moveTo(arr: T[], elementToMove: T, position: number): T[]; contains(haystack: T[], needle: T): boolean; containsAny(haystack: T[] | T, needles: T[] | T): boolean; containsAll(haystack: T[] | T, needles: T[] | T): boolean; first(arr: T[]): T; last(arr: T[]): T; /** * @returns true if the given argument is an array and has a length > 0, false in any other case. */ hasElements(arr: T[] | T): 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(arr: T[] | T): boolean; /** * @returns the size of the array, or 0 if the argument is not an array */ length(arr: T[] | T): number; /** * Pushes all elements of `source` to `target`. * * The implementation uses a loop to push the elements rather than `Array.apply` or the spread operator so it can handle very large arrays * (Chrome throws a Maximum call stack size exceeded when using spread operator at around 125'000 items, Firefox can handle around 500'000). * * In terms of performance, using a loop is about the same as with the spread operator. */ pushAll(target: T[], source: T | T[]): 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(array1: T[], array2: T[]): T[]; equalsIgnoreOrder(arr: any[], arr2: any[]): boolean; equals(arr: ArrayLike, arr2: ArrayLike): boolean; greater(arr: [], arr2: []): boolean; eachSibling(arr: ArrayLike, element: T, func: (elem: T, 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(arr: ArrayLike, predicate: (elem: T, index: number, arr: T[]) => boolean, thisArg?: any): number; /** * * @param thisArg optional "this" binding for predicate function */ find(arr: ArrayLike, predicate: (elem: T, index: number, arr: T[]) => boolean, thisArg?: any): T; findFrom(arr: ArrayLike, startIndex: number, predicate: (elem: T, index: number) => boolean, reverse?: boolean): T; findIndexFrom(arr: ArrayLike, startIndex: number, predicate: (elem: T, index: number) => boolean, reverse?: boolean): number; findFromForward(arr: ArrayLike, startIndex: number, predicate: (elem: T, index: number) => boolean): T; findIndexFromForward(arr: ArrayLike, startIndex: number, predicate: (elem: T, index: number) => boolean): number; findFromReverse(arr: ArrayLike, startIndex: number, predicate: (elem: T, index: number) => boolean): T; findIndexFromReverse(arr: ArrayLike, startIndex: number, predicate: (elem: T, index: number) => boolean): number; /** * Pushes all elements to the given array that are not null or undefined. */ pushIfDefined(arr: T[], ...elements: T[]): 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(arr: T[], element: T): 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, delimiter?: string, encodeHtml?: boolean): string; formatEncoded(arr: ArrayLike, 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(arr1: T[], arr2: T[]): T[]; flatMap(arr: T[] | T, 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(arr: T[], childrenAccessor: (T: any) => T[]): T[]; /** * 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(array: T[]): T; /** * 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(array: T[], keyMapper?: (el: T) => PropertyKey, valueMapper?: (el: T) => any): any; /** * If the argument is an empty array, null is returned. Otherwise, the argument is returned unchanged. */ nullIfEmpty(array: T[]): T[]; /** * Clears the content of an array in-place. 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(array: T[]): T[]; /** * 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(array: T[], element1: T, element2: T): 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(array: T[], template: T[], direction?: "asc" | "desc"): T[]; }; //# sourceMappingURL=arrays.d.ts.map