v4.js 1009 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _native = _interopRequireDefault(require("./native.js"));
  7. var _rng = _interopRequireDefault(require("./rng.js"));
  8. var _stringify = require("./stringify.js");
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. function v4(options, buf, offset) {
  11. if (_native.default.randomUUID && !buf && !options) {
  12. return _native.default.randomUUID();
  13. }
  14. options = options || {};
  15. const rnds = options.random || (options.rng || _rng.default)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
  16. rnds[6] = rnds[6] & 0x0f | 0x40;
  17. rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
  18. if (buf) {
  19. offset = offset || 0;
  20. for (let i = 0; i < 16; ++i) {
  21. buf[offset + i] = rnds[i];
  22. }
  23. return buf;
  24. }
  25. return (0, _stringify.unsafeStringify)(rnds);
  26. }
  27. var _default = v4;
  28. exports.default = _default;