Skip to content

Instantly share code, notes, and snippets.

@guiseek
Created March 11, 2021 00:51
Show Gist options
  • Save guiseek/5d178f05a44ccbe4432a7386132c3f63 to your computer and use it in GitHub Desktop.
Save guiseek/5d178f05a44ccbe4432a7386132c3f63 to your computer and use it in GitHub Desktop.
UUID / Tweet 4 / 10/03/2021
export class uuid {
static long() {
return uuid.fromBase('xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx')
}
static short() {
return uuid.fromBase('xxxxxxxx')
}
private static fromBase(base: string) {
return base.replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0
const v = c == 'x' ? r : (r & 0x3) | 0x8
return v.toString(16)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment