1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-06 22:46:29 +02:00

35 lines
1.0 KiB
JavaScript
Raw Normal View History

2017-11-28 21:49:58 +00:00
// parseUri 1.2.2
// (c) Steven Levithan <stevenlevithan.com>
// MIT License
2018-03-09 17:49:35 +00:00
function parseUri(str) {
var o = parseUri.options,
m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
2017-11-28 21:49:58 +00:00
uri = {},
2018-03-09 17:49:35 +00:00
i = 14;
2017-11-28 21:49:58 +00:00
while (i--) uri[o.key[i]] = m[i] || "";
uri[o.q.name] = {};
2018-03-09 17:49:35 +00:00
uri[o.key[12]].replace(o.q.parser, function($0, $1, $2) {
2017-11-28 21:49:58 +00:00
if ($1) uri[o.q.name][$1] = $2;
});
return uri;
2018-03-09 17:49:35 +00:00
}
2017-11-28 21:49:58 +00:00
parseUri.options = {
strictMode: false,
2018-03-09 17:49:35 +00:00
key: ["source", "protocol", "authority", "userInfo", "user", "password", "host", "port", "relative", "path", "directory", "file", "query", "anchor"],
q: {
name: "queryKey",
parser: /(?:^|&)([^&=]*)=?([^&]*)/g,
2017-11-28 21:49:58 +00:00
},
parser: {
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
2018-03-09 17:49:35 +00:00
loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,
},
2017-11-28 21:49:58 +00:00
};
2018-03-09 17:49:35 +00:00
module.exports = parseUri;