@credo-ts/core
Version:
<p align="center"> <br /> <img alt="Credo Logo" src="https://github.com/openwallet-foundation/credo-ts/blob/c7886cb8377ceb8ee4efe8d264211e561a75072d/images/credo-logo.png" height="250px" /> </p> <h1 align="center"><b>Credo - Core</b></h1
33 lines (32 loc) • 1.08 kB
JavaScript
//#region src/utils/path.ts
/**
* Extract directory from path (should also work with windows paths)
*
* @param path the path to extract the directory from
* @returns the directory path
*/
function getDirFromFilePath(path) {
return path.substring(0, Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\")));
}
/**
* Combine multiple uri parts into a single uri taking into account slashes.
*
* @param parts the parts to combine
* @returns the combined url
*/
function joinUriParts(base, parts) {
if (parts.length === 0) return base;
let combined = base.trim();
combined = base.endsWith("/") ? base.slice(0, base.length - 1) : base;
for (const part of parts) {
let strippedPart = part.trim();
strippedPart = strippedPart.startsWith("/") ? strippedPart.slice(1) : strippedPart;
strippedPart = strippedPart.endsWith("/") ? strippedPart.slice(0, strippedPart.length - 1) : strippedPart;
if (strippedPart === "") continue;
combined += `/${strippedPart}`;
}
return combined;
}
//#endregion
export { getDirFromFilePath, joinUriParts };
//# sourceMappingURL=path.mjs.map