gPass/chrome_addon/lib/parseuri.js

31 lines
1.0 KiB
JavaScript
Raw Normal View History

2015-01-27 21:10:55 +01:00
// parseUri 1.2.2
// (c) Steven Levithan <stevenlevithan.com>
// MIT License
2022-09-26 20:30:40 +02:00
export function parseUri (str) {
var o = {
2015-01-27 21:10:55 +01:00
strictMode: false,
key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
q: {
2022-09-26 20:30:40 +02:00
name: "queryKey",
parser: /(?:^|&)([^&=]*)=?([^&]*)/g
2015-01-27 21:10:55 +01:00
},
parser: {
2022-09-26 20:30:40 +02:00
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
2015-01-27 21:10:55 +01:00
}},
2022-09-26 20:30:40 +02:00
m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
uri = {},
i = 14;
while (i--) uri[o.key[i]] = m[i] || "";
2015-01-27 21:10:55 +01:00
2022-09-26 20:30:40 +02:00
uri[o.q.name] = {};
uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
if ($1) uri[o.q.name][$1] = $2;
});
2015-01-27 21:10:55 +01:00
2022-09-26 20:30:40 +02:00
return uri;
}
2015-01-27 21:10:55 +01:00