lib/external/primus-client.js
function URL(address, location, parser) {
      if (!(this instanceof URL)) {
        return new URL(address, location, parser);
      }

      var relative = relativere.test(address)
        , parse, instruction, index, key
        , type = typeof location
        , url = this
        , i = 0;

      //
      // The following if statements allows this module two have compatibility with
      // 2 different API:
      //
      // 1. Node.js's `url.parse` api which accepts a URL, boolean as arguments
      //    where the boolean indicates that the query string should also be parsed.
      //
      // 2. The `URL` interface of the browser which accepts a URL, object as
      //    arguments. The supplied object will be used as default values / fall-back
      //    for relative paths.
      //
      if ('object' !== type && 'string' !== type) {
        parser = location;
        location = null;
      }

      if (parser && 'function' !== typeof parser) {
        parser = qs.parse;
      }

      location = lolcation(location);

      for (; i < instructions.length; i++) {
        instruction = instructions[i];
        parse = instruction[0];
        key = instruction[1];

        if (parse !== parse) {
          url[key] = address;
        } else if ('string' === typeof parse) {
          if (~(index = address.indexOf(parse))) {
            if ('number' === typeof instruction[2]) {
              url[key] = address.slice(0, index);
              address = address.slice(index + instruction[2]);
            } else {
              url[key] = address.slice(index);
              address = address.slice(0, index);
            }
          }
        } else if (index = parse.exec(address)) {
          url[key] = index[1];
          address = address.slice(0, address.length - index[0].length);
        }

        url[key] = url[key] || (instruction[3] || ('port' === key && relative) ? location[key] || '' : '');

        //
        // Hostname, host and protocol should be lowercased so they can be used to
        // create a proper `origin`.
        //
        if (instruction[4]) {
          url[key] = url[key].toLowerCase();
        }
      }

      //
      // Also parse the supplied query string in to an object. If we're supplied
      // with a custom parser as function use that instead of the default build-in
      // parser.
      //
      if (parser) url.query = parser(url.query);

      //
      // We should not add port numbers if they are already the default port number
      // for a given protocol. As the host also contains the port number we're going
      // override it with the hostname which contains no port number.
      //
      if (!required(url.port, url.protocol)) {
        url.host = url.hostname;
        url.port = '';
      }

      //
      // Parse down the `auth` for the username and password.
      //
      url.username = url.password = '';
      if (url.auth) {
        instruction = url.auth.split(':');
        url.username = instruction[0] || '';
        url.password = instruction[1] || '';
      }

      //
      // The href is just the compiled result.
      //
      url.href = url.toString();
    }
function URL(address, location, parser) {
      if (!(this instanceof URL)) {
        return new URL(address, location, parser);
      }

      var relative = relativere.test(address)
        , parse, instruction, index, key
        , type = typeof location
        , url = this
        , i = 0;

      //
      // The following if statements allows this module two have compatibility with
      // 2 different API:
      //
      // 1. Node.js's `url.parse` api which accepts a URL, boolean as arguments
      //    where the boolean indicates that the query string should also be parsed.
      //
      // 2. The `URL` interface of the browser which accepts a URL, object as
      //    arguments. The supplied object will be used as default values / fall-back
      //    for relative paths.
      //
      if ('object' !== type && 'string' !== type) {
        parser = location;
        location = null;
      }

      if (parser && 'function' !== typeof parser) {
        parser = qs.parse;
      }

      location = lolcation(location);

      for (; i < instructions.length; i++) {
        instruction = instructions[i];
        parse = instruction[0];
        key = instruction[1];

        if (parse !== parse) {
          url[key] = address;
        } else if ('string' === typeof parse) {
          if (~(index = address.indexOf(parse))) {
            if ('number' === typeof instruction[2]) {
              url[key] = address.slice(0, index);
              address = address.slice(index + instruction[2]);
            } else {
              url[key] = address.slice(index);
              address = address.slice(0, index);
            }
          }
        } else if (index = parse.exec(address)) {
          url[key] = index[1];
          address = address.slice(0, address.length - index[0].length);
        }

        url[key] = url[key] || (instruction[3] || ('port' === key && relative) ? location[key] || '' : '');

        //
        // Hostname, host and protocol should be lowercased so they can be used to
        // create a proper `origin`.
        //
        if (instruction[4]) {
          url[key] = url[key].toLowerCase();
        }
      }

      //
      // Also parse the supplied query string in to an object. If we're supplied
      // with a custom parser as function use that instead of the default build-in
      // parser.
      //
      if (parser) url.query = parser(url.query);

      //
      // We should not add port numbers if they are already the default port number
      // for a given protocol. As the host also contains the port number we're going
      // override it with the hostname which contains no port number.
      //
      if (!required(url.port, url.protocol)) {
        url.host = url.hostname;
        url.port = '';
      }

      //
      // Parse down the `auth` for the username and password.
      //
      url.username = url.password = '';
      if (url.auth) {
        instruction = url.auth.split(':');
        url.username = instruction[0] || '';
        url.password = instruction[1] || '';
      }

      //
      // The href is just the compiled result.
      //
      url.href = url.toString();
    }
