monkeeShark/src/web/app/common/scripts/uuid.js
2017-05-11 07:19:26 +09:00

18 lines
310 B
JavaScript

/**
* Generate a UUID
*/
export default () => {
let uuid = '';
for (let i = 0; i < 32; i++) {
const random = Math.random() * 16 | 0;
if (i == 8 || i == 12 || i == 16 || i == 20) {
uuid += '-';
}
uuid += (i == 12 ? 4 : (i == 16 ? (random & 3 | 8) : random)).toString(16);
}
return uuid;
};