uuid.js 820 B

1234567891011121314151617181920212223
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.uuid = void 0;
  4. /* eslint-disable no-bitwise */
  5. function uuid() {
  6. // credit: http://stackoverflow.com/posts/2117523/revisions
  7. // return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
  8. // const r = (Math.random() * 16) | 0
  9. // const v = c === 'x' ? r : (r & 0x3) | 0x8
  10. // return v.toString(16)
  11. // })
  12. let res = '';
  13. const template = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
  14. for (let i = 0, len = template.length; i < len; i += 1) {
  15. const s = template[i];
  16. const r = (Math.random() * 16) | 0;
  17. const v = s === 'x' ? r : s === 'y' ? (r & 0x3) | 0x8 : s;
  18. res += v.toString(16);
  19. }
  20. return res;
  21. }
  22. exports.uuid = uuid;
  23. //# sourceMappingURL=uuid.js.map