signal-desktop/ts/util/makeLookup.ts

16 lines
369 B
TypeScript
Raw Normal View History

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>,
key: keyof T
): 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;
}
2022-11-14 19:35:37 +00:00
}
return result;
2019-01-14 21:49:58 +00:00
}