hapipal / confidence

Dynamic, declarative configurations
Other
264 stars 44 forks source link

$coerce array #97

Closed YoannMa closed 4 years ago

YoannMa commented 4 years ago

I sometime deal with environment variables storing an array of string that I want to split. I currently do that outside of confidence.

I thought of having a way to declare it like :

new Confidence.Store({
    foo : {
        bar: { $env : 'MY_ENV', $coerce : 'array', $splitToken : ',', $default : [] },
    }
})

Or would it be better to keep this out of Confidence ? As it can introduce some weird edge case like wanting to coerce to an array of number. It could also lead to more feature like parsing JSON, etc...

I can send a PR to implement the feature.

augnin commented 4 years ago

you're most welcome to submit a PR

augnin commented 4 years ago

@YoannMa, and while you are at it, would you mind adding a few more data types? like boolean and possibly an object?