@metapages/hash-query
Version:
Get/set URL parameters in the hash string instead of the query string.
163 lines (162 loc) • 5.89 kB
JavaScript
function I(t) {
return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
}
var V = function(t, n) {
n || (n = {}), typeof n == "function" && (n = { cmp: n });
var r = typeof n.cycles == "boolean" ? n.cycles : !1, e = n.cmp && /* @__PURE__ */ function(s) {
return function(a) {
return function(c, i) {
var m = { key: c, value: a[c] }, d = { key: i, value: a[i] };
return s(m, d);
};
};
}(n.cmp), o = [];
return function s(a) {
if (a && a.toJSON && typeof a.toJSON == "function" && (a = a.toJSON()), a !== void 0) {
if (typeof a == "number") return isFinite(a) ? "" + a : "null";
if (typeof a != "object") return JSON.stringify(a);
var c, i;
if (Array.isArray(a)) {
for (i = "[", c = 0; c < a.length; c++)
c && (i += ","), i += s(a[c]) || "null";
return i + "]";
}
if (a === null) return "null";
if (o.indexOf(a) !== -1) {
if (r) return JSON.stringify("__cycle__");
throw new TypeError("Converting circular structure to JSON");
}
var m = o.push(a) - 1, d = Object.keys(a).sort(e && e(a));
for (i = "", c = 0; c < d.length; c++) {
var w = d[c], H = s(a[w]);
H && (i && (i += ","), i += JSON.stringify(w) + ":" + H);
}
return o.splice(m, 1), "{" + i + "}";
}
}(t);
};
const v = /* @__PURE__ */ I(V), P = (t) => f(v(t)), F = (t) => {
if (t && t.length > 0)
return JSON.parse(S(t));
}, f = (t) => btoa(encodeURIComponent(t)), S = (t) => {
for (; t.endsWith("%3D"); )
t = t.slice(0, -3);
return decodeURIComponent(atob(t));
}, b = (t) => {
const n = new URL(t);
return y(n.hash);
}, y = (t) => {
let n = t;
for (; n.startsWith("#"); )
n = n.substring(1);
const r = n.indexOf("?");
if (r === -1)
return [n, {}];
const e = n.substring(0, r);
n = n.substring(r + 1);
const o = {};
return n.split("&").filter((s) => s.length > 0).map((s) => {
const a = s.indexOf("=");
if (a === -1)
return [s, ""];
const c = s.substring(0, a), i = s.substring(a + 1);
return [c, i];
}).forEach(([s, a]) => {
o[s] = a;
}), Object.keys(o).forEach((s) => {
try {
o[s] = decodeURIComponent(o[s]);
} catch {
o[s] = o[s];
}
}), [e, o];
}, l = (t, n) => {
const [r, e] = b(t);
return e[n];
}, E = (t) => p()[1][t], p = () => b(window.location.href), h = (t, n, r) => {
const e = window.location.hash.startsWith("#") ? window.location.hash.substring(1) : window.location.hash, o = g(e, t, n);
o !== e && (r != null && r.modifyHistory ? window.location.hash = o : (window.history.replaceState(null, document.title, `${window.location.pathname}${window.location.search}${o.startsWith("#") ? "" : "#"}${o}`), window.dispatchEvent(new HashChangeEvent("hashchange"))));
}, g = (t, n, r) => {
const [e, o] = y(t);
let s = !1;
if (o.hasOwnProperty(n) && r === null || r === void 0 ? (delete o[n], s = !0) : o[n] !== r && (o[n] = r, s = !0), !s)
return t;
const a = Object.keys(o);
a.sort();
const c = a.map((i, m) => `${i}=${encodeURIComponent(o[i])}`).join("&");
return `${e}?${c}`;
}, u = (t, n, r) => {
const e = new URL(t), o = g(e.hash, n, r);
return e.hash = o, e.href;
}, $ = (t, n, r) => {
const e = new URL(t);
return e.hash = O(e.hash, n, r), e.href;
}, U = (t, n) => {
const r = l(t, n);
if (r && r !== "")
return F(r);
}, C = (t, n, r) => {
const e = n ? P(n) : void 0;
h(t, e, r);
}, R = (t) => U(window.location.href, t), O = (t, n, r) => {
const e = r ? P(r) : void 0;
return g(t, n, e);
}, _ = (t, n, r) => u(t, n, r ? r.toString() : void 0), W = (t, n) => {
const r = l(t, n);
return r ? parseFloat(r) : void 0;
}, B = (t, n, r) => {
h(t, n != null ? n.toString() : void 0, r);
}, x = (t) => W(window.location.href, t), D = (t, n, r) => u(t, n, r != null ? r.toString() : void 0), J = (t, n) => {
const r = l(t, n);
return r ? parseInt(r) : void 0;
}, L = (t, n, r) => {
B(t, n, r);
}, T = (t) => J(window.location.href, t), A = (t, n, r) => u(t, n, r ? "true" : void 0), j = (t, n) => l(t, n) === "true", q = (t, n, r) => {
h(t, n ? "true" : void 0, r);
}, M = (t) => j(window.location.href, t), k = (t, n, r) => u(t, n, r == null ? void 0 : f(r)), N = (t, n) => {
const r = l(t, n);
return r && r !== "" ? S(r) : void 0;
}, z = (t, n, r) => {
const e = n == null ? void 0 : f(n);
h(t, e, r);
}, G = (t) => N(window.location.href, t), K = (t, n) => {
h(t, void 0, n);
}, Q = (t, n) => u(t, n, void 0);
export {
F as blobFromBase64String,
P as blobToBase64String,
Q as deleteHashParamFromUrl,
K as deleteHashParamFromWindow,
E as getHashParamFromWindow,
l as getHashParamValue,
N as getHashParamValueBase64DecodedFromUrl,
G as getHashParamValueBase64DecodedFromWindow,
j as getHashParamValueBooleanFromUrl,
M as getHashParamValueBooleanFromWindow,
W as getHashParamValueFloatFromUrl,
x as getHashParamValueFloatFromWindow,
J as getHashParamValueIntFromUrl,
T as getHashParamValueIntFromWindow,
U as getHashParamValueJsonFromUrl,
R as getHashParamValueJsonFromWindow,
p as getHashParamsFromWindow,
b as getUrlHashParams,
y as getUrlHashParamsFromHashString,
h as setHashParamInWindow,
k as setHashParamValueBase64EncodedInUrl,
z as setHashParamValueBase64EncodedInWindow,
A as setHashParamValueBooleanInUrl,
q as setHashParamValueBooleanInWindow,
_ as setHashParamValueFloatInUrl,
B as setHashParamValueFloatInWindow,
g as setHashParamValueInHashString,
u as setHashParamValueInUrl,
D as setHashParamValueIntInUrl,
L as setHashParamValueIntInWindow,
O as setHashParamValueJsonInHashString,
$ as setHashParamValueJsonInUrl,
C as setHashParamValueJsonInWindow,
S as stringFromBase64String,
f as stringToBase64String
};
//# sourceMappingURL=index.js.map