龙空技术网

碎片时间学编程「200]:在浏览器中生成 UUID值

路条编程 38

前言:

而今兄弟们对“html获取uuid”都比较看重,各位老铁们都想要剖析一些“html获取uuid”的相关内容。那么小编在网络上网罗了一些有关“html获取uuid””的相关知识,希望咱们能喜欢,小伙伴们快快来了解一下吧!

在浏览器中生成 UUID 值。

使用 Crypto.getRandomValues() 方法生成符合RFC4122版本 4 的 UUID 值。

使用 Number.prototype.toString() 方法将其转换为正确的 UUID(十六进制字符串)值。

JavaScript

const UUIDGeneratorBrowser = () =>  ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>    (      c ^      (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))    ).toString(16)  );

示例:

UUIDGeneratorBrowser(); // '7982fcfe-5721-4632-bede-6000885be57d'

更多内容请访问我的网站:

标签: #html获取uuid