uuid.js 754 B

12345678910111213141516171819
  1. "use strict";
  2. // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
  3. Object.defineProperty(exports, "__esModule", { value: true });
  4. exports.uuid4 = void 0;
  5. /**
  6. * https://stackoverflow.com/a/2117523
  7. */
  8. let uuid4 = function () {
  9. const { crypto } = globalThis;
  10. if (crypto?.randomUUID) {
  11. exports.uuid4 = crypto.randomUUID.bind(crypto);
  12. return crypto.randomUUID();
  13. }
  14. const u8 = new Uint8Array(1);
  15. const randomByte = crypto ? () => crypto.getRandomValues(u8)[0] : () => (Math.random() * 0xff) & 0xff;
  16. return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, (c) => (+c ^ (randomByte() & (15 >> (+c / 4)))).toString(16));
  17. };
  18. exports.uuid4 = uuid4;
  19. //# sourceMappingURL=uuid.js.map