function getDomain() {
  const url = window.location.href;
  const domainPattern = /https?:\/\/([^\/]+)/;
  const match = url.match(domainPattern);
  if (match) {
    const domain = match[1];
    const domainWithoutPort = domain.split(":")[0];
    if (/^(\d{1,3}\.){3}\d{1,3}$/.test(domainWithoutPort)) {
      return domainWithoutPort;
    }
    if (domainWithoutPort === "localhost") {
      return "localhost";
    }
    const domainParts = domainWithoutPort.split(".");
    if (domainParts.length > 2) {
      return `.${domainParts.slice(-2).join(".")}`;
    } else {
      return `.${domainWithoutPort}`;
    }
  }
  return void 0;
}
function urlJoin(...parts) {
  if (parts.length === 0) return "";
  if (parts.length === 1) return parts[0];
  const result = parts.map((part, i) => {
    if (i === 0) {
      if (part === "/") return "";
      return part.replace(/\/+$/, "");
    }
    if (i === parts.length - 1) return part.replace(/^\/+/, "");
    return part.replace(/^\/+|\/+$/g, "");
  }).filter(Boolean).join("/");
  return parts[0] === "/" ? "/" + result : result;
}
function getHeaderValue(headers, key) {
  const lowerKey = key.toLowerCase();
  const foundKey = Object.keys(headers).find((k) => k.toLowerCase() === lowerKey);
  return foundKey ? headers[foundKey] : void 0;
}

export { getDomain, getHeaderValue, urlJoin };
//# sourceMappingURL=url.mjs.map
