From ca2542d81aca931623311670830461935899381a Mon Sep 17 00:00:00 2001 From: kingbri Date: Sun, 2 Jul 2023 18:31:02 -0400 Subject: [PATCH] Utils: Add UUID v4 support Unique IDs should use UUID as there's a higher prevention of overflow when assigning them. Signed-off-by: kingbri --- public/scripts/utils.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/public/scripts/utils.js b/public/scripts/utils.js index 4ba27ef47..e19b3f790 100644 --- a/public/scripts/utils.js +++ b/public/scripts/utils.js @@ -668,3 +668,11 @@ export async function waitUntilCondition(condition, timeout = 1000, interval = 1 }, interval); }); } + +export function uuidv4() { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { + const r = Math.random() * 16 | 0; + const v = c === 'x' ? r : (r & 0x3 | 0x8); + return v.toString(16); + }); +}