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>,
|
2020-09-14 14:56:35 -07:00
|
|
|
key: keyof T
|
2021-01-06 07:41:43 -08:00
|
|
|
): 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;
|
2021-01-06 07:41:43 -08:00
|
|
|
}
|
2022-11-14 11:35:37 -08:00
|
|
|
}
|
|
|
|
return result;
|
2019-01-14 13:49:58 -08:00
|
|
|
}
|