projeto-hit/TEST_SERVER1/test/whats/funcs/tools.js

44 lines
1.4 KiB
JavaScript
Raw Normal View History

module.exports = function() {
this.getTimestamp = function() {
var date = new Date();
var year = date.getFullYear();
var month = ("0"+(date.getMonth()+1)).substr(-2);
var day = ("0"+date.getDate()).substr(-2);
var hour = ("0"+date.getHours()).substr(-2);
var minutes = ("0"+date.getMinutes()).substr(-2);
var seconds = ("0"+date.getSeconds()).substr(-2);
return year+"-"+month+"-"+day+" "+hour+":"+minutes+":"+seconds;
};
this.log = function(desc, message) {
console.log(getTimestamp() + ' >> ' + desc + " :: ");
console.log(message);
};
this.getTime = function() {
var date = new Date();
var hour = ("0"+date.getHours()).substr(-2);
var minutes = ("0"+date.getMinutes()).substr(-2);
var seconds = ("0"+date.getSeconds()).substr(-2);
return hour+":"+minutes+":"+seconds;
};
this.forceGC = function() {
if (global.gc) {
console.log(getTimestamp() + " >> Starting Garbage Collector...");
global.gc();
} else {
console.warn("Garbage Collector não habilitado! Execute seu programa com node --expose-gc app.js.");
}
};
this.isJSON = function(str) {
try {
return (JSON.parse(str) && !!str);
} catch (e) {
return false;
}
}
}