-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelper-functions.js
69 lines (60 loc) · 2.08 KB
/
helper-functions.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
Helper functions
*/
/*
This program is free software. It comes without any warranty, and is offered “as-is”, without warranty. The software user accepts all liability for damages resulting in the use of this software.
All trademarks are the property of their respective owners.
No agreement has been made between any party to ensure support of this project. Any connectivity issues should be investigated with your authorized support representative.
To the extent permitted by applicable law.
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
See LICENSE file for more information.
*/
const fs = require(`fs`);
module.exports = {
padZero: (input) => {
// Pad digits with 0 if needed and returns two-digit format.
if(input < 10){
input = `0` + input;
return(input);
} else {
return(input);
}
},
theDate: (returnType) => {
// Returns date or data/time.
var dateFnc = new Date();
var date = dateFnc.getFullYear() + `-` + (dateFnc.getMonth() + 1) + `-` + dateFnc.getDate();
var time = dateFnc.getHours() + `:` + module.exports.padZero(dateFnc.getMinutes()) + `:` + module.exports.padZero(dateFnc.getSeconds());
var dateTime = date + ` - ` + time;
if(returnType == `date`){
return date;
} else if(returnType == `dateTime`){
return dateTime;
}
},
logFile: (message, fileName) => {
// Append information to a log file.
fs.appendFile(`./Logs/` + fileName, message + `\n`, `utf8`, (err) => {
});
},
logMessage: (direction, message, data, fileName) => {
// Log information to console, file, or both.
if(direction == `in`){
var direction = `=>`;
} else if(direction == `out`){
var direction = `<=`;
} else if(direction == `other`){
var direction = `--`;
} else if(direction == `notify`){
var direction = `!!`;
}
var theMessage = `\t` + direction + `\t` + message + `:\t` + data;
if(process.env.VERBOSE_CONSOLE ===`true`){
console.log(theMessage);
}
if(process.env.VERBOSE_LOG){
module.exports.logFile(module.exports.theDate(`dateTime`) + `\t:` + theMessage, module.exports.theDate(`date`) + `.log`);
}
}
}