socketioMEANseed/www/node_modules/url-join/lib/url-join.js
www/node_modules/url-join/lib/url-join.jsRaw
1(function (name, context, definition) {
2 if (typeof module !== 'undefined' && module.exports) module.exports = definition();
3 else if (typeof define === 'function' && define.amd) define(definition);
4 else context[name] = definition();
5})('urljoin', this, function () {
6
7 function normalize (str, options) {
8
9 // make sure protocol is followed by two slashes
10 str = str.replace(/:\//g, '://');
11
12 // remove consecutive slashes
13 str = str.replace(/([^:\s])\/+/g, '$1/');
14
15 // remove trailing slash before parameters or hash
16 str = str.replace(/\/(\?|&|#[^!])/g, '$1');
17
18 // replace ? in parameters with &
19 str = str.replace(/(\?.+)\?/g, '$1&');
20
21 return str;
22 }
23
24 return function () {
25 var input = arguments;
26 var options = {};
27
28 if (typeof arguments[0] === 'object') {
29 // new syntax with array and options
30 input = arguments[0];
31 options = arguments[1] || {};
32 }
33
34 var joined = [].slice.call(input, 0).join('/');
35 return normalize(joined, options);
36 };
37
38});