-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
40 lines (36 loc) · 913 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
var transforms = require('./lib/transforms');
/**
* Build a configuration object from a list of transformations:
*
* var confab = require('confab');
* var config = confab([
* confab.loadJSON([
* './config.' + process.env.NODE_ENV + '.json',
* './config.json'
* ]),
*
* confab.defaults({
* role: 'api',
* port: 3200
* })
* ]);
*
* Later, access the configuration exactly as you would expect.
*
* console.log(config.role); // 'api'
*
* @id confab
* @type Function
* @param {Array<Function>} transforms - a list of transformation functions
* @return Object
*/
module.exports = function confab (transforms) {
return transforms.reduce(function (memo, fn) {
return fn(memo);
}, {});
};
// Extend with known transforms
for (var f in transforms) {
module.exports[f] = transforms[f];
}