signal-desktop/ts/util/makeLookup.ts
2020-11-04 13:03:13 -06:00

13 lines
306 B
TypeScript

// Copyright 2019-2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { fromPairs, map } from 'lodash';
export function makeLookup<T>(
items: Array<T>,
key: keyof T
): { [key: string]: T } {
const pairs = map(items, item => [item[key], item]);
return fromPairs(pairs);
}