import type { Writable, numbers, strings, unknowns } from "../types"; /** * Creates array of pairs ([x, y, z] =\> [[x, y], [y, z]]). * @param arr - Array. * @returns Array of pairs. */ export declare function chain(arr: readonly T[]): ChainResult; /** * Creates an array of chunks. * @param arr - Array. * @param size - Chunk size. * @returns Array of chunks. */ export declare function chunk(arr: readonly T[], size?: number): Chunks; /** * Clones array. * @param arr - Array. * @returns New array. */ export declare function clone(arr: readonly [A]): [A]; /** * Clones array. * @param arr - Array. * @returns New array. */ export declare function clone(arr: readonly [A, B]): [A, B]; /** * Clones array. * @param arr - Array. * @returns New array. */ export declare function clone(arr: readonly [A, B, C]): [A, B, C]; /** * Clones array. * @param arr - Array. * @returns New array. */ export declare function clone(arr: readonly [A, B, C, D]): [A, B, C, D]; /** * Clones array. * @param arr - Array. * @returns New array. */ export declare function clone(arr: readonly T[]): T[]; /** * Removes element at given index. * @param arr - Array. * @param index - Index to be removed. * @returns New array with one element removed. */ export declare function drop(arr: readonly T[], index: number): readonly T[]; /** * Finds element matching value. * @param arr - Array. * @param value - Value. * @param keyOrReduce - Comparison key or reduce function. * @returns The first element matching value if available, _undefined_ otherwise. */ export declare function findBy(arr: readonly T[], value: V, keyOrReduce: KeyOrReduce): T | undefined; /** * Finds last index. * @param arr - Array. * @param predicate - Predicate. * @returns Last matching index. */ export declare function findLastIndex(arr: readonly T[], predicate: Predicate): number; /** * Returns the first element from an array. * @param arr - Array. * @returns The first element if available. * @throws Error otherwise. */ export declare function first(arr: readonly T[]): T; /** * Creates array from iterable. * @param iterable - Iterable. * @returns Array. */ export declare function fromIterable(iterable: Iterable): readonly T[]; /** * Creates array from mixed source. * @param value - Value. * @returns Value if it is an array, tuple containing value otherwise. */ export declare function fromMixed(value: Mixed): readonly T[]; /** * Creates array of numbers. * @param from - Lower limit (inclusive). * @param to - Upper limit (inclusive). * @param step - Step. * @returns Array of numbers. */ export declare function fromRange(from: number, to: number, step?: number): numbers; /** * Creates array from string. * @param str - String. * @returns Array. */ export declare function fromString(str: string): strings; /** * Returns element at given index. * @param arr - Array. * @param index - Index. * @returns Element if available. * @throws Error otherwise. */ export declare function get(arr: readonly T[], index: number): T; /** * Checks if array contains element matching value. * @param arr - Array. * @param value - Value. * @param keyOrReduce - Comparison key or reduce function. * @returns _True_ if array contains element matching value, _false_ otherwise. */ export declare function includesBy(arr: readonly T[], value: V, keyOrReduce: KeyOrReduce): boolean; /** * Creates an array of shared values. * @param arrays - Arrays. * @returns Array of shared values. */ export declare function intersection(...arrays: Arrays): readonly T[]; /** * Returns the last element from an array. * @param arr - Array. * @returns The last element if available. * @throws Error otherwise. */ export declare function last(arr: readonly T[]): T; /** * Omit object entries by predicate. * @param arr - Array. * @param predicate - Predicate. * @returns New object. */ export declare function omit(arr: readonly T[], predicate: Predicate): readonly T[]; /** * Adds element to the end of an array. * @param arr - Array. * @param value - Value. * @returns New array with one element added. */ export declare function push(arr: readonly T[], value: T): readonly T[]; /** * Replaces elements matching value if found, pushes value otherwise. * @param arr - Array. * @param value - Value. * @param keyOrReduce - Comparison key or reduce function. * @returns New array. */ export declare function pushOrReplaceBy(arr: readonly T[], value: T, keyOrReduce: KeyOrReduce): readonly T[]; /** * Adds element to the end of an array if it does already not exist. * @param arr - Array. * @param value - Value. * @returns New array with one element added. */ export declare function pushUnique(arr: readonly T[], value: T): readonly T[]; /** * Picks random element from an array. * @param arr - Array. * @returns Random element. */ export declare function random(arr: readonly T[]): T; /** * Removes elements matching value. * @param arr - Array. * @param value - Value. * @param keyOrReduce - Comparison key or reduce function. * @returns New array with matching elements removed. */ export declare function removeBy(arr: readonly T[], value: V, keyOrReduce: KeyOrReduce): readonly T[]; /** * Replaces element at given index. * @param arr - Array. * @param index - Index. * @param value - Value. * @returns New array with one element replaced. */ export declare function replace(arr: readonly T[], index: number, value: T): readonly T[]; /** * Replaces elements matching value. * @param arr - Array. * @param value - Value. * @param keyOrReduce - Comparison key or reduce function. * @returns New array with matching elements replaced. */ export declare function replaceBy(arr: readonly T[], value: T, keyOrReduce: KeyOrReduce): readonly T[]; /** * Reverses array. * @param arr - Array. * @returns New array. */ export declare function reverse(arr: readonly T[]): readonly T[]; /** * Returns the second element from an array. * @param arr - Array. * @returns The second element if available. * @throws Error otherwise. */ export declare function second(arr: readonly T[]): T; /** * Sorts array. * @param arr - Array. * @param compareFn - Comparison function. * @returns New array. */ export declare function sort(arr: readonly T[], compareFn?: (x: T, y: T) => number): readonly T[]; /** * Returns the third element from an array. * @param arr - Array. * @returns The third element if available. * @throws Error otherwise. */ export declare function third(arr: readonly T[]): T; /** * Adds/removes value to/from an array. * @param arr - Array. * @param value - Value. * @param keyOrReduce - Comparison key or reduce function. * @returns New array. */ export declare function toggleBy(arr: readonly T[], value: T, keyOrReduce: KeyOrReduce): readonly T[]; /** * Truncates array. * @param mutableArray - Array. */ export declare function truncate(mutableArray: Writable): void; /** * Creates unique array. * @param arr - Array. * @param keyOrReduce - Comparison key or reduce function. * @returns Unique array. */ export declare function uniqueBy(arr: readonly T[], keyOrReduce: KeyOrReduce): readonly T[]; /** * Adds element to the beginning of an array. * @param arr - Array. * @param value - Value. * @returns New array with one element added. */ export declare function unshift(arr: readonly T[], value: T): readonly T[]; /** * Replaces elements matching value if found, unshifts value otherwise. * @param arr - Array. * @param value - Value. * @param keyOrReduce - Comparison key or reduce function. * @returns New array. */ export declare function unshiftOrReplaceBy(arr: readonly T[], value: T, keyOrReduce: KeyOrReduce): readonly T[]; /** * Adds element to the beginning of an array if it does already not exist. * @param arr - Array. * @param value - Value. * @returns New array with one element added. */ export declare function unshiftUnique(arr: readonly T[], value: T): readonly T[]; /** * @internal */ export type Arrays = ReadonlyArray; export type ChainResult = ReadonlyArray; /** * @internal */ export type Chunks = ReadonlyArray; export type KeyOrReduce = PropertyKey | Reduce; export type Mixed = T | readonly T[]; export interface Predicate { /** * Checks object entry. * @param value - Value. * @param index - Index. * @param arr - Array. * @returns _True_ if object entry passes check, _false_ otherwise. */ (value: T, index: number, arr: readonly T[]): boolean; } export type PrefixKeys = { [K in string & keyof T as `${P}${K}`]: T[K]; }; export interface Reduce { /** * Reduces object. * @param obj - Object. * @returns Reduced value. */ (obj: T): unknown; } //# sourceMappingURL=array.d.ts.map