Convert rc's config object to env vars
const config = {
app: {
prop: 'foo',
camelCase: 'bar',
},
bar: 'baz'
}
rc2env(config)
//=>
{
APP_PROP: 'foo',
APP_CAMEL_CASE: 'bar',
BAR: 'baz'
}
npm install --save rc2env
rc2env(<object>[, string])
This is meant to be used with rc, so:
const rc = require('rc')
const rc2env = require('rc2env')
const defaults = {
app: {
prop: 'foo'
},
bar: 'baz'
}
const config = rc('app', defaults)
const envConfig = rc2env(config)
//=>
{
APP_PROP: 'foo',
BAR: 'baz'
}
Optionally, pass in a string (appname
) to form rc-like nested env properties:
const config = {
foo: 'foo',
bar: {
baz: 'baz',
preserveCase: 'yes'
}
}
const envConfig = rc2env(config, 'app')
//=>
{
app_foo: 'foo',
app_bar__baz: 'baz',
app_bar__preserveCase: 'yes'
}
© 2016 Tom Vincent git@tlvince.com (https://tlvince.com)
Released under the MIT license.