2020-11-12 21:13:28 +02:00
|
|
|
export function dirname(path: string) {
|
2020-01-30 23:05:23 +02:00
|
|
|
if (!path) throw new Error('Path is empty');
|
2020-03-14 01:46:14 +02:00
|
|
|
const s = path.split(/\/|\\/);
|
2020-01-30 23:05:23 +02:00
|
|
|
s.pop();
|
|
|
|
return s.join('/');
|
|
|
|
}
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
export function basename(path: string) {
|
2020-01-30 23:05:23 +02:00
|
|
|
if (!path) throw new Error('Path is empty');
|
2020-03-14 01:46:14 +02:00
|
|
|
const s = path.split(/\/|\\/);
|
2020-01-30 23:05:23 +02:00
|
|
|
return s[s.length - 1];
|
|
|
|
}
|
|
|
|
|
2023-06-30 10:11:26 +02:00
|
|
|
export function filename(path: string, includeDir = false): string {
|
2020-01-30 23:05:23 +02:00
|
|
|
if (!path) throw new Error('Path is empty');
|
2020-10-24 01:14:30 +02:00
|
|
|
const output = includeDir ? path : basename(path);
|
2020-01-30 23:05:23 +02:00
|
|
|
if (output.indexOf('.') < 0) return output;
|
|
|
|
|
2020-10-21 01:23:55 +02:00
|
|
|
const splitted = output.split('.');
|
|
|
|
splitted.pop();
|
|
|
|
return splitted.join('.');
|
2020-01-30 23:05:23 +02:00
|
|
|
}
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
export function fileExtension(path: string) {
|
2020-01-30 23:05:23 +02:00
|
|
|
if (!path) throw new Error('Path is empty');
|
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
const output = path.split('.');
|
2020-01-30 23:05:23 +02:00
|
|
|
if (output.length <= 1) return '';
|
|
|
|
return output[output.length - 1];
|
|
|
|
}
|
2020-12-09 23:30:51 +02:00
|
|
|
|
|
|
|
export function toForwardSlashes(path: string) {
|
|
|
|
return path.replace(/\\/g, '/');
|
|
|
|
}
|