signal-desktop/ts/util/makeLookup.ts

16 lines
369 B
TypeScript
Raw Normal View History

2023-01-03 11:55:46 -08:00
// Copyright 2019 Signal Messenger, LLC
2020-10-30 15:34:04 -05:00
// SPDX-License-Identifier: AGPL-3.0-only
2019-01-14 13:49:58 -08:00
export function makeLookup<T>(
2021-03-11 15:29:31 -06:00
items: ReadonlyArray<T>,
key: keyof T
): Record<string, T> {
2022-11-14 11:35:37 -08:00
const result: Record<string, T> = {};
for (const item of items) {
if (item != null && item[key] !== undefined) {
result[String(item[key])] = item;
}
2022-11-14 11:35:37 -08:00
}
return result;
2019-01-14 13:49:58 -08:00
}