/** * Intersperses a separator element between each element of an array. * * Takes an array and a separator value, and returns a new array where the separator * is inserted between each pair of adjacent elements from the original array. * The separator is not added before the first element or after the last element. * * @template T - The type of elements in the input array * @template S - The type of the separator element * @param arr - The input array to intersperse * @param sep - The separator element to insert between array elements * @returns A new array with separator elements interspersed between original elements * * @example * ```typescript * intersperse([1, 2, 3], 0) * // Returns: [1, 0, 2, 0, 3] * * intersperse(['a', 'b', 'c'], '-') * // Returns: ['a', '-', 'b', '-', 'c'] * * intersperse([1], 0) * // Returns: [1] * * intersperse([], 0) * // Returns: [] * ``` */ declare function intersperse(arr: T[], sep: S): (T | S)[]; /** * Flattens a nested array by one level. * * Takes an array of arrays and returns a new array with all sub-arrays * concatenated into a single level. Only flattens one level deep. * * @template T - The type of elements in the nested arrays * @param arr - The array of arrays to flatten * @returns A new flattened array containing all elements from the sub-arrays * * @example * ```typescript * flatten([[1, 2], [3, 4], [5]]) * // Returns: [1, 2, 3, 4, 5] * * flatten([['a', 'b'], ['c'], ['d', 'e']]) * // Returns: ['a', 'b', 'c', 'd', 'e'] * * flatten([]) * // Returns: [] * * flatten([[], [1, 2], []]) * // Returns: [1, 2] * ``` */ declare function flatten(arr: T[][]): T[]; /** * Creates a cross join (Cartesian product) of two arrays. * * Takes two arrays and returns an array of tuples representing all possible * combinations where the first element comes from the first array and the * second element comes from the second array. * * @template T - The type of elements in the first array * @template U - The type of elements in the second array * @param arr1 - The first array * @param arr2 - The second array * @returns An array of tuples representing all combinations * * @example * ```typescript * crossJoin([1, 2], ['a', 'b']) * // Returns: [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']] * * crossJoin(['x'], [1, 2, 3]) * // Returns: [['x', 1], ['x', 2], ['x', 3]] * * crossJoin([], [1, 2]) * // Returns: [] * * crossJoin([1], []) * // Returns: [] * ``` */ declare function crossJoin(arr1: T[], arr2: U[]): [T, U][]; /** * Gets an element from an array at the specified index. * * Retrieves an element at the given index. Supports negative indices to count * from the end of the array. Returns the default value if the index is out of bounds. * * @template T - The type of elements in the array * @template D - The type of the default value * @param arr - The array to get the element from * @param index - The index to get, negative values count from the end * @param defaultValue - The value to return if index is out of bounds * @returns The element at the specified index or the default value * * @example * ```typescript * get([1, 2, 3, 4], 1) * // Returns: 2 * * get([1, 2, 3, 4], -1) * // Returns: 4 * * get([1, 2, 3], 10, 'default') * // Returns: 'default' * * get([], 0, 'empty') * // Returns: 'empty' * ``` */ declare function get(arr: T[], index: number, defaultValue?: D): T | D | undefined; /** * Gets the first element of an array. * * Returns the first element of the array, or the default value if the array is empty. * * @template T - The type of elements in the array * @template D - The type of the default value * @param arr - The array to get the first element from * @param defaultValue - The value to return if array is empty * @returns The first element or the default value * * @example * ```typescript * first([1, 2, 3]) * // Returns: 1 * * first(['a', 'b', 'c']) * // Returns: 'a' * * first([], 'default') * // Returns: 'default' * * first([]) * // Returns: undefined * ``` */ declare function first(arr: T[], defaultValue?: D): T | D | undefined; /** * Gets the last element of an array. * * Returns the last element of the array, or the default value if the array is empty. * * @template T - The type of elements in the array * @template D - The type of the default value * @param arr - The array to get the last element from * @param defaultValue - The value to return if array is empty * @returns The last element or the default value * * @example * ```typescript * last([1, 2, 3]) * // Returns: 3 * * last(['a', 'b', 'c']) * // Returns: 'c' * * last([], 'default') * // Returns: 'default' * * last([]) * // Returns: undefined * ``` */ declare function last(arr: T[], defaultValue?: D): T | D | undefined; /** * Splits an array into chunks based on size or a predicate function. * * If a number is provided, splits the array into chunks of that size. * If a function is provided, splits the array at positions where the function returns true. * * @template T - The type of elements in the array * @param arr - The array to split * @param sizeOrFunc - Either the chunk size (number) or a predicate function * @returns An array of arrays representing the chunks * * @example * ```typescript * split([1, 2, 3, 4, 5, 6], 2) * // Returns: [[1, 2], [3, 4], [5, 6]] * * split([1, 2, 3, 4, 5], 2) * // Returns: [[1, 2], [3, 4], [5]] * * split([1, 2, 3, 4, 5], (item, index) => item % 3 === 0) * // Returns: [[1, 2], [3], [4, 5]] * * split([], 2) * // Returns: [] * ``` */ declare function split(arr: T[], sizeOrFunc: number | ((item: T, index: number) => boolean)): T[][]; /** * Returns a random element from an array. * * Selects and returns a random element from the array. Returns undefined if the array is empty. * * @template T - The type of elements in the array * @param arr - The array to select a random element from * @returns A random element from the array or undefined if empty * * @example * ```typescript * random([1, 2, 3, 4, 5]) * // Returns: any element from the array (e.g., 3) * * random(['apple', 'banana', 'cherry']) * // Returns: any string from the array (e.g., 'banana') * * random([]) * // Returns: undefined * * random(['single']) * // Returns: 'single' * ``` */ declare function random(arr: T[]): T | undefined; /** * Returns a new array with elements shuffled in random order. * * Creates a new array with the same elements as the input array but in a random order. * Uses the Fisher-Yates shuffle algorithm for uniform distribution. * * @template T - The type of elements in the array * @param arr - The array to shuffle * @returns A new array with elements in random order * * @example * ```typescript * shuffle([1, 2, 3, 4, 5]) * // Returns: [3, 1, 5, 2, 4] (example, actual order will be random) * * shuffle(['a', 'b', 'c']) * // Returns: ['c', 'a', 'b'] (example, actual order will be random) * * shuffle([]) * // Returns: [] * * shuffle(['single']) * // Returns: ['single'] * ``` */ declare function shuffle(arr: T[]): T[]; /** * Creates a deep clone of an object or array. * * Performs a deep copy by recursively iterating through objects and arrays, * creating new instances with copied primitive values. Uncloneable types * (functions, symbols, etc.) are converted to undefined. Handles circular * references to prevent infinite loops. * * @param obj - The object or array to clone * @param visited - Internal WeakMap for tracking visited objects (used for circular reference detection) * @returns A deep clone of the input * * @example * ```typescript * deepClone({ a: 1, b: { c: 2 } }) * // Returns: { a: 1, b: { c: 2 } } (new object) * * const original = { x: [1, 2, 3], y: { z: 4 } }; * const cloned = deepClone(original); * cloned.x.push(4); * // original.x is still [1, 2, 3] * * deepClone({ fn: () => {}, num: 42 }) * // Returns: { fn: undefined, num: 42 } * ``` */ declare function deepClone(obj: T, visited?: WeakMap): T; /** * Deeply merges two objects based on these rules. * - for every given object key: * - if firstObject has the key but secondObject doesn't, firstObject's value is used * - if secondObject has the key but firstObject doesn't, secondObject's value is used * - if both values are primitive, the secondObject's value will be used * - if both values are objects, they are merged recursively * - if both values are arrays, they are merged based on the arrayMergeStrategy option * - if the values are of different types, the second value will be used * * @param firstObj First object to merge from * @param secondObj Second object to merge into * @param options - Options for merging behavior * @param options.arrayMergeStrategy - Strategy for merging arrays: 'replace' (default) or 'concat' * @returns The merged object */ declare function deepMerge(firstObj: Record, secondObj: Record, options?: { arrayMergeStrategy?: 'replace' | 'concat'; }): Record; /** * Recursively evaluates all nodes in an object using the provided async function. * * Traverses the object and applies the async function to each non-object value, * returning a new object with the evaluated values. If a value is a Promise, * it will be awaited before applying the function. Objects and arrays are processed * recursively. * * @param obj - The object to evaluate * @param func - The async function to apply to each non-object value * @returns A promise that resolves to the new object with evaluated values * * @example * ```typescript * const input = { * a: 1, * b: { * c: 2, * d: [3, 4] * } * }; * * const result = await evaluateAllNodes(input, async (value) => value * 2); * // result is: * // { * // a: 2, * // b: { * // c: 4, * // d: [6, 8] * // } * // } * ``` */ declare function evaluateAllNodes(obj: Record, func: (node: any) => any): Promise>; /** * traverse an object and apply a function to all branches (objects and arrays) * @param obj object to be traversed * @param func function to be applied to each branch * @returns traversed object */ declare function evaluateAllBranches(obj: Record, func: (node: any) => any): Promise>; declare const array_crossJoin: typeof crossJoin; declare const array_deepClone: typeof deepClone; declare const array_deepMerge: typeof deepMerge; declare const array_evaluateAllBranches: typeof evaluateAllBranches; declare const array_evaluateAllNodes: typeof evaluateAllNodes; declare const array_first: typeof first; declare const array_flatten: typeof flatten; declare const array_get: typeof get; declare const array_intersperse: typeof intersperse; declare const array_last: typeof last; declare const array_random: typeof random; declare const array_shuffle: typeof shuffle; declare const array_split: typeof split; declare namespace array { export { array_crossJoin as crossJoin, array_deepClone as deepClone, array_deepMerge as deepMerge, array_evaluateAllBranches as evaluateAllBranches, array_evaluateAllNodes as evaluateAllNodes, array_first as first, array_flatten as flatten, array_get as get, array_intersperse as intersperse, array_last as last, array_random as random, array_shuffle as shuffle, array_split as split }; } export { array as a, first as b, crossJoin as c, shuffle as d, deepClone as e, flatten as f, get as g, deepMerge as h, intersperse as i, evaluateAllNodes as j, evaluateAllBranches as k, last as l, random as r, split as s };