Skip to content

Commit

Permalink
refine comment
Browse files Browse the repository at this point in the history
  • Loading branch information
marcuspoehls committed Feb 12, 2024
1 parent 54358f3 commit 8ae71de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/contracts/src/env/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export interface EnvStore {
number (key: string, defaultValue: number): number

/**
* Returns the environment variable identified by the given `key` as a boolean value.
* Returns the environment variable identified by the given `key` as a boolean
* value. The environment variable values `'true'` and `'1'` translate to a
* truthy value, every other value returns `false` or the default value.
*/
boolean (key: string): boolean
boolean (key: string, defaultValue: boolean): boolean
Expand Down
8 changes: 5 additions & 3 deletions packages/env/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ export class Env implements EnvStore {
}

/**
* Returns the environment variable identified by the given `key` as a boolean value.
* Returns the environment variable identified by the given `key` as a boolean
* value. The environment variable values `'true'` and `'1'` translate to a
* truthy value, every other value returns `false` or the default value.
*/
boolean (key: string): boolean
boolean (key: string, defaultValue: boolean): boolean
boolean (key: string, defaultValue?: boolean): boolean {
const validTruthy = ['1', 'true']
const truthyValues = ['1', 'true']
key = this.get(key).toLowerCase()

if (validTruthy.includes(key)) {
if (truthyValues.includes(key)) {
return true
}

Expand Down

0 comments on commit 8ae71de

Please sign in to comment.