New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

configury

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

configury

Easy management of environment based configuration

latest
Source
npmnpm
Version
0.3.0
Version published
Maintainers
1
Created
Source

configury

Easy management of environment based configuration

build status

Installation

  npm install configury

Usage

configury([path, defaultSection])

Using in-memory configuration

var configury = require('configury')
  , config = configury()

Using configuration file on disk

var configury = require('configury')
  , config = configury('./properties.json')

Using default config section other than 'global'

var configury = require('configury')
  , config = configury('./properties.json', 'myDefaultConfigSection')

config.raw()

var configury = require('configury')
  , config = configury('./properties.json')

config.raw()
//-> { "global": { "foo": "bar" }, "development": { "foo": "bar" } ... }

config.write([path, cb])

Save the current configuration in memory to disk

var configury = require('configury')
  , config = configury('./properties.json')

// Write to './properties.json' file on disk synchronously
config.write()

// Write to './properties.json' file on disk asynchronously
config.write(false, function (err) {
  if (!err) console.log('Yeah')
})

// Write to './myBackupProperties.json' file on disk asynchronously
config.write('myBackupProperties.json', function (err) {
  if (!err) console.log('Yeah')
})

// Write to './myBackupProperties.json' file on disk synchronously
config.write('myBackupProperties.json')

config.set(key, value)

Setting a variable in 'global' configuration

var configury = require('configury')
  , config = configury('./properties.json')

config.set('Alice', 'Bob')
config.raw()
//-> { "global": { "Alice": "Bob" } ... }

Setting a variable in 'myCustomGlobal'

var configury = require('configury')
  , config = configury('./properties.json', 'myCustomGlobal')

config.set('Alice', 'Bob')
config.raw()
//-> { "myCustomGlobal": { "Alice": "Bob" } ... }

config.section(section)

var configury = require('configury')
  , config = configury('./properties.json', 'myCustomGlobal')

var mySection = config.section('mySection')
//-> mySection = { set: function(key, value), merge: function(object) }

Setting a variable in 'mySection'

var configury = require('configury')
  , config = configury('./properties.json')
  , mySection = config.section('mySection')

mySection.set('Alice', 'Bob')
config.raw()
//-> { "global": { ... } "mySection" { "Alice": "Bob" } }

config.merge()

Merging an object over a property in the configuration

var configury = require('configury')
  , config = configury('./properties.json')

config.set('foo', 'bar')
//-> { "global": { "foo": "bar" } ... }
config.merge({ 'global': { 'foo': 'woo' }, 'pickles': 'bananas' })
//-> { "global": { "foo": "woo" }, "pickles": "bananas" }

Merging an object over a property in 'mySection'

var configury = require('configury')
  , config = configury('./properties.json')
  , mySection = config.section('mySection')

mySection.set('foo', 'bar')
//-> { "global": { ... } "mySection": { "foo": "bar" } }
mySection.merge({ 'foo': 'woo' })
//-> { "global": { ... } "mySection": { "foo": "woo" } }

Substitution

By default, configury will substitute any values that match the pattern: %string%. This will substitute the current value with the value of that key if it exists. E.g:

var configury = require('configury')
  , config = configury()

config.set('url', 'http://localhost:3000')
config.set('loginUrl', '%url%/login')

console.log(config().loginUrl)
//-> 'http://localhost:3000/login'

Credits

Paul Serby follow me on twitter @serby

Licence

Licensed under the New BSD License

FAQs

Package last updated on 26 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts