mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-10-19 17:22:12 +00:00
progress
This commit is contained in:
1 parent
2e1ca00afa
commit
1ba5436af3
29 files changed
+3348
-190
No files matched your search
@@ -0,0 +1,28 @@
|
||||
/** `\` and `/` alike. */
|
||||
function parts(path: string): string[] {
|
||||
return path.split(/[\\/]+/).filter((part) => part !== '');
|
||||
}
|
||||
|
||||
/** The name of the folder, the last part of its path. */
|
||||
export function folderName(folder: string): string {
|
||||
return parts(folder).at(-1) ?? folder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Where a file is in the open folder: the folders between them, as a path (`''` if it is in the
|
||||
* folder itself). `undefined` for a file that is not in the folder (or not on the disk).
|
||||
*/
|
||||
export function subfolder(
|
||||
folder: string | undefined,
|
||||
path: string | undefined
|
||||
): string | undefined {
|
||||
if (folder === undefined || path === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
const root = parts(folder);
|
||||
const file = parts(path);
|
||||
if (file.length <= root.length || root.some((part, i) => part !== file[i])) {
|
||||
return undefined;
|
||||
}
|
||||
return file.slice(root.length, -1).join('/');
|
||||
}
|
||||
Reference in new issue
Block a user