Skip to content

Commit

Permalink
fix(get-env): getEnvValue logic
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Oct 25, 2024
1 parent 544e23d commit 8f1afd7
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/get-env-value/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ __dev_mode__: packageTracer.add(__package_name__, __package_version__);
/**
* Parameters for retrieving an environment variable value.
*/
export type GetEnvValueParams = {
export type GetEnvValueOption = {
/**
* The name of the environment variable.
*/
Expand All @@ -26,14 +26,15 @@ export type GetEnvValueParams = {
developmentValue?: string;
}

export function getEnvValue(option: GetEnvValueParams): string {
export function getEnvValue(option: GetEnvValueOption): string {
let value = process.env[option.name];
if (value === '') value = undefined; // empty string is considered as undefined in environment variables

value ??= option.defaultValue;

if (platformInfo.development === true) {
value ??= option.developmentValue;
value ??= option.developmentValue ?? option.defaultValue;
}
else {
value ??= option.defaultValue;
}

if (value === undefined) {
Expand Down

0 comments on commit 8f1afd7

Please sign in to comment.