Update utils.ts
This commit is contained in:
parent
72a0fd38dd
commit
b4d67c767c
1 changed files with 12 additions and 8 deletions
|
@ -1586,17 +1586,21 @@ export function getFromCache<V, I extends object>(
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const byteToHex = []
|
||||||
|
|
||||||
|
for (let i = 0; i < 256; ++i) {
|
||||||
|
byteToHex.push((i + 0x100).toString(16).substr(1))
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a unique string id.
|
* Get a unique string id.
|
||||||
*/
|
*/
|
||||||
export function uniqueId(): string {
|
|
||||||
const array = new Uint32Array(8)
|
export function uniqueId(a = ''): string {
|
||||||
window.crypto.getRandomValues(array)
|
return a
|
||||||
let str = ''
|
? /* eslint-disable no-bitwise */
|
||||||
for (let i = 0; i < array.length; i++) {
|
((Number(a) ^ (Math.random() * 16)) >> (Number(a) / 4)).toString(16)
|
||||||
str += (i < 2 || i > 5 ? '' : '-') + array[i].toString(16).slice(-4)
|
: `${1e7}-${1e3}-${4e3}-${8e3}-${1e11}`.replace(/[018]/g, uniqueId)
|
||||||
}
|
|
||||||
return str
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue