add buildURL func

This commit is contained in:
Hamidreza Ghavami 2023-05-31 01:34:15 +04:30
parent 6c26e40aea
commit 1c9fc9422e
No known key found for this signature in database
GPG Key ID: 402C6797325182D9

View File

@ -135,3 +135,21 @@ function doAllItemsExist(array1, array2) {
} }
return true; return true;
} }
function buildURL({ host, port, isTLS, base, path }) {
if (!host || host.length === 0) host = window.location.hostname;
if (!port || port.length === 0) port = window.location.port;
if (isTLS === undefined) isTLS = window.location.protocol === "https:";
const protocol = isTLS ? "https:" : "http:";
port = String(port);
if (port === "" || (isTLS && port === "443") || (!isTLS && port === "80")) {
port = "";
} else {
port = `:${port}`;
}
return `${protocol}//${host}${port}${base}${path}`;
}