mirror of
https://github.com/imezx/Warp.git
synced 2025-04-25 07:30:02 +00:00
15 lines
403 B
TypeScript
15 lines
403 B
TypeScript
/**
|
|
* Create UUID according to
|
|
* https://www.ietf.org/rfc/rfc4122.txt.
|
|
*
|
|
* @returns Generated UUID.
|
|
*/
|
|
export function createUUID(): string {
|
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
/* eslint-disable no-bitwise */
|
|
const r = (Math.random() * 16) | 0;
|
|
const v = c === "x" ? r : (r & 0x3) | 0x8;
|
|
/* eslint-enable */
|
|
return v.toString(16);
|
|
});
|
|
}
|