arnaucube
arnaucube/socketioMEANseedPublic Self-hosted repository
socketioMEANseed/server/node_modules/parseuri/index.js
server/node_modules/parseuri/index.jsRaw
 1/**
 2 * Parses an URI
 3 *
 4 * @author Steven Levithan <stevenlevithan.com> (MIT license)
 5 * @api private
 6 */
 7
 8var re = /^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
 9
10var parts = [
11    'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'
12];
13
14module.exports = function parseuri(str) {
15    var src = str,
16        b = str.indexOf('['),
17        e = str.indexOf(']');
18
19    if (b != -1 && e != -1) {
20        str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length);
21    }
22
23    var m = re.exec(str || ''),
24        uri = {},
25        i = 14;
26
27    while (i--) {
28        uri[parts[i]] = m[i] || '';
29    }
30
31    if (b != -1 && e != -1) {
32        uri.source = src;
33        uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':');
34        uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':');
35        uri.ipv6uri = true;
36    }
37
38    return uri;
39};