25 lines
827 B
TypeScript
25 lines
827 B
TypeScript
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 baseName = normalizedPath.split('/').pop()?.split('.').slice(0, -1).join('.') || '';
|
|
return baseName;
|
|
};
|
|
|
|
export const getDirPath = (filePath: string) => {
|
|
const normalizedPath = filePath.replace(/\\/g, '/');
|
|
const parts = normalizedPath.split('/');
|
|
parts.pop();
|
|
return parts.join('/');
|
|
};
|