forked from Shinonome/dots-hyprland
34 lines
852 B
JavaScript
34 lines
852 B
JavaScript
/**
|
|
* Trims the File protocol off the input string
|
|
* @param {string} str
|
|
* @returns {string}
|
|
*/
|
|
function trimFileProtocol(str) {
|
|
return str.startsWith("file://") ? str.slice(7) : str;
|
|
}
|
|
|
|
/**
|
|
* Extracts the file name from a file path
|
|
* @param {string} str
|
|
* @returns {string}
|
|
*/
|
|
function fileNameForPath(str) {
|
|
if (typeof str !== "string") return "";
|
|
const trimmed = trimFileProtocol(str);
|
|
return trimmed.split(/[\\/]/).pop();
|
|
}
|
|
|
|
/**
|
|
* Removes the file extension from a file path or name
|
|
* @param {string} str
|
|
* @returns {string}
|
|
*/
|
|
function trimFileExt(str) {
|
|
if (typeof str !== "string") return "";
|
|
const trimmed = trimFileProtocol(str);
|
|
const lastDot = trimmed.lastIndexOf(".");
|
|
if (lastDot > -1 && lastDot > trimmed.lastIndexOf("/")) {
|
|
return trimmed.slice(0, lastDot);
|
|
}
|
|
return trimmed;
|
|
} |