@@ -33,7 +33,6 @@ export function getEnv(): Required<ENVIRONMENT> {
33
33
34
34
/**
35
35
* Retrieves a number from an environment variable.
36
- * - Trims leading and trailing whitespace.
37
36
* - Returns `undefined` if the environment variable is empty, unset, contains only whitespace, or is not a number.
38
37
* - Returns a number in all other cases.
39
38
*
@@ -75,26 +74,29 @@ export function getStringFromEnv(key: string): string | undefined {
75
74
/**
76
75
* Retrieves a boolean value from an environment variable.
77
76
* - Trims leading and trailing whitespace and ignores casing.
78
- * - Returns `undefined ` if the environment variable is empty, unset, or contains only whitespace.
79
- * - Returns `undefined ` for strings that cannot be mapped to a boolean.
77
+ * - Returns `false ` if the environment variable is empty, unset, or contains only whitespace.
78
+ * - Returns `false ` for strings that cannot be mapped to a boolean.
80
79
*
81
80
* @param {string } key - The name of the environment variable to retrieve.
82
- * @returns {boolean | undefined } - The boolean value or `undefined` .
81
+ * @returns {boolean } - The boolean value or `false` if the environment variable is unset empty, unset, or contains only whitespace .
83
82
*/
84
- export function getBooleanFromEnv ( key : string ) : boolean | undefined {
83
+ export function getBooleanFromEnv ( key : string ) : boolean {
85
84
const raw = process . env [ key ] ?. trim ( ) . toLowerCase ( ) ;
86
85
if ( raw == null || raw === '' ) {
87
- return undefined ;
86
+ // NOTE: falling back to `false` instead of `undefined` as required by the specification.
87
+ // If you have a use-case that requires `undefined`, consider using `getStringFromEnv()` and applying the necessary
88
+ // normalizations in the consuming code.
89
+ return false ;
88
90
}
89
91
if ( raw === 'true' ) {
90
92
return true ;
91
93
} else if ( raw === 'false' ) {
92
94
return false ;
93
95
} else {
94
96
diag . warn (
95
- `Unknown value ${ inspect ( raw ) } for ${ key } , expected 'true' or 'false', using defaults `
97
+ `Unknown value ${ inspect ( raw ) } for ${ key } , expected 'true' or 'false', falling back to 'false' (default) `
96
98
) ;
97
- return undefined ;
99
+ return false ;
98
100
}
99
101
}
100
102
0 commit comments