/** * @private */ declare const ISharedArrayBuffer: SharedArrayBufferConstructor | undefined; /** * Defines an abstract class with array utilities. */ export declare abstract class Arrays { /** * Contains an empty array. */ static readonly EMPTY: readonly []; /** * Contains all the possible typed arrays. */ private static readonly TYPED_ARRAYS; /** * Gets the supported typed arrays. */ static get supportedTypedArrays(): Array; /** * @constructor * * @private */ private constructor(); /** * Adds the specified item to the beginning of the given array. * * @param {Array} array Contains some array. * @param {*} item Contains some array item. * @return {Array} an array. */ static addFirst(array: T[], item: T): T[]; /** * Adds the specified item to the beginning of the given array. * * @param {Array} array Contains some array. * @param {*} item Contains some array item. * @return {Array} an array. */ static addFirst(array: T[], item: any): any[]; /** * Clones an array. * * @param {Array} array Contains some array. * @return {Array} the cloned array. */ static clone(array: T[]): T[]; /** * Checks whether the given array contains the given item. * * **Usage Examples:** * ```typescript * Arrays.contains([], "a"); // false * Arrays.contains(["a", "b", "c"], "c"); // true * Arrays.contains(["a", "b", "c"], "d"); // false * ``` * * @param {Array} array Contains some array. * @param {*} item Contains the item to be checked whether it exists in the * given array. * @return {Boolean} whether the given array contains the given item. * * @since v1.5.0 */ static contains(array: T[] | readonly T[], item: T): boolean; /** * Checks whether the specified array contains either of the specified * items. * * **Usage Examples:** * ```typescript * Arrays.containsAny([], "a"); // false * Arrays.containsAny(["a", "b", "c"], "g", "c", "i"); // true * Arrays.containsAny(["a", "b", "c"], "d", "e"); // false * ``` * * @param {Array} array Contains some array. * @param {Array} items Contains the items to be checked whether they exist * in the given array. * @return {Boolean} whether the specified array contains either of the * specified items. * * @since v1.5.0 */ static containsAny(array: T[] | readonly T[], ...items: T[]): boolean; /** * Checks whether the specified array contains none of the specified items. * * **Usage Examples:** * ```typescript * Arrays.containsNone([], "a"); // true * Arrays.containsNone(["a", "b", "c"], "g", "c", "i"); // true * Arrays.containsNone(["a", "b", "c"], "d", "e"); // true * ``` * * @param {Array} array Contains some array. * @param {Array} items Contains the items to be checked whether they exist * in the given array. * @return {Boolean} whether the specified array contains none of the * specified items. * * @since v1.6.5 */ static containsNone(array: T[] | readonly T[], ...items: T[]): boolean; /** * Calls the specified predicate function for each of the array elements. * * **Usage Examples:** * ```typescript * Arrays.each(['a', 'b', 'c'], (item, index, self) => { * // Code goes here.. * }) * ``` * * @param {Array} array Contains some array. * @param {Function} predicate Contains some predicate to be executed * for each array item. */ static each(array: readonly T[], predicate: (item: T, index: number, self: T[]) => void): void; /** * Calls the specified predicate function for each of the array elements. * * **Usage Examples:** * ```typescript * Arrays.each(['a', 'b', 'c'], (item, index, self) => { * // Code goes here.. * }) * ``` * * @param {Array} array Contains some array. * @param {Function} predicate Contains some predicate to be executed * for each array item. */ static each(array: T[], predicate: (item: T, index: number, self: T[]) => void): void; /** * Filters out unwanted values from the given array. * * @param {Array} array Contains some array to be filtered. * @param {*} unwantedValues Contains the values to be filtered out from the * array. * @return {Array} the filtered array. */ static filterOut(array: T[], unwantedValues: T[]): T[]; /** * Filters out unwanted values from the given array. * * @param {Array} array Contains some array to be filtered. * @param {*} unwantedValues Contains the values to be filtered out from the * array. * @return {Array} the filtered array. */ static filterOut(array: readonly T[], unwantedValues: T[]): T[]; /** * Filters out falsy values like `null`, `undefined`, `false`, `NaN`, `0`, * `-0`, `0n`, `""`. * * @param {Array} array Contains some array to be filtered. * @return {Array} the filtered array. */ static filterTruthy(array: T[]): T[]; /** * Filters out falsy values like `null`, `undefined`, `false`, `NaN`, `0`, * `-0`, `0n`, `""`. * * @param {Array} array Contains some array to be filtered. * @return {Array} the filtered array. */ static filterTruthy(array: readonly T[]): readonly T[]; /** * Gets the first array item. * * @param {Array} array Contains some array. * @return {*} the first array item. */ static first(array: T[]): T; /** * Gets the first array item. * * @param {Array} array Contains some array. * @return {*} the first array item. */ static first(array: []): null; /** * Gets the first array item. * * @param {Array} array Contains some array. * @return {*} the first array item. */ static first(array: readonly []): null; /** * Gets the first array item. * * @param {Array} array Contains some array. * @return {*} the first array item. */ static first(array: readonly T[]): T; /** * Flattens the specified array. * * **Usage Examples:** * ```typescript * const arr = [1,2,[3,4,5], [6],7,[8, [9, 10]]]; * Arrays.flatten(arr); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] * ``` * * @param {Array} array Contains the specified array. * @return {Array} the flattened array. */ static flatten(array: any[]): T[]; /** * Inserts the given item at the given index in the given array. * * **Usage Examples:** * ```typescript * const arr = ["f", "o", "o", "b", "r"]; * Arrays.insertAt(arr, 4, "a"); // ["f", "o", "o", "b", "a", "r"] * ``` * * @param {Array} array Contains some array. * @param {Number} index Contains the index at which to add the given items. * @param {*} item Contains the item to be inserted at the given * index. * @return {Array} the extended array. */ static insertAt(array: T[], index: number, item: T): T[]; /** * Inserts the given items at the given index in the given array. * * **Usage Examples:** * ```typescript * const arr = ["f", "o", "o", "b", "r"]; * Arrays.insertAt(arr, 4, "a"); // ["f", "o", "o", "b", "a", "r"] * ``` * * @param {Array} array Contains some array. * @param {Number} index Contains the index at which to add the given items. * @param {*} item Contains the items to be inserted at the given * index. * @return {Array} the extended array. */ static insertAt(array: T[], index: number, item: T[]): T[]; /** * Generates an array where each of the items of the given array is followed * by the given separator item. * * **Usage Examples:** * ```typescript * const arr1 = ['a', 'b', 'c']; * const arr2 = Arrays.intersperse(arr1, 'x'); * console.log(arr2); // 'a', 'x', 'b', 'x', 'c' * ``` * This method has been adopted from an article about readonly arrays written * by [Marius Schulz](https://mariusschulz.com/blog/read-only-array-and-tuple-types-in-typescript). * * @param {Array} array Contains some array. * @param {*} separator Contains some separator array item which appears after * each array item. * @return {Array} a new array where each of the items of the given array is * followed by the given separator item. */ static intersperse(array: T[], separator: T): T[]; /** * Checks whether the given value is an array. * * @param {*} value Contains some value. * @return {Boolean} whether the given value is an array. */ static isArray(value?: any | any[]): value is any[]; /** * Check whether the specified value is of type `ArrayBuffer`. * * **Usage Examples:** * ```typescript * Arrays.isArrayBuffer([]); // false * Arrays.isArrayBuffer(new ArrayBuffer(5)); // true * ``` * * @param {*} value Contains some value. * @return {Boolean} whether the specified value is of type `ArrayBuffer`. */ static isArrayBuffer(value?: any): boolean; /** * Checks whether the specified value is an array buffer view. * * @param {*} value Contains some value. * @return {Boolean} whether the specified value is an array buffer view. */ static isArrayBufferView(value?: any): boolean; /** * Checks whether the specified value is of type `BigInt64Array`. * * @param {*} value Contains some value. * @return {Boolean} whether the specified value is of type `BigInt64Array`. */ static isBigInt64Array(value?: any): value is BigInt64Array; /** * Checks whether the specified value is of type `BigUint64Array`. * * @param {*} value Contains some value. * @return {Boolean} whether the specified value is of type `BigUint64Array`. */ static isBigUint64Array(value?: any): value is BigUint64Array; /** * Checks whether the specified array of numbers is a binary array i. e. * whether its values are only `0` and `1`. * * @param {Array} array Contains an array of numbers. * @return {Boolean} whether the specified array of numbers is a binary * array i. e. whether its values are only `0` and `1`. */ static isBinary(array: number[]): boolean; /** * Checks whether the specified array of numbers is a binary array i. e. * whether its values are only `0` and `1`. * * @param {Array} array Contains an array of numbers. * @return {Boolean} whether the specified array of numbers is a binary * array i. e. whether its values are only `0` and `1`. */ static isBinary(array: readonly number[]): boolean; /** * Checks whether the given array is empty. * * @param {Array} array Contains some array. * @return {Boolean} whether the given array is empty. */ static isEmpty(array: T[]): boolean; /** * Checks whether the given array is empty. * * @param {Array} array Contains some array. * @return {Boolean} whether the given array is empty. */ static isEmpty(array: readonly T[]): boolean; /** * Checks whether the specified value is of type `Float32Array`. * * @param {*} value Contains some value. * @return {Boolean} whether the specified value is of type `Float32Array`. */ static isFloat32Array(value?: any): value is Float32Array; /** * Checks whether the specified value is of type `Float64Array`. * * @param {*} value Contains some value. * @return {Boolean} whether the specified value is of type `Float64Array`. */ static isFloat64Array(value?: any): value is Float64Array; /** * Checks whether the specified array is identical i. e. whether * all the array items are equal to one another. * * **Usage Examples:** * ```typescript * Arrays.isIdentical([]); // true * Arrays.isIdentical(["a"]); // true * Arrays.isIdentical(["a", "a"]); // true * Arrays.isIdentical(["a", "b"]); // false * Arrays.isIdentical([1, false]); // false * ``` * * @param {Array} array Contains some array. * @return {Boolean} whether the specified array is identical. */ static isIdentical(array: T[]): boolean; /** * Checks whether the specified value is of type `Int16Array`. * * @param {*} value Contains some value. * @return {Boolean} whether the specified value is of type `Int16Array`. */ static isInt16Array(value?: any): value is Int16Array; /** * Checks whether the specified value is of type `Int8Array`. * * @param {*} value Contains some value. * @return {Boolean} whether the specified value is of type `Int8Array`. */ static isInt8Array(value?: any): value is Int8Array; /** * Checks whether the specified value is of type `Int32Array`. * * @param {*} value Contains some value. * @return {Boolean} whether the specified value is of type `Int32Array`. */ static isInt32Array(value?: any): value is Int32Array; /** * Checks whether the specified value is an iterable object. * * @param {*} value Contains some value. * @return {Boolean} whether the specified value is an iterable object. */ static isIterable(value?: any): boolean; /** * Checks whether the given array is empty. * * @param {Array} array Contains some array. * @return {Boolean} whether the given array is empty. */ static isNotEmpty(array: T[]): boolean; /** * Checks whether the given array is empty. * * @param {Array} array Contains some array. * @return {Boolean} whether the given array is empty. */ static isNotEmpty(array: readonly T[]): boolean; /** * Checks whether the specified value is of type `SharedArrayBuffer`. * * @param {*} value Contains some value. * @return {Boolean} whether the specified value is of type * `SharedArrayBuffer`. */ static isSharedArrayBuffer(value?: any): value is typeof ISharedArrayBuffer extends undefined ? false : SharedArrayBuffer; /** * Checks whether the specified array is sorted. * * **Usage Examples:** * ```typescript * Arrays.isSorted([]); // true * Arrays.isSorted([1, 2, 3, 4]); // true * Arrays.isSorted([6, 1, 9, 4, 2]); // false * Arrays.isSorted([9, 8, 7, 6, 5, 4]); // false * ``` * * @param {Array} array Contains some array. * @return {Boolean} whether the specified array is sorted. */ static isSorted(array: T[]): boolean; /** * Checks whether the specified array is sorted. * * **Usage Examples:** * ```typescript * Arrays.isSorted([]); // true * Arrays.isSorted([1, 2, 3, 4]); // true * Arrays.isSorted([6, 1, 9, 4, 2]); // false * Arrays.isSorted([9, 8, 7, 6, 5, 4]); // false * ``` * * @param {Array} array Contains some array. * @return {Boolean} whether the specified array is sorted. */ static isSorted(array: readonly T[]): boolean; /** * Checks whether the specified value is a typed array. * * **Usage Examples:** * ```typescript * Arrays.isTypedArray(new Int8Array()); // true * Arrays.isTypedArray(new Int16Array()); // true * Arrays.isTypedArray(new Int32Array()); // true * Arrays.isTypedArray(new Float32Array()); // true * Arrays.isTypedArray(new Float64Array()); // true * Arrays.isTypedArray(new Uint8Array()); // true * Arrays.isTypedArray(new Uint8ClampedArray()); // true * Arrays.isTypedArray(new Uint16Array()); // true * Arrays.isTypedArray(new Uint32Array()); // true * ``` * * @param {*} value Contains some value. * @return {Boolean} whether the specified value is a typed array * i. e. of type `Uint8Array`, `Uint8ClampedArray`, `Int8Array`, * `Uint16Array`, `Uint16Array` */ static isTypedArray(value?: any): boolean; /** * Checks whether the specified value is of type `Uint16Array`. * * @param {*} value Contains some value. * @return {Boolean} whether the specified value is of type `Uint16Array`. */ static isUint16Array(value?: any): value is Uint16Array; /** * Checks whether the specified value is of type `Uint32Array`. * * @param {*} value Contains some value. * @return {Boolean} whether the specified value is of type `Uint32Array`. */ static isUint32Array(value?: any): value is Uint32Array; /** * Checks whether the specified value is of type `Uint8Array`. * * @param {*} value Contains some value. * @return {Boolean} whether the specified value is of type `Uint8Array`. */ static isUint8Array(value?: any): value is Uint8Array; /** * Checks whether the specified value is of type `Uint8ClampedArray`. * * @param {*} value Contains some value. * @return {Boolean} whether the specified value is of type * `Uint8ClampedArray`. */ static isUint8ClampedArray(value?: any): value is Uint8ClampedArray; /** * Gets the last array item. * * @param {Array} array Contains some array. * @return {*} the last array item. */ static last(array: T[]): T; /** * Gets the last array item. * * @param {Array} array Contains some array. * @return {*} the last array item. */ static last(array: []): null; /** * Gets the last array item. * * @param {Array} array Contains some array. * @return {*} the last array item. */ static last(array: readonly []): null; /** * Gets the last array item. * * @param {Array} array Contains some array. * @return {*} the last array item. */ static last(array: readonly T[]): T | null; /** * Removes the specified items from the given array. * * ```typescript * Arrays.removeAll([], 0); // [] * Arrays.removeAll([0], 0); // [] * Arrays.removeAll([1, 2, 3], 2, 3); // [1] * Arrays.removeAll([1, 2, 3], 1, 2, 3); // [] * ``` * * @param {Array} array Contains some array. * @param {Array} items Contains the array items to be removed. * @return {Array} an array. */ static removeAll(array: T[], ...items: T[]): T[]; /** * Removes the array item at the specified index and returns an array copy. * * **Usage Examples:** * ```typescript * Arrays.removeAt([], 0); // [] * Arrays.removeAt(['a'], 0); // [] * Arrays.removeAt(['a', 'b'], 1); // ['a'] * Arrays.removeAt(['a', 'b', 'c'], 0); // ['b', 'c'] * Arrays.removeAt(['a', 'b', 'c'], -1); // ['a', 'b'] * ``` * * @param {Array} array Contains some array. * @param {Number} index Contains the index of the array item to be removed. * @return {Array} an array. */ static removeAt(array: T[], index: number): T[]; /** * Reverses the specified array. * * **Usage Examples:** * ```typescript * Arrays.reverse([]); // [] * Arrays.reverse(["a"]); // ["a"] * Arrays.reverse(["a", "b", "c"]); // ["c", "b", "a"] * ``` * * @param {Array} array Contains some array. * @return {Array} the reverse array. */ static reverse(array: T[]): T[]; /** * Shuffles the specified array. * * @param {Array} array Contains some array. * @return {Array} an array. */ static shuffle(array: T[]): T[]; /** * Sorts the specified array. * * @param {Array} array Contains some array. * @param {String} order Contains the sorting order. Possible values are * `asc` (ascending order) and `desc` (descending order). Defaults to `desc`. * @return {Array} the sorted array. */ static sort(array: T[], order?: 'asc' | 'desc'): T[]; /** * Generates a subarray with items from the given start index to the given * end index of the items of the specified array. * * **Usage Examples:** * ```typescript * Arrays.subarray([], 0); // [] * Arrays.subarray([1, 2, 3], 0); // [1, 2, 3] * Arrays.subarray([1, 2, 3], 1); // [2, 3] * Arrays.subarray([1, 2, 3, 4], 1, 3); // [2, 3] * ``` * * @param {Array} array Contains some array. * @param {Number} start Contains the index of the first subarray item. * @param {Number} end Contains the index next to the last index of the * subarray. If not specified, the length of the given array is considered. * Defaults to `array.length`. * @return {Array} a subarray. */ static subarray(array: T[], start: number, end?: number): T[]; /** * Generates a subarray with items from the given start index to the given * end index of the items of the specified array. * * **Usage Examples:** * ```typescript * Arrays.subarray([], 0); // [] * Arrays.subarray([1, 2, 3], 0); // [1, 2, 3] * Arrays.subarray([1, 2, 3], 1); // [2, 3] * Arrays.subarray([1, 2, 3, 4], 1, 3); // [2, 3] * ``` * * @param {Array} array Contains some array. * @param {Number} start Contains the index of the first subarray item. * @param {Number} end Contains the index next to the last index of the * subarray. If not specified, the length of the given array is considered. * Defaults to `array.length`. * @return {Array} a subarray. */ static subarray(array: readonly T[], start: number, end?: number): T[]; /** * Calculates the sum of the numerical array items. * * @param {Array} array Contains some array of numbers. * @return {Number} the sum of the array items. */ static sum(array: number[]): number; /** * Calculates the sum of the numerical array items. * * @param {Array} array Contains some array of numbers. * @return {Number} the sum of the array items. */ static sum(array: readonly number[]): number; /** * Converts an iterable object to array. * * @param {Iterable} iterable Contains an iterable. * @return {Array} an array. */ static toArray(iterable: Iterable): T[]; /** * Removes duplicates from the given array. * * @param {Array} array Contains some array. * @return {Array} the array without duplicates. */ static unique(array: T[]): T[]; /** * Removes duplicates from the given array. * * @param {Array} array Contains some array. * @return {Array} the array without duplicates. */ static unique(array: readonly T[]): readonly T[]; private static __sortAsc; private static __sortDesc; } export {};