import {
  isNumeric
} from "./chunk-JNITUVXP.js";

// common/urlmap.js
function urlmap_default(search = "", log = console.warn) {
  const location = search ? { search } : window.location;
  const urlp = /* @__PURE__ */ new Map();
  for (const s of location.search.substr(1).split("&")) {
    if (!s) continue;
    const l = s.split("=");
    if (l.length == 2 && l[0] != "" && l[1] != "") {
      let value = decodeURIComponent(l[1]);
      if (
        // assume JSON encoding when the string is enclosed by matching characters below
        value.startsWith('"') && value.endsWith('"') || value.startsWith("{") && value.endsWith("}") || value.startsWith("[") && value.endsWith("]")
      ) {
        try {
          value = JSON.parse(value);
        } catch (e) {
          log(e);
        }
      } else if (isNumeric(value)) {
        value = Number(value);
      }
      urlp.set(l[0].toLowerCase(), value);
    } else if (l.length > 2) {
      log(`unexpected '=' character in the URL parameter value for '${l[0]}'`);
    } else {
      log(`Invalid url parameter: '${s}'`);
    }
  }
  return urlp;
}

export {
  urlmap_default
};
//# sourceMappingURL=chunk-WKNI3HRQ.js.map
