1.2.4 • Published 9 years ago

nu-config v1.2.4

Weekly downloads
7
License
MIT
Repository
github
Last release
9 years ago

nu-config

A library for handling application configs.

Build Status Codecov npm version Dependency Status devDependency Status Known Vulnerabilities

Install

npm install nu-config

Usage

const Config = require('nu-config');

const config = new Config();

#get(prop)

Get a property from the config object.

Example

Assumeing the config object already has the following properties.

{
    fname: 'John',
    lname: 'Doe',
    age: '37',
    sex: 'male',
    spouse: {
        fname: 'Jane',
        lname: 'Doe',
        age: '36'
    },
    dynamic: 'age'
}

We can call config.get in several ways...

// Get a top level property
const name = config.get('fname'); // name === 'John'

// Get a nested property
const spouseName = config.get('spouse.fname'); // spouseName === 'Jane'

// Get a dynamic property
const age = config.get('spouse.{dynamic}'); // age === 36

#getAll()

Get all properties from the config object.

#set(prop, value)

Set a property of the config object.

Example

// Set a top level property
config.set('name', 'John');

const name = config.get('name'); // name === 'John';

// Set a nested property
config.set('car.make', 'Honda');

const carMake = config.get('car.make'); // carMake === 'Honda';

#merge(obj)

Merge an object with the config object. Not using assumed configs.

Example

config.set('prop', 10);

config.getAll(); // { prop: 10 }

config.merge({
    prop2: 20,
    prop3: [30, 40, 50]
});

config.getAll(); // { prop: 10, prop2: 20, prop3: [30, 40, 50] }

#env(file)

Merge contents of a JSON file with the config object asynchronously.

Example

config.env('file.json', callback(err, data) {
    // data === config data
});

#envAsync(file)

Merge contents of a JSON file with the config object using promises.

Example

config.env('file.json').then(function (result) {
    // result === config data
});

#envSync(file)

Merge contents of a JSON file with the config object synchronously.

Example

    const data = config.env('file.json'); // data === config data

License

MIT

1.2.4

9 years ago

1.2.3

9 years ago

1.2.2

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago