Created
January 24, 2021 02:35
-
-
Save HallexCosta/6c2a14d2be1a888fb9ff963702b96f3b to your computer and use it in GitHub Desktop.
Generate Unique Id (ObjectId)
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 function guid(): string { | |
const date = new Date() | |
const timestamp = ((date.getTime() / 1000) | 0).toString(16) | |
const context = `${timestamp}xxxxxxxxxxxxxxxx` | |
const hash = context | |
.replace(/[x]/g, () => ((Math.random() * 16) | 0).toString(16)) | |
.toLowerCase() | |
return hash | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment