Debian Codegraph @

frontend/src/lib/paths.ts

raw
1 /**
2 * Get the basename of a file path.
3 */
4 export function basename(filename: string): string {
5 const parts = filename.split(/\/|\\/);
6 return parts[parts.length - 1] ?? "";
7 }
8
9 /**
10 * Get the extension of a filename.
11 */
12 export function ext(filename: string): string {
13 const match = /\.(\w+)$/.exec(filename);
14 return match?.[1] ?? "";
15 }
16
17 /**
18 * Check whether the given filename includes the account parts at the end.
19 */
20 export function documentHasAccount(filename: string, account: string): boolean {
21 const accountParts = account.split(":").reverse();
22 const folders = filename.split(/\/|\\/).reverse().slice(1);
23 return accountParts.every((part, index) => part === folders[index]);
24 }