util.js 741 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. function pad(num) {
  2. if(num < 10) {
  3. return '0'+num;
  4. }
  5. else {
  6. return ''+num;
  7. }
  8. }
  9. function dateToString(date) {
  10. var dateString =
  11. date.getFullYear()+'/'+pad(1+date.getMonth())+'/'+ pad(date.getDate())+
  12. ' '+
  13. pad(date.getHours())+':'+pad(date.getMinutes());
  14. return dateString;
  15. }
  16. function merge(a, b) {
  17. for(var i in b) {
  18. var n = a[i];
  19. var o = b[i];
  20. if(typeof n == 'object' && typeof o == 'object') {
  21. merge(n, o);
  22. }
  23. else {
  24. a[i] = b[i];
  25. }
  26. }
  27. return a;
  28. }
  29. function deepMerge() {
  30. var ret = {};
  31. for(var i = 0; i < arguments.length; ++i) {
  32. merge(ret, arguments[i]);
  33. }
  34. return ret;
  35. }
  36. module.exports = {
  37. dateToString: dateToString,
  38. deepMerge: deepMerge
  39. }