Function Signature
Parameters
The name of the environment variable to read
Returns
UUID | undefined - A UUID string (branded type from node:crypto), or undefined if the variable is not set or empty.
Behavior
Returnsundefined when:
- The environment variable is not set
- The environment variable is an empty string
- The environment variable contains only whitespace
TypeError when:
- The value is not a valid UUID format
Example
UUID Format
Accepts standard UUID formats:550e8400-e29b-41d4-a716-446655440000(with hyphens)- Any valid UUID v1, v3, v4, or v5
When to Use
UsemaybeEnvUuid instead of envUuid when:
- The environment variable is optional
- You want to handle missing values gracefully with
undefined - You can generate a UUID or use alternative logic when not provided
envUuid when:
- The environment variable is required for your application
- You want the application to fail fast if the variable is missing
