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

20 lines
409 B
TypeScript

export function getMapFromList<T>(
list: T[],
name: string = 'name'
): Record<string, T> {
const acc: Record<string, T> = {};
for (const t of list) {
const key = t[name] as string | undefined;
if (key === undefined) {
continue;
}
acc[key] = t;
}
return acc;
}
export function getListFromMap<T>(map: Record<string, T>): T[] {
return Object.keys(map).map((n) => map[n]);
}