From 11d785f12043f302feeff4e74730dff6311a3de1 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 11 May 2017 07:19:26 +0900 Subject: [PATCH] Refactor --- src/web/app/common/scripts/uuid.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/web/app/common/scripts/uuid.js b/src/web/app/common/scripts/uuid.js index 6a103d6e0..ff016e18a 100644 --- a/src/web/app/common/scripts/uuid.js +++ b/src/web/app/common/scripts/uuid.js @@ -1,12 +1,18 @@ +/** + * Generate a UUID + */ export default () => { - var uuid = '', i, random; - for (i = 0; i < 32; i++) { - random = Math.random() * 16 | 0; + 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; };