@open-condo/miniapp-utils
Version:
A set of helper functions / components / hooks used to build new condo apps fast
57 lines (56 loc) • 2.03 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/helpers/uuid.ts
var uuid_exports = {};
__export(uuid_exports, {
generateUUIDv4: () => generateUUIDv4
});
module.exports = __toCommonJS(uuid_exports);
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("");
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
generateUUIDv4
});
//# sourceMappingURL=uuid.js.map