| 1 | import { ValueIteratee } from '../_internal/ValueIteratee.js';
|
|---|
| 2 |
|
|---|
| 3 | /**
|
|---|
| 4 | * Creates a new object that reverses the keys and values of the given object, similar to the invert.
|
|---|
| 5 | * The values of the new object are arrays of keys that correspond to the value returned by the `iteratee` function.
|
|---|
| 6 | *
|
|---|
| 7 | * @param {Record<string|number, T>} object - The object to iterate over
|
|---|
| 8 | * @param {ValueIteratee<T>} [iteratee] - Optional function to transform values into keys
|
|---|
| 9 | * @returns {Record<string, string[]>} An object with transformed values as keys and arrays of original keys as values
|
|---|
| 10 | *
|
|---|
| 11 | * @example
|
|---|
| 12 | * const obj = { a: 1, b: 2, c: 1 };
|
|---|
| 13 | * invertBy(obj); // => { '1': ['a', 'c'], '2': ['b'] }
|
|---|
| 14 | *
|
|---|
| 15 | * @example
|
|---|
| 16 | * const obj = { a: 1, b: 2, c: 1 };
|
|---|
| 17 | * invertBy(obj, value => `group${value}`); // => { 'group1': ['a', 'c'], 'group2': ['b'] }
|
|---|
| 18 | */
|
|---|
| 19 | declare function invertBy<T>(object: Record<string, T> | Record<number, T> | null | undefined, interatee?: ValueIteratee<T>): Record<string, string[]>;
|
|---|
| 20 | /**
|
|---|
| 21 | * Creates a new object that reverses the keys and values of the given object, similar to the invert.
|
|---|
| 22 | * The values of the new object are arrays of keys that correspond to the value returned by the `iteratee` function.
|
|---|
| 23 | *
|
|---|
| 24 | * @param {T} object - The object to iterate over
|
|---|
| 25 | * @param {ValueIteratee<T[keyof T]>} [iteratee] - Optional function to transform values into keys
|
|---|
| 26 | * @returns {Record<string, string[]>} An object with transformed values as keys and arrays of original keys as values
|
|---|
| 27 | *
|
|---|
| 28 | * @example
|
|---|
| 29 | * const obj = { foo: { id: 1 }, bar: { id: 2 }, baz: { id: 1 } };
|
|---|
| 30 | * invertBy(obj, value => String(value.id)); // => { '1': ['foo', 'baz'], '2': ['bar'] }
|
|---|
| 31 | */
|
|---|
| 32 | declare function invertBy<T extends object>(object: T | null | undefined, interatee?: ValueIteratee<T[keyof T]>): Record<string, string[]>;
|
|---|
| 33 |
|
|---|
| 34 | export { invertBy };
|
|---|