UNPKG

games

Version:

games

89 lines (72 loc) 1.96 kB
var _ = require('underscore'); exports.helloworld = function(){ return 'hello world'; }; exports.year = function(){ return new Date().getFullYear(); }; exports.month = function(){ return new Date().getMonth()+1; }; exports.mday = function(){ return new Date().getDate(); }; exports.hour = function(){ return new Date().getHours(); }; exports.min = function(){ return new Date().getMinutes(); }; exports.sec = function(){ return new Date().getSeconds(); }; exports.yday = function(){ return parseInt((new Date().getTime()+8*3600*1000)/86400000); }; exports.wday = function(){ return new Date().getDay(); }; exports.time = function(){ return new Date().getTime(); }; exports.seconds2midnight = function(){ var date = new Date(); var hour = date.getHours(); var min = date.getMinutes(); var sec = date.getSeconds(); return 86400-(hour*3600 + min*60 + sec); }; exports.exec = function(command_line,cb){ var exec = require('child_process').exec; exec(command_line,function(err,stdout,stderr){ cb(err,stdout,stderr); }); }; exports.readFile = function(filename,cb){ var fs = require('fs'); fs.readFile(filename,function(err,data){ cb(err,data.toString()); }); }; exports.md5 = function(str){ arcrypto = require('crypto'); var md5 = crypto.createHash('md5'); md5.update(str); return md5.digest('hex'); }; exports.between = function (str,from,to){ var ind_from = str.indexOf(from); var ind_to = str.indexOf(to); if(ind_from !== -1 && ind_to !== -1){ return str.substring(ind_from+from.length,ind_to); } return ""; } exports.outer = function (str,from,to){ var ind_from = str.indexOf(from); var ind_to = str.indexOf(to); if(ind_from !== -1 && ind_to !== -1 && ind_from <= ind_to){ return str.substring(0,ind_from) + str.substring(ind_to+to.length,str.length+1); } return ""; }