hapipal / confidence

Dynamic, declarative configurations
Other
264 stars 44 forks source link

Evaluate if $default is defined instead of using it as a boolean #116

Closed jlimas closed 2 years ago

devinivy commented 2 years ago

Thanks for the contribution! Could you add a test to ensure we're fixing the case you described in #115?

jlimas commented 2 years ago

Hello @devinivy ! I did add a test case specifically for the issue I was having in #115

The test case below without the fix was returning undefined since it was evaluating if node.$default and since 0 evaluates to false it was assuming the node didn't have a $default property. I just changed the code to check if the variable is defined instead.

key12: {
    zero: {
        $env: 'ZERO',
        $coerce: 'number',
        $default: 0
    }
},

get('/key12', { zero: 0 }, {}, [], {});
get('/key12', { zero: 1000 }, {}, [], { ZERO: '1000' });
devinivy commented 2 years ago

Oh apologies, not sure how I missed that! Thanks 👍

jlimas commented 2 years ago

No worries, really happy to help, I'm a big fan of this library.

devinivy commented 2 years ago

Resolves #115

Nargonath commented 2 years ago

Thanks @devinivy for the publish and @jlimas for the quick fix. 💪