/** * Utility class for collection operations. * Provides static methods for working with arrays, objects, sets, and maps. */ export default class Collection { /** * Evaluates an array with a predicate function, optionally in reverse order. * Returns the first truthy result from the predicate. * * @param {Array} collection - The array to evaluate * @param {(value: unknown, index: number, array: Array) => unknown} predicate - Function to evaluate each element * @param {boolean} [forward] - Whether to iterate forward (true) or backward (false). Defaults to true * @returns {unknown|undefined} The first truthy result from the predicate, or undefined * @throws {Sass} If collection is not an array or predicate is not a function */ static evalArray(collection: Array, predicate: (value: unknown, index: number, array: Array) => unknown, forward?: boolean): unknown | undefined; /** * Evaluates an object with a predicate function. * Returns the first truthy result from the predicate. * * @param {object} collection - The object to evaluate * @param {(value: unknown, key: string, object: object) => unknown} predicate - Function to evaluate each property * @returns {unknown|undefined} The first truthy result from the predicate, or undefined * @throws {Sass} If collection is not an object or predicate is not a function */ static evalObject(collection: object, predicate: (value: unknown, key: string, object: object) => unknown): unknown | undefined; /** * Evaluates a Set with a predicate function. * Returns the first truthy result from the predicate. * * @param {Set} collection - The Set to evaluate * @param {(value: unknown, set: Set) => unknown} predicate - Function to evaluate each element * @returns {unknown|undefined} The first truthy result from the predicate, or undefined * @throws {Sass} If collection is not a Set or predicate is not a function */ static evalSet(collection: Set, predicate: (value: unknown, set: Set) => unknown): unknown | undefined; /** * Evaluates a Map with a predicate function, optionally in reverse order. * Returns the first truthy result from the predicate. * * @param {Map} collection - The Map to evaluate * @param {(value: unknown, key: unknown, map: Map) => unknown} predicate - Function to evaluate each entry * @param {boolean} [forward] - Whether to iterate forward (true) or backward (false). Defaults to true * @returns {unknown|undefined} The first truthy result from the predicate, or undefined * @throws {Sass} If collection is not a Map or predicate is not a function */ static evalMap(collection: Map, predicate: (value: unknown, key: unknown, map: Map) => unknown, forward?: boolean): unknown | undefined; /** * Zips two arrays together into an array of pairs. * The resulting array length equals the shorter input array. * * @param {Array} array1 - The first array * @param {Array} array2 - The second array * @returns {Array<[unknown, unknown]>} Array of paired elements */ static zip(array1: Array, array2: Array): Array<[unknown, unknown]>; /** * Unzips an array of pairs into separate arrays. * Transposes a 2D array structure. * * @param {Array>} array - Array of arrays to unzip * @returns {Array>} Array of unzipped arrays, or empty array for invalid input */ static unzip(array: Array>): Array>; /** * Maps an array using an async function, processing items sequentially. * Unlike Promise.all(array.map()), this processes one item at a time. * * @param {Array} array - The array to map * @param {(item: unknown) => Promise} asyncFn - Async function to apply to each element * @returns {Promise>} Promise resolving to the mapped array * @throws {Sass} If array is not an Array or asyncFn is not a function */ static asyncMap(array: Array, asyncFn: (item: unknown) => Promise): Promise>; /** * Checks if all elements in an array are of a specified type * * @param {Array} arr - The array to check * @param {string} [type] - The type to check for (optional, defaults to the type of the first element) * @param {unknown} options - Options for checking types * @param {boolean} [options.strict] - Whether to use strict type or looser TypeSpec checking * @returns {boolean} Whether all elements are of the specified type */ static isArrayUniform(arr: Array, type?: string, options?: unknown): boolean; /** * Checks if an array is unique * * @param {Array} arr - The array of which to remove duplicates * @returns {Array} The unique elements of the array */ static isArrayUnique(arr: Array): Array; /** * Returns the intersection of two arrays. * * @param {Array} arr1 - The first array. * @param {Array} arr2 - The second array. * @returns {Array} The intersection of the two arrays. */ static intersection(arr1: Array, arr2: Array): Array; /** * Checks whether two arrays have any elements in common. * * This function returns `true` if at least one element from `arr1` exists in * `arr2`, and `false` otherwise. It optimizes by iterating over the shorter * array for efficiency. * * Example: * Collection.intersects([1, 2, 3], [3, 4, 5]) // returns true * Collection.intersects(["a", "b"], ["c", "d"]) // returns false * * @param {Array} arr1 - The first array to check for intersection. * @param {Array} arr2 - The second array to check for intersection. * @returns {boolean} True if any element is shared between the arrays, false otherwise. */ static intersects(arr1: Array, arr2: Array): boolean; /** * Pads an array to a specified length with a value. This operation * occurs in-place. * * @param {Array} arr - The array to pad. * @param {number} length - The length to pad the array to. * @param {unknown} value - The value to pad the array with. * @param {number} [position] - The position to pad the array at. Defaults to 0 * @returns {Array} The padded array. */ static arrayPad(arr: Array, length: number, value: unknown, position?: number): Array; /** * Filters an array asynchronously using a predicate function. * Applies the predicate to all items in parallel and returns filtered results. * * @param {Array} arr - The array to filter * @param {(value: unknown, index: number, array: Array) => Promise} predicate - Async predicate function that returns a promise resolving to boolean * @returns {Promise>} Promise resolving to the filtered array */ static asyncFilter(arr: Array, predicate: (value: unknown, index: number, array: Array) => Promise): Promise>; /** * Clones an object * * @param {object} obj - The object to clone * @param {boolean} freeze - Whether to freeze the cloned object * @returns {object} The cloned object */ static cloneObject(obj: object, freeze?: boolean): object; /** * Checks if an object is empty * * @param {object} obj - The object to check * @returns {boolean} Whether the object is empty */ static isObjectEmpty(obj: object): boolean; /** * Ensures that a nested path of objects exists within the given object. * Creates empty objects along the path if they don't exist. * * @param {object} obj - The object to check/modify * @param {Array} keys - Array of keys representing the path to ensure * @returns {object} Reference to the deepest nested object in the path */ static assureObjectPath(obj: object, keys: Array): object; /** * Sets a value in a nested object structure using an array of keys; creating * the structure if it does not exist. * * @param {object} obj - The target object to set the value in * @param {Array} keys - Array of keys representing the path to the target property * @param {unknown} value - The value to set at the target location */ static setNestedValue(obj: object, keys: Array, value: unknown): void; /** * Deeply merges two or more objects. Arrays are replaced, not merged. * * @param {...object} sources - Objects to merge (left to right) * @returns {object} The merged object */ static mergeObject(...sources: object[]): object; /** * Freezes an object and all of its properties recursively. * * @param {object} obj The object to freeze. * @returns {object} The frozen object. */ static deepFreezeObject(obj: object): object; /** * Maps an object using a transformer function * * @param {object} original The original object * @param {function(unknown): unknown} transformer The transformer function * @param {boolean} mutate Whether to mutate the original object * @returns {Promise} The mapped object */ static mapObject(original: object, transformer: (arg0: unknown) => unknown, mutate?: boolean): Promise; /** * Allocates an object from a source array and a spec array or function. * * @param {Array} source The source array * @param {Array|function(Array): Promise>|Array} spec The spec array or function * @returns {Promise} The allocated object */ static allocateObject(source: Array, spec: Array | ((arg0: Array) => Promise> | Array)): Promise; /** * Trims falsy values from both ends of an array (in-place). * Optionally preserves specific falsy values. * * @param {Array} arr - The array to trim * @param {Array} [except] - Values to preserve even if falsy. Defaults to empty array * @returns {Array} The trimmed array (same reference, modified in-place) * @throws {Sass} If arr is not an Array or except is not an Array */ static trimArray(arr: Array, except?: Array): Array; /** * Trims falsy values from the right end of an array (in-place). * Optionally preserves specific falsy values. * * @param {Array} arr - The array to trim * @param {Array} [except] - Values to preserve even if falsy. Defaults to empty array * @returns {Array} The trimmed array (same reference, modified in-place) * @throws {Sass} If arr is not an Array or except is not an Array */ static trimArrayRight(arr: Array, except?: Array): Array; /** * Trims falsy values from the left end of an array (in-place). * Optionally preserves specific falsy values. * * @param {Array} arr - The array to trim * @param {Array} [except] - Values to preserve even if falsy. Defaults to empty array * @returns {Array} The trimmed array (same reference, modified in-place) * @throws {Sass} If arr is not an Array or except is not an Array */ static trimArrayLeft(arr: Array, except?: Array): Array; /** * Transposes an array of objects into an object of arrays. * Collects values for each key across all objects into arrays. * * @param {Array} objects - Array of plain objects to transpose * @returns {object} Object with keys from input objects, values as arrays * @throws {Sass} If objects is not an Array or contains non-plain objects */ static transposeObjects(objects: Array): object; /** * Flattens an array (or nested array) of objects and transposes them. * Combines flat() and transposeObjects() operations. * * @param {Array|Array>} input - Array or nested array of objects * @returns {object} Transposed object with arrays of values */ static flattenObjectArray(input: Array | Array>): object; /** * Computes the structured difference between two objects. * Returns an object with three keys: `added`, `removed`, and `changed`. * Nested objects are recursed into, producing the same structure. * Primitive changes are represented as `{from, to}` pairs. * * @param {object|Array} original - The original object or array to compare from * @param {object|Array} updated - The updated object or array to compare against * @returns {{added: object, removed: object, changed: object}} Structured diff. * `added` contains keys new in `updated` with their new values. * `removed` contains keys absent from `updated` with their old values. * `changed` contains keys present in both but with different values; * primitives are `{from, to}` pairs, nested objects recurse. * All three keys are always present, empty when there are no differences. */ static diff(original: object | Array, updated: object | Array): { added: object; removed: object; changed: object; }; } //# sourceMappingURL=Collection.d.ts.map