@stryke/path
Version:
A package containing various utilities that expand the functionality of NodeJs's built-in `path` module
28 lines (26 loc) • 822 B
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_is_type = require('./is-type.cjs');
//#region src/slash.ts
/**
* Replace backslash to slash
*
* @param path - The string to replace
* @returns The string with replaced backslashes
*/
function slash(path) {
if (path.startsWith("\\\\?\\")) return path;
return path.replace(/\\/g, "/");
}
/**
* Replace backslash to slash and remove unneeded leading and trailing slashes
*
* @param path - The string to replace
* @returns The string with replaced backslashes
*/
function formatSlash(path) {
const formatted = slash(path);
return require_is_type.isAbsolutePath(formatted) ? formatted.replace(/\/+$/g, "") : formatted.replace(/^\.\//g, "").replace(/\/+$/g, "");
}
//#endregion
exports.formatSlash = formatSlash;
exports.slash = slash;