mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-12 08:54:00 +02:00
33 lines
774 B
JavaScript
33 lines
774 B
JavaScript
|
function dirname(path) {
|
||
|
if (!path) throw new Error('Path is empty');
|
||
|
let s = path.split(/\/|\\/);
|
||
|
s.pop();
|
||
|
return s.join('/');
|
||
|
}
|
||
|
|
||
|
function basename(path) {
|
||
|
if (!path) throw new Error('Path is empty');
|
||
|
let s = path.split(/\/|\\/);
|
||
|
return s[s.length - 1];
|
||
|
}
|
||
|
|
||
|
function filename(path, includeDir = false) {
|
||
|
if (!path) throw new Error('Path is empty');
|
||
|
let output = includeDir ? path : basename(path);
|
||
|
if (output.indexOf('.') < 0) return output;
|
||
|
|
||
|
output = output.split('.');
|
||
|
output.pop();
|
||
|
return output.join('.');
|
||
|
}
|
||
|
|
||
|
function fileExtension(path) {
|
||
|
if (!path) throw new Error('Path is empty');
|
||
|
|
||
|
let output = path.split('.');
|
||
|
if (output.length <= 1) return '';
|
||
|
return output[output.length - 1];
|
||
|
}
|
||
|
|
||
|
module.exports = { basename, dirname, filename, fileExtension };
|