UNPKG

@vizhub/viz-utils

Version:

Utility functions for use across VizHub packages.

34 lines (33 loc) 1.16 kB
const a = (e) => e.length !== 32 || !/^[0-9a-f]{32}$/i.test(e) ? !1 : e[12] === "4", i = () => typeof globalThis.crypto < "u" ? globalThis.crypto : require("node:crypto").webcrypto, s = i(), l = () => { const e = new Uint8Array(16); return s.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( "" ); }, n = () => l().substring(0, 8), f = n, u = (e, t) => { if (e && e.files) for (const r of Object.keys(e.files)) { const o = e.files[r]; if (o.name === t) return o.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; }, g = (e) => Object.entries(e).reduce((t, [r, o]) => (t[n()] = { name: r, text: o }, t), {}), d = (e) => Math.floor(e.getTime() / 1e3), b = (e) => new Date(e * 1e3); export { d as dateToTimestamp, g as fileCollectionToVizFiles, f as generateRunId, n as generateVizFileId, l as generateVizId, u as getFileText, a as isVizId, b as timestampToDate, c as vizFilesToFileCollection }; //# sourceMappingURL=index.js.map