signal-desktop/ts/util/makeLookup.ts

14 lines
306 B
TypeScript
Raw Normal View History

2020-10-30 15:34:04 -05:00
// Copyright 2019-2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
2019-01-14 13:49:58 -08:00
import { fromPairs, map } from 'lodash';
export function makeLookup<T>(
items: Array<T>,
key: keyof T
2019-01-14 13:49:58 -08:00
): { [key: string]: T } {
const pairs = map(items, item => [item[key], item]);
return fromPairs(pairs);
}