parseUri.js 1022 B

1234567891011121314151617181920212223242526272829303132
  1. // parseUri 1.2.2
  2. // (c) Steven Levithan <stevenlevithan.com>
  3. // MIT License
  4. function parseUri (str) {
  5. var o = parseUri.options,
  6. m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
  7. uri = {},
  8. i = 14;
  9. while (i--) uri[o.key[i]] = m[i] || "";
  10. uri[o.q.name] = {};
  11. uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
  12. if ($1) uri[o.q.name][$1] = $2;
  13. });
  14. return uri;
  15. };
  16. parseUri.options = {
  17. strictMode: false,
  18. key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
  19. q: {
  20. name: "queryKey",
  21. parser: /(?:^|&)([^&=]*)=?([^&]*)/g
  22. },
  23. parser: {
  24. strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
  25. loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
  26. }
  27. };