2
0
mirror of https://github.com/frappe/books.git synced 2024-11-13 00:46:28 +00:00
books/schemas/helpers.ts
2022-05-23 16:18:21 +05:30

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]);
}