You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-21 23:17:42 +02:00
@ -1,56 +1,56 @@
|
||||
function dirname(path) {
|
||||
if (!path) throw new Error("Path is empty");
|
||||
if (!path) throw new Error('Path is empty');
|
||||
let s = path.split(/\/|\\/);
|
||||
s.pop();
|
||||
return s.join("/");
|
||||
return s.join('/');
|
||||
}
|
||||
|
||||
function basename(path) {
|
||||
if (!path) throw new Error("Path is empty");
|
||||
if (!path) throw new Error('Path is empty');
|
||||
let s = path.split(/\/|\\/);
|
||||
return s[s.length - 1];
|
||||
}
|
||||
|
||||
function filename(path) {
|
||||
if (!path) throw new Error("Path is empty");
|
||||
if (!path) throw new Error('Path is empty');
|
||||
let output = basename(path);
|
||||
if (output.indexOf(".") < 0) return output;
|
||||
if (output.indexOf('.') < 0) return output;
|
||||
|
||||
output = output.split(".");
|
||||
output = output.split('.');
|
||||
output.pop();
|
||||
return output.join(".");
|
||||
return output.join('.');
|
||||
}
|
||||
|
||||
function fileExtension(path) {
|
||||
if (!path) throw new Error("Path is empty");
|
||||
if (!path) throw new Error('Path is empty');
|
||||
|
||||
let output = path.split(".");
|
||||
if (output.length <= 1) return "";
|
||||
let output = path.split('.');
|
||||
if (output.length <= 1) return '';
|
||||
return output[output.length - 1];
|
||||
}
|
||||
|
||||
function isHidden(path) {
|
||||
let b = basename(path);
|
||||
if (!b.length) throw new Error("Path empty or not a valid path: " + path);
|
||||
return b[0] === ".";
|
||||
if (!b.length) throw new Error('Path empty or not a valid path: ' + path);
|
||||
return b[0] === '.';
|
||||
}
|
||||
|
||||
function safeFileExtension(e) {
|
||||
if (!e || !e.replace) return "";
|
||||
return e.replace(/[^a-zA-Z0-9]/g, "");
|
||||
if (!e || !e.replace) return '';
|
||||
return e.replace(/[^a-zA-Z0-9]/g, '')
|
||||
}
|
||||
|
||||
function toSystemSlashes(path, os) {
|
||||
if (os === "win32") return path.replace(/\//g, "\\");
|
||||
if (os === 'win32') return path.replace(/\//g, "\\");
|
||||
return path.replace(/\\/g, "/");
|
||||
}
|
||||
|
||||
function rtrimSlashes(path) {
|
||||
return path.replace(/\/+$/, "");
|
||||
return path.replace(/\/+$/, '');
|
||||
}
|
||||
|
||||
function ltrimSlashes(path) {
|
||||
return path.replace(/^\/+/, "");
|
||||
return path.replace(/^\/+/, '');
|
||||
}
|
||||
|
||||
module.exports = { basename, dirname, filename, isHidden, fileExtension, safeFileExtension, toSystemSlashes, rtrimSlashes, ltrimSlashes };
|
||||
module.exports = { basename, dirname, filename, isHidden, fileExtension, safeFileExtension, toSystemSlashes, rtrimSlashes, ltrimSlashes };
|
Reference in New Issue
Block a user