mirror of
https://github.com/frappe/books.git
synced 2024-11-10 07:40:55 +00:00
20 lines
409 B
TypeScript
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]);
|
||
|
}
|