You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
690 B

  1. /**
  2. * Parses an URI
  3. *
  4. * @author Steven Levithan <stevenlevithan.com> (MIT license)
  5. * @api private
  6. */
  7. var re = /^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
  8. var parts = [
  9. 'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host'
  10. , 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'
  11. ];
  12. module.exports = function parseuri(str) {
  13. var m = re.exec(str || '')
  14. , uri = {}
  15. , i = 14;
  16. while (i--) {
  17. uri[parts[i]] = m[i] || '';
  18. }
  19. return uri;
  20. };