UNPKG

uid-promise

Version:

generates a cryptographically strong random uid

20 lines (19 loc) 668 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.uid = void 0; const uid_js_1 = require("./uid.js"); const randomBytes = (size, callback) => { if (size < 0 || size > 65536) { throw new RangeError('The value of "size" is out of range. It must be >= 0 && <= 65536. Received ' + size); } var array = new Uint8Array(size); globalThis.crypto.getRandomValues(array); if (!callback) { return array; } // Mimic async behavior with setTimeout setTimeout(() => callback(null, array), 0); return new Uint8Array(); }; exports.uid = (0, uid_js_1.generateUidFunction)(randomBytes);