function URL ( address , location , parser ) { if ( ! ( this instanceof URL ) ) { return new URL ( address , location , parser ) ; } var relative = relativere . test ( address ) , parse , instruction , index , key , type = typeof location , url = this , i = 0 ; // // The following if statements allows this module two have compatibility with // 2 different API: // // 1. Node.js's `url.parse` api which accepts a URL, boolean as arguments //    where the boolean indicates that the query string should also be parsed. // // 2. The `URL` interface of the browser which accepts a URL, object as //    arguments. The supplied object will be used as default values / fall-back //    for relative paths. // if ( 'object' !== type && 'string' !== type ) { parser = location ; location = null ; } if ( parser && 'function' !== typeof parser ) { parser = qs . parse ; } location = lolcation ( location ) ; for ( ; i < instructions . length ; i ++ ) { instruction = instructions [ i ] ; parse = instruction [ 0 ] ; key = instruction [ 1 ] ; if ( parse !== parse ) { url [ key ] = address ; } else if ( 'string' === typeof parse ) { if ( ~ ( index = address . indexOf ( parse ) ) ) { if ( 'number' === typeof instruction [ 2 ] ) { url [ key ] = address . slice ( 0 , index ) ; address = address . slice ( index + instruction [ 2 ] ) ; } else { url [ key ] = address . slice ( index ) ; address = address . slice ( 0 , index ) ; } } } else if ( index = parse . exec ( address ) ) { url [ key ] = index [ 1 ] ; address = address . slice ( 0 , address . length - index [ 0 ] . length ) ; } url [ key ] = url [ key ] || ( instruction [ 3 ] || ( 'port' === key && relative ) ? location [ key ] || '' : '' ) ; // // Hostname, host and protocol should be lowercased so they can be used to // create a proper `origin`. // if ( instruction [ 4 ] ) { url [ key ] = url [ key ] . toLowerCase ( ) ; } } // // Also parse the supplied query string in to an object. If we're supplied // with a custom parser as function use that instead of the default build-in // parser. // if ( parser ) url . query = parser ( url . query ) ; // // We should not add port numbers if they are already the default port number // for a given protocol. As the host also contains the port number we're going // override it with the hostname which contains no port number. // if ( ! required ( url . port , url . protocol ) ) { url . host = url . hostname ; url . port = '' ; } // // Parse down the `auth` for the username and password. // url . username = url . password = '' ; if ( url . auth ) { instruction = url . auth . split ( ':' ) ; url . username = instruction [ 0 ] || '' ; url . password = instruction [ 1 ] || '' ; } // // The href is just the compiled result. // url . href = url . toString ( ) ; }
The actual URL instance. Instead of returning an object we've opted-in to
create an actual constructor as it's much more memory efficient and
faster and it pleases my CDO.

@constructor
@param {String} address URL we want to parse.
@param {Boolean|function} parser Parser for the query string.
@param {Object} location Location defaults for relative paths.
@api public
The actual URL instance . Instead of returning an object we ve opted - in to create an actual constructor as it s much more memory efficient and faster and it pleases my CDO .