Guest User

Untitled

a guest
May 20th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. function parseUri(s) {
  2. if(typeof s === 'object')
  3. return s;
  4.  
  5. var re = /^(sips?):(?:([^\s>:@]+)(?::([^\s@>]+))?@)?([\w\-\.]+)(?::(\d+))?((?:;[^\s=\?>;]+(?:=[^\s?\;]+)?)*)(?:\?(([^\s&=>]+=[^\s&=>]+)(&[^\s&=>]+=[^\s&=>]+)*))?$/;
  6.  
  7. var r = re.exec(s);
  8.  
  9. if(r) {
  10. return {
  11. schema: r[1],
  12. user: r[2],
  13. password: r[3],
  14. host: r[4],
  15. port: +r[5],
  16. params: (r[6].match(/([^;=]+)(=([^;=]+))?/g) || [])
  17. .map(function(s) { return s.split('='); })
  18. .reduce(function(params, x) { params[x[0]]=x[1] || null; return params;}, {}),
  19. headers: ((r[7] || '').match(/[^&=]+=[^&=]+/g) || [])
  20. .map(function(s){ return s.split('=') })
  21. .reduce(function(params, x) { params[x[0]]=x[1]; return params; }, {})
  22. }
  23. }
  24. }
Add Comment
Please, Sign In to add comment