| [a762898] | 1 | import { ValueIterateeCustom } from '../_internal/ValueIterateeCustom.mjs';
|
|---|
| 2 |
|
|---|
| 3 | /**
|
|---|
| 4 | * Creates an object composed of keys generated from the results of running each element of collection thru iteratee.
|
|---|
| 5 | *
|
|---|
| 6 | * @template T
|
|---|
| 7 | * @param {ArrayLike<T> | null | undefined} collection - The collection to iterate over.
|
|---|
| 8 | * @param {ValueIterateeCustom<T, PropertyKey>} [iteratee] - The iteratee to transform keys.
|
|---|
| 9 | * @returns {Record<string, T>} Returns the composed aggregate object.
|
|---|
| 10 | *
|
|---|
| 11 | * @example
|
|---|
| 12 | * const array = [
|
|---|
| 13 | * { dir: 'left', code: 97 },
|
|---|
| 14 | * { dir: 'right', code: 100 }
|
|---|
| 15 | * ];
|
|---|
| 16 | *
|
|---|
| 17 | * keyBy(array, o => String.fromCharCode(o.code));
|
|---|
| 18 | * // => { a: { dir: 'left', code: 97 }, d: { dir: 'right', code: 100 } }
|
|---|
| 19 | *
|
|---|
| 20 | * keyBy(array, 'dir');
|
|---|
| 21 | * // => { left: { dir: 'left', code: 97 }, right: { dir: 'right', code: 100 } }
|
|---|
| 22 | */
|
|---|
| 23 | declare function keyBy<T>(collection: ArrayLike<T> | null | undefined, iteratee?: ValueIterateeCustom<T, PropertyKey>): Record<string, T>;
|
|---|
| 24 | /**
|
|---|
| 25 | * Creates an object composed of keys generated from the results of running each element of collection thru iteratee.
|
|---|
| 26 | *
|
|---|
| 27 | * @template T
|
|---|
| 28 | * @param {T | null | undefined} collection - The object to iterate over.
|
|---|
| 29 | * @param {ValueIterateeCustom<T[keyof T], PropertyKey>} [iteratee] - The iteratee to transform keys.
|
|---|
| 30 | * @returns {Record<string, T[keyof T]>} Returns the composed aggregate object.
|
|---|
| 31 | *
|
|---|
| 32 | * @example
|
|---|
| 33 | * const obj = { a: { dir: 'left', code: 97 }, b: { dir: 'right', code: 100 } };
|
|---|
| 34 | * keyBy(obj, o => String.fromCharCode(o.code));
|
|---|
| 35 | * // => { a: { dir: 'left', code: 97 }, d: { dir: 'right', code: 100 } }
|
|---|
| 36 | */
|
|---|
| 37 | declare function keyBy<T extends object>(collection: T | null | undefined, iteratee?: ValueIterateeCustom<T[keyof T], PropertyKey>): Record<string, T[keyof T]>;
|
|---|
| 38 |
|
|---|
| 39 | export { keyBy };
|
|---|