@vizhub/viz-utils
Version:
Utility functions for use across VizHub packages.
31 lines (30 loc) • 1.01 kB
JavaScript
const f = (e) => e.length !== 32 || !/^[0-9a-f]{32}$/i.test(e) ? !1 : e[12] === "4", n = () => typeof globalThis.crypto < "u" ? globalThis.crypto : require("node:crypto").webcrypto, o = n(), l = () => {
const e = new Uint8Array(16);
return o.getRandomValues(e), e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128, Array.from(e, (t) => t.toString(16).padStart(2, "0")).join(
""
);
}, s = () => l().substring(0, 8), u = (e, t) => {
if (e && e.files)
for (const r of Object.keys(e.files)) {
const i = e.files[r];
if (i.name === t)
return i.text;
}
return null;
}, c = (e) => {
const t = {};
if (!e)
return t;
for (const r of Object.values(e))
t[r.name] = r.text;
return t;
}, a = (e) => Object.entries(e).reduce((t, [r, i]) => (t[s()] = { name: r, text: i }, t), {});
export {
a as fileCollectionToVizFiles,
s as generateVizFileId,
l as generateVizId,
u as getFileText,
f as isVizId,
c as vizFilesToFileCollection
};
//# sourceMappingURL=index.js.map