Skip to content

Commit af9bda3

Browse files
committed
refactor: reduce the amount of code for TreeBuilder.getParent(path)
1 parent b3d4658 commit af9bda3

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/utils/TreeBuilder.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,10 @@ export class TreeBuilder {
172172
}
173173

174174
// if it's not a FOLDER, then it's FILE or VIRTUAL
175-
const extension = path.split('.').pop() ?? '';
176-
let result = path.replace(RegExp('(\/|^)[^\.\/]+.' + extension + '$'), '');
177-
result = result === '' ? '/' : result.replace(RegExp('\.[^\.]+\.' + extension + '$'), '.' + extension);
175+
// remove the file name if not dots
176+
let result = path.replace(/(\/|^)[^./]+\.[^\.]+$/, '');
177+
// otherwise, remove the last part of the dendron path
178+
result = result === '' ? '/' : result.replace(/\.[^\.]+(\.[^\.]+)$/, '$1');
178179
return result;
179180
}
180181

0 commit comments

Comments
 (0)