getUUID()function
getUUID(value: string): string | undefined
| Param | Type | |
|---|---|---|
value | string | The value to convert/validate as a UUID. required |
| Return | |
|---|---|
string | undefined | The normalised UUID string, or undefined if the value is not a valid UUID. |
Convert/validate a string value as a UUID, or return undefined if it isn't valid.
- Strips any non-hex characters (including existing dashes) and normalises to lowercase.
- Requires exactly 32 hex characters after cleaning, otherwise returns
undefined. - The returned string is re-grouped into the canonical
8-4-4-4-12segment layout.
Examples
getUUID("1b4e28ba-2fa1-4931-918f-4c9bf9f12b3a") // "1b4e28ba2fa14931918f4c9bf9f12b3a"