All files util.js

100% Statements 26/26
100% Branches 10/10
100% Functions 6/6
100% Lines 25/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 444x 35x     4x 4x 2x   2x     4x 4x 4x 7x 7x 1x   7x       4x     4x 8x 8x   6x   8x     4x 2x   1x 1x 1x   1x    
exports.isNumber = function(arg) {
  return !isNaN(arg) && typeof arg === 'number';
};
 
exports.isEmpty = function(obj) {
  if (typeof obj === 'object') {
    return JSON.stringify(obj) === '{}';
  }
  return !obj;
};
 
exports.build_query = function(obj) {
  const params = [];
  for (const k in obj) {
    let val = obj[k];
    if (typeof val === 'object') {
      val = JSON.stringify(val);
    }
    params.push(
      encodeURIComponent(k) + '=' + encodeURIComponent(val)
    );
  }
  return params.join('&');
};
 
exports.getPerformance = function() {
  const performance = global.performance;
  if (!performance) {
    // eslint-disable-next-line no-console
    console.log('Browser doesn\'t support Performance API');
  }
  return performance;
};
 
exports.sendLog = function(url) {
  if (!url) return;
 
  global.sadLog = new Image();
  global.sadLog.onload = global.sadLog.onerror = () => {
    delete global.sadLog;
  };
  global.sadLog.src = url;
};