v4.js 860 B

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