Created
January 20, 2022 10:39
-
-
Save AndrewIngram/b59fa2321e6b0d53556f12f0f0f13ded to your computer and use it in GitHub Desktop.
Stable UUID hack
This file contains 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
import { v5 as uuidv5, NIL } from 'uuid'; | |
function stableUuid(namespace, name) { | |
return uuidv5(name, uuidv5(namespace, NIL)) | |
} | |
// > stableUuid('Some namespace', 'some name') | |
// '019761ac-2321-5ae0-9086-70c9557bcc58' | |
// > stableUuid('Some namespace', 'some name') | |
// '019761ac-2321-5ae0-9086-70c9557bcc58' | |
// > stableUuid('Some namespace', 'some other name') | |
// '68944cf9-ebbf-58c6-8e4a-fd1390ad95bc' |
This file contains 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
from uuid import UUID, uuid5 | |
def stable_uuid(namespace: str, name: str): | |
return uuid5( | |
uuid5( | |
UUID("00000000-0000-0000-0000-000000000000"), | |
namespace | |
), | |
name | |
) | |
# >>> stable_uuid('Some namespace', 'some name') | |
# UUID('019761ac-2321-5ae0-9086-70c9557bcc58') | |
# >>> stable_uuid('Some namespace', 'some name') | |
# UUID('019761ac-2321-5ae0-9086-70c9557bcc58') | |
# >>> stable_uuid('Some namespace', 'some other name') | |
# UUID('68944cf9-ebbf-58c6-8e4a-fd1390ad95bc') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment