twitst4tz

twitter statistics web application
Log | Files | Refs | README | LICENSE

index.js (1175B)


      1 
      2 /**
      3  * HOP ref.
      4  */
      5 
      6 var has = Object.prototype.hasOwnProperty;
      7 
      8 /**
      9  * Return own keys in `obj`.
     10  *
     11  * @param {Object} obj
     12  * @return {Array}
     13  * @api public
     14  */
     15 
     16 exports.keys = Object.keys || function(obj){
     17   var keys = [];
     18   for (var key in obj) {
     19     if (has.call(obj, key)) {
     20       keys.push(key);
     21     }
     22   }
     23   return keys;
     24 };
     25 
     26 /**
     27  * Return own values in `obj`.
     28  *
     29  * @param {Object} obj
     30  * @return {Array}
     31  * @api public
     32  */
     33 
     34 exports.values = function(obj){
     35   var vals = [];
     36   for (var key in obj) {
     37     if (has.call(obj, key)) {
     38       vals.push(obj[key]);
     39     }
     40   }
     41   return vals;
     42 };
     43 
     44 /**
     45  * Merge `b` into `a`.
     46  *
     47  * @param {Object} a
     48  * @param {Object} b
     49  * @return {Object} a
     50  * @api public
     51  */
     52 
     53 exports.merge = function(a, b){
     54   for (var key in b) {
     55     if (has.call(b, key)) {
     56       a[key] = b[key];
     57     }
     58   }
     59   return a;
     60 };
     61 
     62 /**
     63  * Return length of `obj`.
     64  *
     65  * @param {Object} obj
     66  * @return {Number}
     67  * @api public
     68  */
     69 
     70 exports.length = function(obj){
     71   return exports.keys(obj).length;
     72 };
     73 
     74 /**
     75  * Check if `obj` is empty.
     76  *
     77  * @param {Object} obj
     78  * @return {Boolean}
     79  * @api public
     80  */
     81 
     82 exports.isEmpty = function(obj){
     83   return 0 == exports.length(obj);
     84 };