| [a762898] | 1 | /**
|
|---|
| 2 | * Traverses object values and creates a new object by accumulating them in the desired form.
|
|---|
| 3 | *
|
|---|
| 4 | * @template T - The type of object.
|
|---|
| 5 | * @template R - The type of accumulator.
|
|---|
| 6 | * @param {readonly T[]} object - The array to iterate over.
|
|---|
| 7 | * @param {(acc: R, curr: T, index: number, arr: T[]) => void} iteratee - The function invoked per iteration.
|
|---|
| 8 | * @param {R} [accumulator] - The initial value.
|
|---|
| 9 | * @returns {R} Returns the accumulated value.
|
|---|
| 10 | *
|
|---|
| 11 | * @example
|
|---|
| 12 | * const array = [2, 3, 4];
|
|---|
| 13 | * transform(array, (acc, value) => { acc.push(value * 2); }, []);
|
|---|
| 14 | * // => [4, 6, 8]
|
|---|
| 15 | */
|
|---|
| 16 | declare function transform<T, R>(object: readonly T[], iteratee: (acc: R, curr: T, index: number, arr: T[]) => void, accumulator?: R): R;
|
|---|
| 17 | /**
|
|---|
| 18 | * Traverses object values and creates a new object by accumulating them in the desired form.
|
|---|
| 19 | *
|
|---|
| 20 | * @template T - The type of object.
|
|---|
| 21 | * @template R - The type of accumulator.
|
|---|
| 22 | * @param {Record<string, T>} object - The object to iterate over.
|
|---|
| 23 | * @param {(acc: R, curr: T, key: string, dict: Record<string, T>) => void} iteratee - The function invoked per iteration.
|
|---|
| 24 | * @param {R} [accumulator] - The initial value.
|
|---|
| 25 | * @returns {R} Returns the accumulated value.
|
|---|
| 26 | *
|
|---|
| 27 | * @example
|
|---|
| 28 | * const obj = { 'a': 1, 'b': 2, 'c': 1 };
|
|---|
| 29 | * transform(obj, (result, value, key) => { (result[value] || (result[value] = [])).push(key) }, {});
|
|---|
| 30 | * // => { '1': ['a', 'c'], '2': ['b'] }
|
|---|
| 31 | */
|
|---|
| 32 | declare function transform<T, R>(object: Record<string, T>, iteratee: (acc: R, curr: T, key: string, dict: Record<string, T>) => void, accumulator?: R): R;
|
|---|
| 33 | /**
|
|---|
| 34 | * Traverses object values and creates a new object by accumulating them in the desired form.
|
|---|
| 35 | *
|
|---|
| 36 | * @template T - The type of object.
|
|---|
| 37 | * @template R - The type of accumulator.
|
|---|
| 38 | * @param {T} object - The object to iterate over.
|
|---|
| 39 | * @param {(acc: R, curr: T[keyof T], key: keyof T, dict: Record<keyof T, T[keyof T]>) => void} iteratee - The function invoked per iteration.
|
|---|
| 40 | * @param {R} [accumulator] - The initial value.
|
|---|
| 41 | * @returns {R} Returns the accumulated value.
|
|---|
| 42 | *
|
|---|
| 43 | * @example
|
|---|
| 44 | * const obj = { x: 1, y: 2, z: 3 };
|
|---|
| 45 | * transform(obj, (acc, value, key) => { acc[key] = value * 2; }, {});
|
|---|
| 46 | * // => { x: 2, y: 4, z: 6 }
|
|---|
| 47 | */
|
|---|
| 48 | declare function transform<T extends object, R>(object: T, iteratee: (acc: R, curr: T[keyof T], key: keyof T, dict: Record<keyof T, T[keyof T]>) => void, accumulator?: R): R;
|
|---|
| 49 | /**
|
|---|
| 50 | * Traverses object values and creates a new object by accumulating them in the desired form.
|
|---|
| 51 | *
|
|---|
| 52 | * @param {any[]} object - The array to iterate over.
|
|---|
| 53 | * @returns {any[]} Returns the accumulated value.
|
|---|
| 54 | *
|
|---|
| 55 | * @example
|
|---|
| 56 | * const array = [1, 2, 3];
|
|---|
| 57 | * transform(array);
|
|---|
| 58 | * // => [1, 2, 3]
|
|---|
| 59 | */
|
|---|
| 60 | declare function transform(object: any[]): any[];
|
|---|
| 61 | /**
|
|---|
| 62 | * Traverses object values and creates a new object by accumulating them in the desired form.
|
|---|
| 63 | *
|
|---|
| 64 | * @param {object} object - The object to iterate over.
|
|---|
| 65 | * @returns {Record<string, any>} Returns the accumulated value.
|
|---|
| 66 | *
|
|---|
| 67 | * @example
|
|---|
| 68 | * const obj = { a: 1, b: 2 };
|
|---|
| 69 | * transform(obj);
|
|---|
| 70 | * // => { a: 1, b: 2 }
|
|---|
| 71 | */
|
|---|
| 72 | declare function transform(object: object): Record<string, any>;
|
|---|
| 73 |
|
|---|
| 74 | export { transform };
|
|---|