immich/web/src/lib/utils/tree-utils.ts
Alex b653a20d15
fix(web): sort folders (#12038)
chore(web): sort folders
2024-08-25 16:53:14 -05:00

23 lines
510 B
TypeScript

export interface RecursiveObject {
[key: string]: RecursiveObject;
}
export const normalizeTreePath = (path: string) => path.replace(/^\//, '').replace(/\/$/, '');
export function buildTree(paths: string[]) {
const root: RecursiveObject = {};
paths.sort();
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;
}