Is UUID¶
isUuid validates that a value is a UUID in canonical hyphenated form for versions 1–4.
It enforces strict structural and bit‑level requirements: the value must be a string, must follow the canonical 8‑4‑4‑4‑12 hyphenated layout, must contain only hexadecimal characters, must specify a version between 1 and 4, and must use a valid variant nibble. Any non‑string value or incorrectly formatted UUID results in a single validation event. Otherwise, it produces no validation output.
Signature¶
Through the API:
isUuid();
And internally:
export const isUuid: ValidationRule
(value: unknown, path: FieldPath) => Promise<ReadonlyArray<JaneEvent>>
Events¶
| Event code | Description |
|---|---|
| type.not.valid | Value is not a string. |
| string.not.uuid | String does not match UUID v1–v4 canonical form. |
Design rationale¶
- Enforces canonical UUID formatting:
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. - Restricts version nibble to 1–4, matching the validator’s stated scope.
- Ensures variant nibble is one of 8, 9, a, or b (RFC‑compliant).
- Rejects non‑string values early with a structural‑type diagnostic.
- Avoids normalization — contributors must provide canonical UUID strings.
- Emits exactly one event per failure for clarity and composability.
- Pure, total, async‑compatible, and returns a readonly array of
JaneEventobjects. - Preserves the provided path and supports pipeline‑level
userMessageoverrides.
Invoke¶
isUuid runs only when explicitly included in a boundary or pipeline. It does not run automatically and is disabled when strict mode is enabled.
The rule activates when:
- The value is any JavaScript value.
- If the value is not a string, emits
type.not.valid. - If the string does not match:
/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-4][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/, emitsstring.not.uuid. - Otherwise, returns an empty result set.
Examples¶
Valid — UUIDs v1–v4¶
await isUuid("550e8400-e29b-41d4-a716-446655440000", "$");
// → []
await isUuid("f47ac10b-58cc-11cf-a937-08002b1f003d", "$");
// → []
Invalid — non‑string values¶
await isUuid(12345, "$");
// → [
// JaneEvent{
// kind: "error",
// code: "type.not.valid",
// path: "$",
// ...
// }
// ]
Invalid — incorrect format or version¶
await isUuid("550e8400e29b41d4a716446655440000", "$"); // missing hyphens
// → [
// JaneEvent{
// kind: "error",
// code: "string.not.uuid",
// path: "$",
// ...
// }
// ]
await isUuid("550e8400-e29b-61d4-a716-446655440000", "$"); // version 6 not allowed
// → [
// JaneEvent{
// kind: "error",
// code: "string.not.uuid",
// path: "$",
// ...
// }
// ]