blob: fd4201d7ace7ecc05db5668d4350c3419ae52328 (
plain)
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
40
41
42
43
44
45
46
47
|
var is = require('is');
var Immutable = require('immutable');
var File = require('./file');
var Config = Immutable.Record({
file: File(),
values: Immutable.Map()
});
Config.prototype.getPath = function() {
return this.get('path');
};
Config.prototype.getValues = function() {
return this.get('values');
};
/**
Return a configuration value by its key path
@param {String} key
@return {Mixed}
*/
Config.prototype.getValue = function(keyPath, def) {
var values = this.getValues();
if (is.string(keyPath)) keyPath = keyPath.split('.');
return values.getIn(keyPath) || def;
};
/**
Create a new config, throw error if invalid
@param {File} file
@param {Object} values
@returns {Config}
*/
Config.create = function(file, values) {
return new Config({
file: file,
values: Immutable.fromJS(values)
});
};
module.exports = Config;
|