super-utils-plus
Version:
A superior alternative to Lodash with improved performance, TypeScript support, and developer experience
99 lines (98 loc) • 3.07 kB
TypeScript
/**
* Creates an array of grouped elements, the first of which contains the
* first elements of the given arrays, the second of which contains the
* second elements of the given arrays, and so on.
*
* @param arrays - The arrays to process
* @returns The new array of grouped elements
*
* @example
* ```ts
* zip(['a', 'b'], [1, 2], [true, false]);
* // => [['a', 1, true], ['b', 2, false]]
* ```
*/
export declare function zip<T>(...arrays: T[][]): T[][];
/**
* This method is like zip except that it accepts an array of grouped
* elements and creates an array regrouping the elements to their pre-zip
* configuration.
*
* @param array - The array of grouped elements to process
* @returns The new array of regrouped elements
*
* @example
* ```ts
* const zipped = zip(['a', 'b'], [1, 2], [true, false]);
* // => [['a', 1, true], ['b', 2, false]]
*
* unzip(zipped);
* // => [['a', 'b'], [1, 2], [true, false]]
* ```
*/
export declare function unzip<T>(array: T[][]): T[][];
/**
* This method is like unzip except that it accepts an iteratee to specify
* how regrouped values should be combined. The iteratee is invoked with four
* arguments: (accumulator, value, index, group).
*
* @param array - The array of grouped elements to process
* @param iteratee - The function to combine regrouped values
* @returns The new array of regrouped elements
*
* @example
* ```ts
* const zipped = zip([1, 2], [10, 20], [100, 200]);
* // => [[1, 10, 100], [2, 20, 200]]
*
* unzipWith(zipped, _.add);
* // => [3, 30, 300]
* ```
*/
export declare function unzipWith<T, R>(array: T[][], iteratee: (...values: T[]) => R): R[];
/**
* Creates an object composed from arrays of property names and values.
*
* @param props - The property identifiers
* @param values - The property values
* @returns The new object
*
* @example
* ```ts
* zipObject(['a', 'b'], [1, 2]);
* // => { 'a': 1, 'b': 2 }
* ```
*/
export declare function zipObject<T = any>(props: Array<string | number | symbol>, values: T[]): Record<string | number | symbol, T>;
/**
* This method is like zipObject except that it supports property paths.
*
* @param paths - The property paths
* @param values - The property values
* @returns The new object
*
* @example
* ```ts
* zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
* // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
* ```
*/
export declare function zipObjectDeep<T = any>(paths: string[], values: T[]): Record<string, any>;
/**
* This method is like zip except that it accepts an iteratee to specify
* how grouped values should be combined. The iteratee is invoked with the
* elements of each group.
*
* @param arrays - The arrays to process
* @param iteratee - The function to combine grouped values
* @returns The new array of grouped elements
*
* @example
* ```ts
* zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
* return a + b + c;
* });
* // => [111, 222]
* ```
*/
export declare function zipWith<T, R>(...args: [...arrays: T[][], iteratee: (...values: T[]) => R]): R[];