@azure-utils/storybooks
Version:
Utils to upload and manage Storybooks via Azure Functions and storage.
38 lines (37 loc) • 1.24 kB
JavaScript
//#region src/utils/url-utils.ts
function urlSearchParamsToObject(query) {
const result = {};
for (const key of query.keys()) {
const values = query.getAll(key);
result[key] = values.length > 1 ? values : values[0];
}
return result;
}
function joinUrl(...parts) {
if (parts.length === 0) return "";
let protocol = "";
let host = "";
const match = parts[0]?.match(/^([a-zA-Z][a-zA-Z0-9+\-.]*:)?(\/\/[^\/?#]*)?/);
if (match && (match[1] || match[2])) {
protocol = match[1] || "";
host = match[2] || "";
const remainder = parts[0]?.slice((match[0] || "").length);
parts = remainder ? [remainder, ...parts.slice(1)] : parts.slice(1);
}
const segments = [];
for (const part of parts) for (const seg of part.split("/")) {
if (!seg || seg === ".") continue;
if (seg === "..") {
if (segments.length > 0) segments.pop();
} else segments.push(seg);
}
let result = "";
if (protocol || host) {
result = protocol + host;
if (segments.length > 0) result += segments[0]?.startsWith("?") || segments[0]?.startsWith("#") ? "" : "/" + segments.join("/");
} else result = "/" + segments.join("/");
return result;
}
//#endregion
export { joinUrl, urlSearchParamsToObject };
//# sourceMappingURL=url-utils-B9Pl4bQ7.mjs.map