Code coverage report for socket.io-client/lib/url.js

Statements: 100% (25 / 25)      Branches: 96.15% (25 / 26)      Functions: 100% (1 / 1)      Lines: 100% (24 / 24)      Ignored: none     

All files » socket.io-client/lib/ » url.js
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69          1 1           1                     1 20     20 20     8 8 2 1       8 3 3 2   1         8 8       8   1     8     8     8   8    
 
/**
 * Module dependencies.
 */
 
var parseuri = require('parseuri');
var debug = require('debug')('socket.io-client:url');
 
/**
 * Module exports.
 */
 
module.exports = url;
 
/**
 * URL parser.
 *
 * @param {String} url
 * @param {Object} An object meant to mimic window.location.
 *                 Defaults to window.location.
 * @api public
 */
 
function url(uri, loc){
  var obj = uri;
 
  // default to window.location
  var loc = loc || global.location;
  if (null == uri) uri = loc.protocol + '//' + loc.hostname;
 
  // relative path support
  Eif ('string' == typeof uri) {
    if ('/' == uri.charAt(0)) {
      if ('undefined' != typeof loc) {
        uri = loc.hostname + uri;
      }
    }
 
    if (!/^(https?|wss?):\/\//.test(uri)) {
      debug('protocol-less url %s', uri);
      if ('undefined' != typeof loc) {
        uri = loc.protocol + '//' + uri;
      } else {
        uri = 'https://' + uri;
      }
    }
 
    // parse
    debug('parse %s', uri);
    obj = parseuri(uri);
  }
 
  // make sure we treat `localhost:80` and `localhost` equally
  if ((/(http|ws)/.test(obj.protocol) && 80 == obj.port) ||
     (/(http|ws)s/.test(obj.protocol) && 443 == obj.port)) {
    delete obj.port;
  }
 
  obj.path = obj.path || '/';
 
  // define unique id
  obj.id = obj.protocol + obj.host + (obj.port ? (':' + obj.port) : '');
 
  // define href
  obj.href = obj.protocol + '://' + obj.host + (obj.port ? (':' + obj.port) : '');
 
  return obj;
}