source: trip-planner-front/node_modules/sockjs-client/lib/utils/url.js@ 6c1585f

Last change on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.1 KB
Line 
1'use strict';
2
3var URL = require('url-parse');
4
5var debug = function() {};
6if (process.env.NODE_ENV !== 'production') {
7 debug = require('debug')('sockjs-client:utils:url');
8}
9
10module.exports = {
11 getOrigin: function(url) {
12 if (!url) {
13 return null;
14 }
15
16 var p = new URL(url);
17 if (p.protocol === 'file:') {
18 return null;
19 }
20
21 var port = p.port;
22 if (!port) {
23 port = (p.protocol === 'https:') ? '443' : '80';
24 }
25
26 return p.protocol + '//' + p.hostname + ':' + port;
27 }
28
29, isOriginEqual: function(a, b) {
30 var res = this.getOrigin(a) === this.getOrigin(b);
31 debug('same', a, b, res);
32 return res;
33 }
34
35, isSchemeEqual: function(a, b) {
36 return (a.split(':')[0] === b.split(':')[0]);
37 }
38
39, addPath: function (url, path) {
40 var qs = url.split('?');
41 return qs[0] + path + (qs[1] ? '?' + qs[1] : '');
42 }
43
44, addQuery: function (url, q) {
45 return url + (url.indexOf('?') === -1 ? ('?' + q) : ('&' + q));
46 }
47
48, isLoopbackAddr: function (addr) {
49 return /^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(addr) || /^\[::1\]$/.test(addr);
50 }
51};
Note: See TracBrowser for help on using the repository browser.