Skip to content

tlvince/rc2env

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rc2env

Build Status npm version License

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'
}

Installation

npm install --save rc2env

Usage

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'
}

Author

© 2016 Tom Vincent git@tlvince.com (https://tlvince.com)

License

Released under the MIT license.