Created
March 11, 2021 00:51
-
-
Save guiseek/5d178f05a44ccbe4432a7386132c3f63 to your computer and use it in GitHub Desktop.
UUID / Tweet 4 / 10/03/2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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