@metapages/hash-query
Version:
Get/set URL parameters in the hash string instead of the query string.
121 lines (120 loc) • 4.62 kB
JavaScript
import { useState as H, useEffect as i, useCallback as l } from "react";
import { getHashParamFromWindow as S, getHashParamsFromWindow as g, setHashParamInWindow as c, stringToBase64String as u, stringFromBase64String as v, blobToBase64String as F, blobFromBase64String as I } from "../core/index.js";
import { deleteHashParamFromUrl as D, deleteHashParamFromWindow as N, getHashParamValue as x, getHashParamValueBase64DecodedFromUrl as C, getHashParamValueBase64DecodedFromWindow as L, getHashParamValueBooleanFromUrl as T, getHashParamValueBooleanFromWindow as _, getHashParamValueFloatFromUrl as f, getHashParamValueFloatFromWindow as A, getHashParamValueIntFromUrl as j, getHashParamValueIntFromWindow as q, getHashParamValueJsonFromHashString as z, getHashParamValueJsonFromUrl as G, getHashParamValueJsonFromWindow as K, getUrlHashParams as M, getUrlHashParamsFromHashString as O, setHashParamValueBase64EncodedInUrl as Q, setHashParamValueBase64EncodedInWindow as R, setHashParamValueBooleanInUrl as X, setHashParamValueBooleanInWindow as Y, setHashParamValueFloatInUrl as Z, setHashParamValueFloatInWindow as $, setHashParamValueInHashString as k, setHashParamValueInUrl as y, setHashParamValueIntInUrl as aa, setHashParamValueIntInWindow as sa, setHashParamValueJsonInHashString as ra, setHashParamValueJsonInUrl as na, setHashParamValueJsonInWindow as ea } from "../core/index.js";
const P = (r, a) => {
const [s, n] = H(S(r) ?? a);
i(() => {
const [e, t] = g();
a && t[r] === void 0 && c(r, a);
}, [a]), i(() => {
const e = (t) => {
const o = g()[1];
n(o[r]);
};
return window.addEventListener("hashchange", e), () => window.removeEventListener("hashchange", e);
}, []);
const h = l((e, t) => {
c(r, e, t);
}, []);
return [s, h];
}, V = (r, a) => {
const [s, n] = P(r, a != null ? u(a) : void 0), [h, e] = H(a);
i(() => {
e(s ? v(s) : void 0);
}, [r, s, e]);
const t = l((o, m) => {
if (o == null)
n(void 0, m);
else {
const d = u(o);
n(d, m);
}
}, [n]);
return [h, t];
}, U = (r) => {
const [a, s] = P(r), [n, h] = H(a === "true");
i(() => {
h(a === "true");
}, [r, a, h]);
const e = l((t, o) => {
t = !!t, s(t ? "true" : void 0, o);
}, [s]);
return [n, e];
}, W = (r, a) => {
const [s, n] = P(r, a != null ? a.toString() : void 0), [h, e] = H(s ? parseFloat(s) : void 0);
i(() => {
e(s ? parseFloat(s) : void 0);
}, [r, s, e]);
const t = l((o, m) => {
n(o ? o.toString() : void 0, m);
}, [n]);
return [h, t];
}, J = (r, a) => {
const [s, n] = P(r, a != null ? a.toString() : void 0), [h, e] = H(s ? parseInt(s) : void 0);
i(() => {
e(s ? parseInt(s) : void 0);
}, [r, s, e]);
const t = l((o, m) => {
n(o ? o.toString() : void 0, m);
}, [n]);
return [h, t];
}, b = (r, a) => {
const [s, n] = P(r, a != null ? F(a) : void 0), [h, e] = H(I(s));
i(() => {
e(I(s));
}, [r, s, e]);
const t = l((o, m) => {
if (o == null)
n(void 0, m);
else {
const d = F(o);
n(d, m);
}
}, [n]);
return [h, t];
};
export {
I as blobFromBase64String,
F as blobToBase64String,
D as deleteHashParamFromUrl,
N as deleteHashParamFromWindow,
S as getHashParamFromWindow,
x as getHashParamValue,
C as getHashParamValueBase64DecodedFromUrl,
L as getHashParamValueBase64DecodedFromWindow,
T as getHashParamValueBooleanFromUrl,
_ as getHashParamValueBooleanFromWindow,
f as getHashParamValueFloatFromUrl,
A as getHashParamValueFloatFromWindow,
j as getHashParamValueIntFromUrl,
q as getHashParamValueIntFromWindow,
z as getHashParamValueJsonFromHashString,
G as getHashParamValueJsonFromUrl,
K as getHashParamValueJsonFromWindow,
g as getHashParamsFromWindow,
M as getUrlHashParams,
O as getUrlHashParamsFromHashString,
c as setHashParamInWindow,
Q as setHashParamValueBase64EncodedInUrl,
R as setHashParamValueBase64EncodedInWindow,
X as setHashParamValueBooleanInUrl,
Y as setHashParamValueBooleanInWindow,
Z as setHashParamValueFloatInUrl,
$ as setHashParamValueFloatInWindow,
k as setHashParamValueInHashString,
y as setHashParamValueInUrl,
aa as setHashParamValueIntInUrl,
sa as setHashParamValueIntInWindow,
ra as setHashParamValueJsonInHashString,
na as setHashParamValueJsonInUrl,
ea as setHashParamValueJsonInWindow,
v as stringFromBase64String,
u as stringToBase64String,
P as useHashParam,
V as useHashParamBase64,
U as useHashParamBoolean,
W as useHashParamFloat,
J as useHashParamInt,
b as useHashParamJson
};
//# sourceMappingURL=index.js.map