/** * Recursively flattens an array of objects based on the specified properties. * * @template T - The type of the elements in the array. * @param {T[]} array - The array to flatten. * @param {string[]} properties - The properties to flatten the array based on. * @returns {T[]} - The flattened array. */ declare function recursiveFlattenArray(array: T[], properties: string[]): T[]; /** * Recursively flattens an object by extracting specified properties. * * @template T - The type of the object being flattened. * @param entity - The object to be flattened. * @param properties - The properties to be extracted from the object. * @returns An array of flattened objects. */ declare function recursiveFlattenObject(entity: T, properties: string[]): T[]; /** * Inserts elements into an array if a condition is true. * * @template T - The type of elements in the array. * @param {boolean} condition - The condition to check. * @param {...T[]} elements - The elements to insert into the array. * @returns {T[]} - The resulting array. */ declare function insertIf(condition: boolean, ...elements: T[]): T[]; /** * Returns an array of unique IDs from the provided arrays of IDs. * * @param idsArrays - Arrays of IDs to be merged and filtered. * @returns An array of unique IDs. */ declare function uniqueIds(...idsArrays: number[][]): number[]; /** * Returns an array of unique items across all provided arrays, removing only `null` and `undefined` values. * * @template T - The type of elements in the arrays. * @param {...T[][]} arrays - Arrays of items to be merged and deduplicated. * @returns {T[]} - A deduplicated array of unique items, excluding only `null` and `undefined`. * * @example * // returns [0, 1, 2, false, NaN, ""] * uniqueItemsFilterNullish([0, 1, 2], [null, undefined, false, NaN, ""]); */ declare function uniqueItems(...arrays: T[][]): T[]; /** * Returns an array of unique items by a given key. Direct wrapper to uniqBy from lodash. * * @template T - The type of elements in the array. * @param {T[]} array - The array to inspect. * @param {((value: T) => unknown) | keyof T} iteratee - The iteratee invoked per element, or a property name. * @returns {T[]} - Returns the new duplicate free array. * * @example * // Using a function iteratee * uniqueBy([2.1, 1.2, 2.3], Math.ceil); * // => [2.1, 1.2] * * @example * // Using a property name (shorthand) * uniqueBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); * // => [{ 'x': 1 }, { 'x': 2 }] */ declare function uniqueBy(array?: T[], iteratee?: ((value: T) => unknown) | keyof T): T[]; /** * Partitions an array into two arrays based on a predicate. * inspired by lodash.partition * @param array - The array to partition. * @param predicate - The predicate to use to partition the array. * @returns A tuple of two arrays, the first containing the items that satisfy the predicate, the second containing the items that do not satisfy the predicate. */ declare function partition(array: T[], predicate: (value: T) => boolean): [T[], T[]]; /** * Creates a unique list of objects from multiple arrays based on specified keys. * * @param {Array} groupKeys - The keys to group by for uniqueness. * @param {...T[]} arrays - The arrays of objects to process. * @returns {T[]} A unique array of objects based on the provided group keys. * * @template T - The type of objects in the input arrays. * * @throws {TypeError} Throws an error if any of the arrays contain items without the specified keys. */ declare function uniqueObjectsList(groupKeys: Array, ...arrays: T[][]): T[]; /** * Compares the first array with multiple other arrays to determine if they are all equal. * Uses a deep comparison method (isEqual) to check the contents of the arrays. * * @deprecated Use `areArraysEqual` instead. * @param {any[]} firstArray - The first array to compare against the others. * @param {...any[][]} arrays - The other arrays to compare to the first array. * @returns {boolean} - Returns true if all arrays are equal; otherwise, false. * * @example * arraysEquals([1, 2, 3], [1, 2, 3], [1, 2, 3]); // returns true * arraysEquals([1, 2], [1, 2, 3]); // returns false * arraysEquals([], [], []); // returns true */ declare function arraysEquals(firstArray: any[], ...arrays: any[][]): boolean; /** * Compares an array with one or more arrays to determine if they are all equal. * * @param {T[]} firstArray - The first array to compare against. * @param {...T[][]} arrays - One or more additional arrays to compare. * @returns {boolean} True if all arrays are equal, false otherwise. * * @throws {TypeError} Throws an error if any of the inputs are not arrays. * * @template T - The type of elements in the arrays. */ declare function areArraysEqual(firstArray: T[], ...arrays: T[][]): boolean; /** * Checks if the provided input is an empty array. * * @param {any[]} [array] - The input to check, which can be an array or undefined. * @returns {boolean} Returns true if the input is an empty array, false otherwise. * * @example * isArrayEmpty([]); // returns true * isArrayEmpty([1, 2, 3]); // returns false * isArrayEmpty(null); // returns false */ declare function isArrayEmpty(array?: any[]): boolean; /** * Inserts a value into an array associated with a key in a Map. * If the key does not exist, it initializes it with an empty array. * * @param {Map} map - The Map to modify, where K is the key type and V is the value type. * @param {K} key - The key under which to store the value. * @param {V} value - The value to insert into the array associated with the key. * @throws {TypeError} Throws an error if the provided map is not a Map instance. * * @template K - The type of the keys in the Map (defaults to string). * @template V - The type of the values in the Map (defaults to any). */ declare function insertToMapArray(map: Map, key: K, value: V): void; /** * Converts an array of objects into a Map, where the keys are the `id` properties of the objects. * * @template T - The type of the objects in the array, which must extend an object containing a numeric `id` property. * @param {T[] | null | undefined} array - The array of objects to convert. Can be null or undefined, in which case an empty Map is returned. * @returns {Map} A Map where the keys are the `id` values from the objects and the values are the objects themselves. * * @example * const input = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }]; * const result = arrayToMap(input); * // result is a Map with: * // 1 => { id: 1, name: 'Alice' } * // 2 => { id: 2, name: 'Bob' } * * @example * const emptyResult = arrayToMap([]); * // emptyResult is an empty Map * * @example * const nullResult = arrayToMap(null); * // nullResult is an empty Map */ declare function arrayToMap(array: T[] | null | undefined): Map; /** * Converts an array of objects into a Map using a specified key function to determine the keys. * * @template T - The type of the objects in the array. * @template K - The type of the keys in the resulting Map. * @param {T[] | null | undefined} array - The array of objects to convert. Can be null or undefined, in which case an empty Map is returned. * @param {(item: T) => K} keyFn - A function that takes an object of type T and returns a key of type K. * @returns {Map} A Map where the keys are determined by the key function and the values are the objects themselves. * * @example * const input = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }]; * const result = arrayToMapWithKey(input, item => item.name); * // result is a Map with: * // 'Alice' => { id: 1, name: 'Alice' } * // 'Bob' => { id: 2, name: 'Bob' } * * @param array * @param keyFn */ declare function arrayToMapWithKey(array: T[] | null | undefined, keyFn: (item: T) => K): Map; /** * Checks if two arrays have any common elements. * * This function verifies whether the provided arrays intersect. * If either array is null or undefined, it returns false. * If both arrays are empty, it returns true, indicating they are considered to intersect. * If only one of the arrays is empty, it returns false. * * @template T - The type of elements in the arrays. * @param {T[] | undefined | null} array - The first array to compare, which can be an array of type T, undefined, or null. * @param {T[] | undefined | null} other - The second array to compare, which can be an array of type T, undefined, or null. * @returns {boolean} - Returns true if the arrays have common elements, * false if they do not or if either input is null/undefined. * * @example * returns true * isIntersecting([1, 2, 3], [3, 4, 5]); * * @example * returns false * isIntersecting([1, 2, 3], [4, 5, 6]); * * @example * returns true * isIntersecting([], []); * * @example * returns false * isIntersecting(null, [1, 2, 3]); * * @example * returns false * isIntersecting([1, 2, 3], undefined); */ declare function isIntersecting(array: T[] | undefined | null, other: T[] | undefined | null): boolean; /** * Lazily yields consecutive slices ("chunks") of an array. * * This is useful for batching work (DB inserts, API calls) without allocating * an array of all chunks up front. * * @template T * @param {readonly T[]} arr - Source array to chunk. * @param {number} size - Chunk size (must be a positive integer). * @returns {Generator} A generator that yields chunks of `arr`. * * @example * for (const batch of lazyChunk(rows, 3)) { * await repo.insert(batch); * } */ declare function lazyChunk(arr: readonly T[], size: number): Generator; export { arrayToMap, arrayToMapWithKey, arraysEquals, areArraysEqual, insertIf, insertToMapArray, isArrayEmpty, recursiveFlattenArray, recursiveFlattenObject, uniqueIds, uniqueItems, uniqueBy, partition, uniqueObjectsList, isIntersecting, lazyChunk, };