drop anywhere in folder

This commit is contained in:
vcoppe committed 2026-10-17 23:39:44 +02:00
1 parent a5c1f6ad33
commit 8fd47d8b18
2 files changed
+21 -8

No files matched your search

@@ -33,6 +33,12 @@ function isSeparator(char: string | undefined) {
return char === '/' || char === '\\';
}
/** The folder that holds `path`. */
export function parentOf(path: string): string {
const index = Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\'));
return index > 0 ? path.slice(0, index) : path;
}
/** Whether `path` is `folder` or something in it. */
export function isWithin(path: string, folder: string): boolean {
return path === folder || (path.startsWith(folder) && isSeparator(path[folder.length]));