1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/lib/path-utils.js

30 lines
679 B
JavaScript
Raw Normal View History

2017-06-23 23:32:24 +02:00
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];
}
2017-06-25 01:19:11 +02:00
function filename(path) {
if (!path) throw new Error('Path is empty');
2017-06-25 13:39:42 +02:00
let output = basename(path);
2017-06-25 01:19:11 +02:00
if (output.indexOf('.') < 0) return output;
output = output.split('.');
output.pop();
return output.join('.');
}
function isHidden(path) {
let b = basename(path);
if (!b.length) throw new Error('Path empty or not a valid path: ' + path);
return b[0] === '.';
}
2017-06-25 13:39:42 +02:00
export { basename, dirname, filename, isHidden };