Created
December 4, 2020 11:42
-
-
Save Torthu/d2484ba06d415a52d4f3c5bed0181bd3 to your computer and use it in GitHub Desktop.
Quick UUIDv4 regex/type guard
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
type UUID = string; | |
function isUuid(uuid: string): uuid is UUID { | |
return ( | |
uuid.match(/^[0-9A-Fa-f]{8}(?:-[0-9A-Fa-f]{4}){3}-[0-9A-Fa-f]{12}$/) | |
?.length > 0 | |
); | |
} | |
export default UUID; | |
export isUuid; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment