-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathutils.js
More file actions
75 lines (63 loc) · 1.45 KB
/
Copy pathutils.js
File metadata and controls
75 lines (63 loc) · 1.45 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var EventEmitter = require('events').EventEmitter;
var logging = new EventEmitter();
var config = new EventEmitter();
var path = require('path');
var fs = require('fs');
var misc = this;
var configPath = path.join(__dirname, 'config.json');
config.nconf = require('nconf');
logging.setMaxListeners(50);
//Check if config file exists
if (!fs.existsSync(configPath))
{
fs.writeFileSync(configPath, '{}');
}
//Read config from command line arguments, environment variables, and the config file
//(each one takes precedence over the next)
config.nconf.argv().env().file({ file: configPath });
logging.packet = function (msg)
{
logging.emit('packet', msg);
}
logging.debug = function (msg)
{
logging.emit('debug', msg);
}
logging.info = function (msg)
{
logging.emit('info', msg);
}
logging.logerror = function (msg)
{
logging.emit('logerror', msg);
}
config.change = function (event, options)
{
config.emit(event, options);
}
misc.isNumber = function (n)
{
return !isNaN(parseFloat(n)) && isFinite(n);
}
misc.toBoolean = function (obj)
{
if (typeof(obj) !== 'undefined')
{
if (obj.toString().toLowerCase() === 'true')
{
return true;
}
}
return false;
}
config.nconf.getBoolean = function(key)
{
return misc.toBoolean(config.nconf.get(key))
}
config.nconf.getInt = function(key)
{
return parseInt(config.nconf.get(key))
}
exports.logging = logging;
exports.config = config;
exports.misc = misc;