mirror of
https://github.com/immich-app/immich.git
synced 2026-03-07 10:37:22 +03:00
20
web/src/lib/utils/tree-utils.ts
Normal file
20
web/src/lib/utils/tree-utils.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user