source: node_modules/es-toolkit/dist/compat/array/keyBy.d.mts

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[a762898]1import { 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 */
23declare 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 */
37declare function keyBy<T extends object>(collection: T | null | undefined, iteratee?: ValueIterateeCustom<T[keyof T], PropertyKey>): Record<string, T[keyof T]>;
38
39export { keyBy };
Note: See TracBrowser for help on using the repository browser.