Subversion Repositories HomeAutomation

Rev

Rev 1647 | Rev 1660 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2. function get_time()
  3. {
  4.     return Math.round(new Date().getTime() / 1000);
  5. }
  6.  
  7. function to_array(obj)
  8. {
  9.     var result = [];
  10.    
  11.     for (var n = 0; n < obj.length; n++)
  12.     {
  13.         result.push(obj[n]);
  14.     }
  15.    
  16.     return result;
  17. }
  18.  
  19. function array_length(array)
  20. {
  21.     var count = 0;
  22.  
  23.     for (var n in array)
  24.     {
  25.         count++;
  26.     }
  27.  
  28.     return count;
  29. }
  30.  
  31. function in_array(array, item)
  32. {
  33.     for (var n in array)
  34.     {
  35.         if (array[n] == item)
  36.         {
  37.             return true;
  38.         }
  39.     }
  40.    
  41.     return false;
  42. }
  43.  
  44. function key_in_array(array, key)
  45. {
  46.     for (var n in array)
  47.     {
  48.         if (n == key)
  49.         {
  50.             return true;
  51.         }
  52.     }
  53.    
  54.     return false;
  55. }
  56.  
  57. function get_keys(array)
  58. {
  59.     var result = [];
  60.    
  61.     for (var name in array)
  62.     {
  63.         result.push(name);
  64.     }
  65.    
  66.     return result;
  67. }
  68.  
  69. String.prototype.ltrim = function(charlist)
  70. {
  71.     charlist = !charlist ? ' \s\xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
  72.     var re = new RegExp('^[' + charlist + ']+', 'g');
  73.     return this.replace(re, '');
  74. }
  75.  
  76. String.prototype.rtrim = function(charlist)
  77. {
  78.     charlist = !charlist ? ' \s\xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
  79.     var re = new RegExp('[' + charlist + ']+$', 'g');
  80.     return this.replace(re, '');
  81. }
  82.  
  83. String.prototype.trim = function(charlist)
  84. {
  85.     var str = this.ltrim(charlist);
  86.     return str.rtrim(charlist);
  87. }
  88.