isUUID
Checks whether a value is a canonical UUID string. A UUID is considered valid when it is a string of 36 characters in the standard 8-4-4-4-12 format and contains only hexadecimal digits and hyphens.
This helper does not enforce UUID version or variant rules. It only verifies that the value matches the canonical UUID shape without coercion or normalization.
It never throws and never mutates input. Use it when you need to confirm that a value already represents a UUID in its canonical form.
Signature
function isUUID(value: unknown): value is string;
Parameters
| Name | Data type | Description |
|---|---|---|
| value | unknown |
The value to check as a potential UUID. |
Returns
true: If the value is a canonical UUID string.
false: Otherwise.
Behavior
- Requires the exact canonical UUID shape:
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. - Accepts uppercase or lowercase hexadecimal digits.
- Does not validate UUID version or variant bits.
- Rejects compact UUIDs (32 hex digits without hyphens).
- Rejects braces (
{}), URN prefixes (urn:uuid:), and any non-canonical formatting. - Never throws or mutates input.
Examples
isUUID("123e4567-e89b-12d3-a456-426614174000")
// true
isUUID("550e8400-e29b-41d4-a716-446655440000")
// true
isUUID("123E4567-E89B-12D3-A456-426614174000")
// true
isUUID("123e4567e89b12d3a456426614174000")
// false (compact form)
isUUID("{123e4567-e89b-12d3-a456-426614174000}")
// false (braces)
isUUID("not-a-uuid")
// false
Notes
- This helper does not coerce values. Non-strings always return
false. - Only the canonical 8-4-4-4-12 UUID format is accepted.
- Version and variant bits are not validated. This helper is format-only by design.
- Suitable for validating identifiers, request parameters, database keys, and any context requiring a guaranteed canonical UUID string.
- The helper never throws and never mutates input.