UNPKG

remeda

Version:

A utility library for JavaScript and Typescript.

51 lines (48 loc) 1.96 kB
import { B as BoundedPartial } from './BoundedPartial-D9pXZQqa.js'; import './IsBoundedRecord-CeHuKZ6O.js'; import 'type-fest'; /** * Converts a list of objects into an object indexing the objects by the given * key. * * There are several other functions that could be used to build an object from * an array: * * `fromKeys` - Builds an object from an array of *keys* and a mapper for values. * * `pullObject` - Builds an object from an array of items with mappers for *both* keys and values. * * `fromEntries` - Builds an object from an array of key-value pairs. * Refer to the docs for more details. * * @param data - The array. * @param mapper - The indexing function. * @signature * R.indexBy(array, fn) * @example * R.indexBy(['one', 'two', 'three'], x => x.length) // => {3: 'two', 5: 'three'} * @dataFirst * @category Array */ declare function indexBy<T, K extends PropertyKey>(data: ReadonlyArray<T>, mapper: (item: T, index: number, data: ReadonlyArray<T>) => K): BoundedPartial<Record<K, T>>; /** * Converts a list of objects into an object indexing the objects by the given * key. * * There are several other functions that could be used to build an object from * an array: * * `fromKeys` - Builds an object from an array of *keys* and a mapper for values. * * `pullObject` - Builds an object from an array of items with mappers for *both* keys and values. * * `fromEntries` - Builds an object from an array of key-value pairs. * Refer to the docs for more details. * * @param mapper - The indexing function. * @signature * R.indexBy(fn)(array) * @example * R.pipe( * ['one', 'two', 'three'], * R.indexBy(x => x.length) * ) // => {3: 'two', 5: 'three'} * @dataLast * @category Array */ declare function indexBy<T, K extends PropertyKey>(mapper: (item: T, index: number, data: ReadonlyArray<T>) => K): (data: ReadonlyArray<T>) => BoundedPartial<Record<K, T>>; export { indexBy };