Skip to content

Commit 9944723

Browse files
committed
make more readable for undefined -> null
1 parent d455db0 commit 9944723

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎lib/main.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,12 @@ function _resolveHome (envPath) {
259259
}
260260

261261
function _configOptions (options = {}) {
262-
// explicit `undefined` must not mask DOTENV_* env settings
263-
const defined = Object.fromEntries(Object.entries(options).filter(([, v]) => v !== undefined))
262+
const defined = { ...options }
263+
264+
for (const key of Object.keys(defined)) {
265+
if (defined[key] === undefined) delete defined[key]
266+
}
267+
264268
return { ...optionsFromEnv(), ...defined }
265269
}
266270

‎tests/test-config.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ t.test('undefined options do not override DOTENV_CONFIG_* defaults', ct => {
7777
ct.end()
7878
})
7979

80+
t.test('null options use environment defaults', ct => {
81+
process.env.DOTENV_CONFIG_PATH = 'tests/.env.local'
82+
process.env.DOTENV_CONFIG_QUIET = 'true'
83+
errorStub = sinon.stub(console, 'error')
84+
85+
const result = dotenv.config(null)
86+
87+
ct.equal(result.error, undefined)
88+
ct.equal(result.parsed.BASIC, 'local_basic')
89+
ct.equal(process.env.BASIC, 'local_basic')
90+
ct.ok(errorStub.notCalled)
91+
ct.end()
92+
})
93+
8094
t.test('takes string for path option', ct => {
8195
const testPath = 'tests/.env'
8296
const env = dotenv.config({ path: testPath })

0 commit comments

Comments
 (0)