uuid.js 779 B

12345678910111213141516171819202122232425262728293031323334
  1. var randomBytes = require('./randomBytes');
  2. exports = function() {
  3. var b = randomBytes(16);
  4. b[6] = (b[6] & 0x0f) | 0x40;
  5. b[8] = (b[8] & 0x3f) | 0x80;
  6. return (
  7. hexBytes[b[0]] +
  8. hexBytes[b[1]] +
  9. hexBytes[b[2]] +
  10. hexBytes[b[3]] +
  11. '-' +
  12. hexBytes[b[4]] +
  13. hexBytes[b[5]] +
  14. '-' +
  15. hexBytes[b[6]] +
  16. hexBytes[b[7]] +
  17. '-' +
  18. hexBytes[b[8]] +
  19. hexBytes[b[9]] +
  20. '-' +
  21. hexBytes[b[10]] +
  22. hexBytes[b[11]] +
  23. hexBytes[b[12]] +
  24. hexBytes[b[13]] +
  25. hexBytes[b[14]] +
  26. hexBytes[b[15]]
  27. );
  28. };
  29. var hexBytes = [];
  30. for (var i = 0; i < 256; i++) {
  31. hexBytes[i] = (i + 0x100).toString(16).substr(1);
  32. }
  33. module.exports = exports;