-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
53 lines (46 loc) · 1.13 KB
/
config.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"use strict";
// config.js
var fs = require('fs');
function fileExists(path) {
try {
var stats = fs.lstatSync(path);
if (stats.isFile()) {
return true;
}
} catch (e) {
}
return false;
}
var Config = function (file) {
var _file, _config;
// Constructor
function Config(file) {
if (!(this instanceof Config)) {
return new Config(file);
}
_file = file || "config.json";
if (fileExists(_file)) {
try {
_config = JSON.parse(fs.readFileSync(_file));
} catch (e) {
}
}
_config = _config || {};
}
Config.prototype.get = function () {
var c = _config;
for (var i = 0; i < arguments.length; i++) {
if (c[arguments[i]]) {
c = c[arguments[i]];
} else {
return undefined;
}
}
return c;
};
Config.prototype.exists = function () {
return this.get.apply(null, arguments) !== undefined;
};
return new Config(file);
}
var exports = module.exports = Config