@aplus-frontend/ui
Version:
23 lines (22 loc) • 624 B
JavaScript
function n() {
const t = new Uint8Array(16);
if (typeof crypto < "u" && crypto.getRandomValues)
crypto.getRandomValues(t);
else
for (let e = 0; e < t.length; e++)
t[e] = Math.floor(Math.random() * 256);
t[6] = t[6] & 15 | 64, t[8] = t[8] & 63 | 128;
const r = Array.from(t).map((e) => e.toString(16).padStart(2, "0")).join("");
return [
r.substr(0, 8),
r.substr(8, 4),
"4" + r.substr(13, 3),
// 版本标识
(parseInt(r.substr(16, 2), 16) & 63 | 128).toString(16) + r.substr(18, 2),
// 变体标识
r.substr(20, 12)
].join("-");
}
export {
n as generateUniqueKey
};