Sha256: 8edf1320d2c642566d9a38975e4beace209596c5afceb4a5b4ca23a5d6df95fa

Contents?: true

Size: 975 Bytes

Versions: 23

Compression:

Stored size: 975 Bytes

Contents

'use strict';

var URL = require('url-parse');

var debug = function() {};
if (process.env.NODE_ENV !== 'production') {
  debug = require('debug')('sockjs-client:utils:url');
}

module.exports = {
  getOrigin: function(url) {
    if (!url) {
      return null;
    }

    var p = new URL(url);
    if (p.protocol === 'file:') {
      return null;
    }

    var port = p.port;
    if (!port) {
      port = (p.protocol === 'https:') ? '443' : '80';
    }

    return p.protocol + '//' + p.hostname + ':' + port;
  }

, isOriginEqual: function(a, b) {
    var res = this.getOrigin(a) === this.getOrigin(b);
    debug('same', a, b, res);
    return res;
  }

, isSchemeEqual: function(a, b) {
    return (a.split(':')[0] === b.split(':')[0]);
  }

, addPath: function (url, path) {
    var qs = url.split('?');
    return qs[0] + path + (qs[1] ? '?' + qs[1] : '');
  }

, addQuery: function (url, q) {
    return url + (url.indexOf('?') === -1 ? ('?' + q) : ('&' + q));
  }
};

Version data entries

23 entries across 23 versions & 10 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/sockjs-client/lib/utils/url.js
disco_app-0.18.0 test/dummy/node_modules/sockjs-client/lib/utils/url.js
disco_app-0.18.2 test/dummy/node_modules/sockjs-client/lib/utils/url.js
tang-0.2.1 spec/tang_app/node_modules/sockjs-client/lib/utils/url.js
tang-0.2.0 spec/tang_app/node_modules/sockjs-client/lib/utils/url.js
tang-0.1.0 spec/tang_app/node_modules/sockjs-client/lib/utils/url.js
tang-0.0.9 spec/tang_app/node_modules/sockjs-client/lib/utils/url.js
enju_library-0.3.8 spec/dummy/node_modules/sockjs-client/lib/utils/url.js
ilog-0.4.1 node_modules/sockjs-client/lib/utils/url.js
ilog-0.4.0 node_modules/sockjs-client/lib/utils/url.js
ilog-0.3.3 node_modules/sockjs-client/lib/utils/url.js
jester-data-8.0.0 node_modules/sockjs-client/lib/utils/url.js
ezii-os-5.2.1 node_modules/sockjs-client/lib/utils/url.js
ezii-os-2.0.1 node_modules/sockjs-client/lib/utils/url.js
ezii-os-1.1.0 node_modules/sockjs-client/lib/utils/url.js
ezii-os-1.0.0 node_modules/sockjs-client/lib/utils/url.js
ezii-os-0.0.0.1.0 node_modules/sockjs-client/lib/utils/url.js
ezii-os-0.0.0.0.1 node_modules/sockjs-client/lib/utils/url.js
optimacms-0.4.3 spec/dummy/node_modules/sockjs-client/lib/utils/url.js
optimacms-0.4.2 spec/dummy/node_modules/sockjs-client/lib/utils/url.js