Files
immich/web/src/lib/utils/tree-utils.ts
Jason Rasmussen f69ce6ad8a refactor(web): folder view (#11967)
refactor(web): tree view
2024-08-22 11:38:19 -04:00

21 lines
492 B
TypeScript

export interface RecursiveObject {
[key: string]: RecursiveObject;
}
export const normalizeTreePath = (path: string) => path.replace(/^\//, '').replace(/\/$/, '');
export function buildTree(paths: string[]) {
const root: RecursiveObject = {};
for (const path of paths) {
const parts = path.split('/');
let current = root;
for (const part of parts) {
if (!current[part]) {
current[part] = {};
}
current = current[part];
}
}
return root;
}