Skip to content

Commit

Permalink
WIP for #37
Browse files Browse the repository at this point in the history
  • Loading branch information
af committed Jul 27, 2017
1 parent 2f2a07a commit c2384eb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,18 @@ function cleanEnv(inputEnv, specs = {}, options = {}) {

for (const k of varKeys) {
const spec = specs[k]
const devDefault = (env.NODE_ENV === 'production' ? undefined : spec.devDefault)
const usingDevDefault = (env.NODE_ENV !== 'production') && ('devDefault' in spec)
const devDefault = usingDevDefault ? spec.devDefault : undefined
let rawValue = env[k]

if (rawValue === undefined) {
rawValue = (devDefault === undefined ? spec.default : devDefault)
}

// Default values can be anything falsy (besides undefined), without
// Default values can be anything falsy (including an explicitly set undefined), without
// triggering validation errors:
const usingFalsyDefault = ((spec.default !== undefined) && (spec.default === rawValue)) ||
((devDefault !== undefined) && (devDefault === rawValue))
const usingFalsyDefault = (('default' in spec) && (spec.default === rawValue)) ||
(usingDevDefault && (devDefault === rawValue))

try {
if (rawValue === undefined && !usingFalsyDefault) {
Expand Down

0 comments on commit c2384eb

Please sign in to comment.