Skip to content

Commit

Permalink
fix: optimized useEnv singleton fn
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Feb 12, 2024
1 parent aa28852 commit a7f08d1
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/env/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,20 @@ export function useEnv(key?: string) : any {
read(EnvironmentVariableName.TYPE),
read(EnvironmentVariableName.TYPE_ALT),
]);
const envURL = oneOf([
read(EnvironmentVariableName.URL),
read(EnvironmentVariableName.URL_ALT),
]);

if (envType) {
type = envType;
} else if (envURL) {
const temp = envURL;
if (temp) {
const parts = temp.split('://');
if (parts.length > 0) {
// eslint-disable-next-line prefer-destructuring
type = parts[0];
}
} else {
const envURL = oneOf([
read(EnvironmentVariableName.URL),
read(EnvironmentVariableName.URL_ALT),
]);

if (envURL) {
[type] = envURL.split('://');
}
}

if (type) {
output.type = type as DatabaseType; // todo: maybe validation here
}
Expand Down

0 comments on commit a7f08d1

Please sign in to comment.