2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +00:00
books/schemas/helpers.ts

20 lines
409 B
TypeScript
Raw Normal View History

2022-03-23 14:46:19 +00:00
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]);
}