index.ts 218 B

1234567
  1. export function v4() {
  2. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
  3. const r = Math.random() * 16 | 0
  4. const v = c === 'x' ? r : (r & 0x3 | 0x8)
  5. return v.toString(16)
  6. })
  7. }