immich/web/src/lib/utils/tree-utils.ts
Michel Heusschen c33b918d74
refactor(web): folders store (#14305)
* refactor(web): folders store

* use typescript private
2024-11-23 13:22:13 -06:00

21 lines
493 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;
}