bytesToUuid.js 1.1 KB

1234567891011121314151617181920212223242526
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. /**
  7. * Convert array of 16 byte values to UUID string format of the form:
  8. * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
  9. */
  10. const byteToHex = [];
  11. for (let i = 0; i < 256; ++i) {
  12. byteToHex.push((i + 0x100).toString(16).substr(1));
  13. }
  14. function bytesToUuid(buf, offset_) {
  15. const offset = offset_ || 0; // Note: Be careful editing this code! It's been tuned for performance
  16. // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
  17. return (byteToHex[buf[offset + 0]] + byteToHex[buf[offset + 1]] + byteToHex[buf[offset + 2]] + byteToHex[buf[offset + 3]] + '-' + byteToHex[buf[offset + 4]] + byteToHex[buf[offset + 5]] + '-' + byteToHex[buf[offset + 6]] + byteToHex[buf[offset + 7]] + '-' + byteToHex[buf[offset + 8]] + byteToHex[buf[offset + 9]] + '-' + byteToHex[buf[offset + 10]] + byteToHex[buf[offset + 11]] + byteToHex[buf[offset + 12]] + byteToHex[buf[offset + 13]] + byteToHex[buf[offset + 14]] + byteToHex[buf[offset + 15]]).toLowerCase();
  18. }
  19. var _default = bytesToUuid;
  20. exports.default = _default;