-
-
Save bvisonl/add693105077e1de406cab47da5cd0f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parseUri(s) { | |
if(typeof s === 'object') | |
return s; | |
var re = /^\<?(sips?):(?:([^\s>:@]+)(?::([^\s@>]+))?@)?([\w\-\.]+)(?::(\d+))?((?:;[^\s=\?>;]+(?:=[^\s?\;]+)?)*)(?:\?(([^\s&=>]+=[^\s&=>]+)(&[^\s&=>]+=[^\s&=>]+)*))?$/; | |
var r = re.exec(s); | |
if(r) { | |
return { | |
schema: r[1], | |
user: r[2], | |
password: r[3], | |
host: r[4], | |
port: +r[5], | |
params: (r[6].match(/([^;=]+)(=([^;=]+))?/g) || []) | |
.map(function(s) { return s.split('='); }) | |
.reduce(function(params, x) { params[x[0]]=x[1] || null; return params;}, {}), | |
headers: ((r[7] || '').match(/[^&=]+=[^&=]+/g) || []) | |
.map(function(s){ return s.split('=') }) | |
.reduce(function(params, x) { params[x[0]]=x[1]; return params; }, {}) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment