@quirks/core
Version:
38 lines (37 loc) • 883 B
JavaScript
import { createClientNotExistError as l } from "./index9.js";
const c = (e, r) => {
try {
let t = e;
for (const n of r)
t = t[n];
return t;
} catch {
return;
}
}, u = async (e) => {
if (typeof window > "u")
return;
const r = Array.isArray(e) ? e : e.split("."), t = c(window, r), n = [...r].shift();
if (!n)
throw Error(`Invalid key: ${JSON.stringify(e)}`);
if (t)
return t;
const o = l(n);
if (document.readyState === "complete") {
if (t)
return t;
throw o;
}
return new Promise((d, f) => {
const i = (s) => {
if (s.target && s.target.readyState === "complete") {
const a = c(window, r);
a ? d(a) : f(o.message), document.removeEventListener("readystatechange", i);
}
};
document.addEventListener("readystatechange", i);
});
};
export {
u as getClientFromExtension
};