Function Signature
Parameters
The name of the environment variable to read
Returns
Date | undefined - The parsed Date object, 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 cannot be parsed as a valid date
Example
When to Use
UsemaybeEnvDate instead of envDate when:
- The environment variable is optional
- You want to handle missing values gracefully with
undefined - The date represents an optional deadline or timestamp
envDate when:
- The environment variable is required for your application
- You want the application to fail fast if the variable is missing
