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