From b4d67c767c02fffc383780abe1e33237773b1785 Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Tue, 13 Jul 2021 22:39:19 +0100 Subject: [PATCH] Update utils.ts --- utils/utils.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/utils/utils.ts b/utils/utils.ts index 560eacce4..b56f8d5de 100644 --- a/utils/utils.ts +++ b/utils/utils.ts @@ -1586,17 +1586,21 @@ export function getFromCache( return value } +const byteToHex = [] + +for (let i = 0; i < 256; ++i) { + byteToHex.push((i + 0x100).toString(16).substr(1)) +} + /** * Get a unique string id. */ -export function uniqueId(): string { - const array = new Uint32Array(8) - window.crypto.getRandomValues(array) - let str = '' - for (let i = 0; i < array.length; i++) { - str += (i < 2 || i > 5 ? '' : '-') + array[i].toString(16).slice(-4) - } - return str + +export function uniqueId(a = ''): string { + return a + ? /* eslint-disable no-bitwise */ + ((Number(a) ^ (Math.random() * 16)) >> (Number(a) / 4)).toString(16) + : `${1e7}-${1e3}-${4e3}-${8e3}-${1e11}`.replace(/[018]/g, uniqueId) } /**