@open-condo/miniapp-utils
Version:
A set of helper functions / components / hooks used to build new condo apps fast
39 lines (38 loc) • 1.39 kB
JavaScript
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function(x) {
if (typeof require !== "undefined") return require.apply(this, arguments);
throw Error('Dynamic require of "' + x + '" is not supported');
});
// src/helpers/uuid.ts
function generateUUIDv4() {
const webCrypto = typeof globalThis !== "undefined" ? globalThis.crypto : void 0;
if (webCrypto && typeof webCrypto.randomUUID === "function") {
return webCrypto.randomUUID();
}
let randomValues;
if (webCrypto && typeof webCrypto.getRandomValues === "function") {
randomValues = new Uint8Array(16);
webCrypto.getRandomValues(randomValues);
} else {
try {
const { randomBytes } = __require("crypto");
randomValues = randomBytes(16);
} catch {
throw new Error("No secure random source available in this environment");
}
}
randomValues[6] = randomValues[6] & 15 | 64;
randomValues[8] = randomValues[8] & 63 | 128;
return [...randomValues].map((value, index) => {
const hex = value.toString(16).padStart(2, "0");
if (index === 4 || index === 6 || index === 8 || index === 10) {
return `-${hex}`;
}
return hex;
}).join("");
}
export {
generateUUIDv4
};
//# sourceMappingURL=uuid.mjs.map