Skip to content

Latest commit

 

History

History
25 lines (18 loc) · 461 Bytes

File metadata and controls

25 lines (18 loc) · 461 Bytes

generateUUID()

Overview

Generates a universally unique identifier (UUID).

Code

A screenshot of the titular code snippet

const generateUUID = () =>
  "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
    const r = (Math.random() * 16) | 0,
      v = c === "x" ? r : (r & 0x3) | 0x8;
    return v.toString(16);
  });

Usage

const uniqueId = uuid();
console.log(uniqueId);