mirror of
https://github.com/frappe/books.git
synced 2024-11-13 00:46:28 +00:00
20 lines
400 B
TypeScript
20 lines
400 B
TypeScript
export function getMapFromList<T, K extends keyof T>(
|
|
list: T[],
|
|
name: K
|
|
): Record<string, T> {
|
|
const acc: Record<string, T> = {};
|
|
for (const t of list) {
|
|
const key = t[name];
|
|
if (key === undefined) {
|
|
continue;
|
|
}
|
|
|
|
acc[String(key)] = t;
|
|
}
|
|
return acc;
|
|
}
|
|
|
|
export function getListFromMap<T>(map: Record<string, T>): T[] {
|
|
return Object.keys(map).map((n) => map[n]);
|
|
}
|