import type { Arrayable, Nullable } from '@stacksjs/types'; /** * Convert `Arrayable` to `Array` * * @category Array * @example * ```ts * toArray('foo') // ['foo'] * toArray(['foo']) // ['foo'] * toArray(null) // [] * toArray(undefined) // [] * toArray(1) // [1] * toArray([1]) // [1] * toArray({ foo: 'bar' }) // [{ foo: 'bar' }] * toArray([{ foo: 'bar' }]) // [{ foo: 'bar' }] * ``` */ export declare function toArray(array?: Nullable>): Array; /** * Flatten `Arrayable` to `Array` * * @category Array * @example * ```ts * flatten([1, [2, [3, [4, [5]]]]]) // [1, 2, 3, 4, 5] * ``` */ export declare function flatten(array?: Nullable>): T[]; /** * Use rest arguments to merge arrays * * @category Array * @example * ```ts * mergeArrayable([1, 2], [3, 4], [5, 6]) // [1, 2, 3, 4, 5, 6] * ``` */ export declare function mergeArrayable(...args: Nullable>[]): Array; /** * Divide an array into two parts by a filter function * * @category Array * @example * ```ts * const [odd, even] = partition([1, 2, 3, 4], i => i % 2 != 0) * console.log(odd) // [1, 3] * console.log(even) // [2, 4] * ``` */ export declare function partition(array: readonly T[], _f1: PartitionFilter): [T[], T[]]; export declare function partition(array: readonly T[], _f1: PartitionFilter, _f2: PartitionFilter): [T[], T[], T[]]; export declare function partition(array: readonly T[], _f1: PartitionFilter, _f2: PartitionFilter, _f3: PartitionFilter): [T[], T[], T[], T[]]; export declare function partition(array: readonly T[], _f1: PartitionFilter, _f2: PartitionFilter, _f3: PartitionFilter, _f4: PartitionFilter): [T[], T[], T[], T[], T[]]; export declare function partition(array: readonly T[], _f1: PartitionFilter, _f2: PartitionFilter, _f3: PartitionFilter, _f4: PartitionFilter, _f5: PartitionFilter): [T[], T[], T[], T[], T[], T[]]; export declare function partition(array: readonly T[], _f1: PartitionFilter, _f2: PartitionFilter, _f3: PartitionFilter, _f4: PartitionFilter, _f5: PartitionFilter, _f6: PartitionFilter): [T[], T[], T[], T[], T[], T[], T[]]; /** * Unique an Array * * @category Array * @example * ```ts * uniq([1, 2, 3, 3, 2, 1]) // [1, 2, 3] * ``` */ export declare function uniq(array: readonly T[]): T[]; /** * Unique an Array * * @param array * @example * ```ts * unique([1, 2, 3, 3, 2, 1]) // [1, 2, 3] * ``` */ export declare function unique(array: readonly T[]): T[]; /** * Unique an Array by a custom equality function * * @category Array * @example * ```ts * uniqueBy([1, 2, 3, 3, 2, 1], (a, b) => a === b) // [1, 2, 3] * ``` */ export declare function uniqueBy(array: readonly T[], equalFn: (a: any, b: any) => boolean): T[]; /** * Get last item * * @category Array * @example * ```ts * last([1, 2, 3]) // 3 * ``` */ export declare function last(array: readonly []): undefined; export declare function last(array: readonly T[]): T; /** * Remove an item from Array. * * **Mutates the input array** via splice — the original reference shrinks * by one element. If you need a non-destructive version, use * `array.filter(x => x !== value)` instead. * * @category Array * @example * ```ts * const arr = [1, 2, 3] * remove(arr, 2) // true * Arr.remove(arr, 4) // false * console.log(arr) // [1, 3] */ export declare function remove(array: T[], value: T): boolean; /** * Get nth item of Array. Negative for backward * * @category Array * @example * ```ts * at([1, 2, 3], 1) // 2 * at([1, 2, 3], -1) // 3 * at([1, 2, 3], 3) // undefined * at([1, 2, 3], -4) // undefined * ``` */ export declare function at(array: readonly [], index: number): undefined; export declare function at(array: readonly T[], index: number): T; /** * Move an item from one index to another * @param array * @param from * @param to * * @category Array * @example * ```ts * move([1, 2, 3, 4], 0, 2) // [2, 3, 1, 4] * move([1, 2, 3, 4], 0, -1) // [2, 3, 4, 1] * move([1, 2, 3, 4], -1, 0) // [4, 1, 2, 3] * move([1, 2, 3, 4], -1, -2) // [1, 4, 2, 3] * move([1, 2, 3, 4], 1, 1) // [1, 2, 3, 4] * ``` */ export declare function move(array: T[], from: number, to: number): T[]; /** * Clamp a number to the index range of an array. * * @category Array * @example * ```ts * clampArrayRange([1, 2, 3], 0) // 0 * clampArrayRange([1, 2, 3], 1) // 1 * clampArrayRange([1, 2, 3], 2) // 2 * clampArrayRange([1, 2, 3], 3) // 2 * clampArrayRange([1, 2, 3], 4) // 2 * clampArrayRange([1, 2, 3], -1) // 0 */ export declare function clampArrayRange(arr: readonly unknown[], n: number): number; /** * Get random items from an array * * @category Array * @example * ```ts * sample([1, 2, 3, 4], 2) // [2, 3] * ``` */ export declare function sample(arr: T[], count: number): T[]; /** * Shuffle an array. This function mutates the array. * * @category Array * @example * ```ts * shuffle([1, 2, 3, 4]) // [2, 4, 1, 3] * ``` */ export declare function shuffle(array: T[]): T[]; export type PartitionFilter = (_i: T, _idx: number, _arr: readonly T[]) => any;