signal-desktop/ts/util/makeLookup.ts

13 lines
318 B
TypeScript
Raw Normal View History

2019-01-14 21:49:58 +00:00
import { fromPairs, map } from 'lodash';
export function makeLookup<T>(
items: Array<T>,
key: string
): { [key: string]: T } {
// Yep, we can't index into item without knowing what it is. True. But we want to.
// @ts-ignore
const pairs = map(items, item => [item[key], item]);
return fromPairs(pairs);
}