2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2019 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
export function makeLookup<T>(
|
2021-03-11 21:29:31 +00:00
|
|
|
items: ReadonlyArray<T>,
|
2020-09-14 21:56:35 +00:00
|
|
|
key: keyof T
|
2021-01-06 15:41:43 +00:00
|
|
|
): Record<string, T> {
|
2022-11-14 19:35:37 +00: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 15:41:43 +00:00
|
|
|
}
|
2022-11-14 19:35:37 +00:00
|
|
|
}
|
|
|
|
return result;
|
2019-01-14 21:49:58 +00:00
|
|
|
}
|