-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (38 loc) · 918 Bytes
/
index.js
File metadata and controls
43 lines (38 loc) · 918 Bytes
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
var fs = require('fs');
var _ = require('underscore');
var ini = require('ini');
var section = function(obj) {
return {
get: function(property) {
return ini_get_string_value(obj, property);
}
};
};
var ini_get_string_value = function(config, property) {
var result = null;
_.each(_.keys(config), function(key) {
if (key.toLowerCase().trim() == property.toLowerCase().trim()) {
result = config[key];
}
});
return result;
};
exports.open = function(options) {
if (_.isString(options)) {
options = {
file: options,
encoding: 'utf-8'
};
} else {
options = _.defaults(options || {}, {
file: 'my.ini',
encoding: 'utf-8'
});
}
var ini_object = ini.parse(fs.readFileSync(options.file, options.encoding));
return {
section: function(property) {
return new section(ini_get_string_value(ini_object, property));
}
};
};