UNPKG

@stryke/path

Version:

A package containing various utilities that expand the functionality of NodeJs's built-in `path` module

27 lines (25 loc) 739 B
import { isAbsolutePath } from "./is-type.mjs"; //#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 isAbsolutePath(formatted) ? formatted.replace(/\/+$/g, "") : formatted.replace(/^\.\//g, "").replace(/\/+$/g, ""); } //#endregion export { formatSlash, slash }; //# sourceMappingURL=slash.mjs.map