File size: 1,028 Bytes
4e1096a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | import { join } from '@tauri-apps/api/path';
import { isContentURI, isFileURI, isValidURL } from './misc';
export const getFilename = (fileOrUri: string) => {
if (isValidURL(fileOrUri) || isContentURI(fileOrUri) || isFileURI(fileOrUri)) {
fileOrUri = decodeURI(fileOrUri);
}
const normalizedPath = fileOrUri.replace(/\\/g, '/');
const parts = normalizedPath.split('/');
const lastPart = parts.pop()!;
return lastPart.split('?')[0]!;
};
export const getBaseFilename = (filename: string) => {
const normalizedPath = filename.replace(/\\/g, '/');
const name = normalizedPath.split('/').pop() || '';
const parts = name.split('.');
if (parts.length <= 1) {
return name;
}
return parts.slice(0, -1).join('.');
};
export const getDirPath = (filePath: string) => {
const normalizedPath = filePath.replace(/\\/g, '/');
const parts = normalizedPath.split('/');
parts.pop();
return parts.join('/');
};
export const joinPaths = async (...paths: string[]) => {
return await join(...paths);
};
|