Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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; }, {})
- }
- }
- }
Add Comment
Please, Sign In to add comment