mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
/* eslint no-useless-escape: 0*/
|
|
/* eslint prefer-const: 0*/
|
|
|
|
// parseUri 1.2.2
|
|
// (c) Steven Levithan <stevenlevithan.com>
|
|
// MIT License
|
|
|
|
function parseUri(str) {
|
|
let o = parseUri.options,
|
|
m = o.parser[o.strictMode ? 'strict' : 'loose'].exec(str),
|
|
uri = {},
|
|
i = 14;
|
|
|
|
while (i--) uri[o.key[i]] = m[i] || '';
|
|
|
|
uri[o.q.name] = {};
|
|
uri[o.key[12]].replace(o.q.parser, ($0, $1, $2) => {
|
|
if ($1) uri[o.q.name][$1] = $2;
|
|
});
|
|
|
|
return uri;
|
|
}
|
|
|
|
parseUri.options = {
|
|
strictMode: false,
|
|
key: ['source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'],
|
|
q: {
|
|
name: 'queryKey',
|
|
parser: /(?:^|&)([^&=]*)=?([^&]*)/g,
|
|
},
|
|
parser: {
|
|
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
|
|
loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,
|
|
},
|
|
};
|
|
|
|
module.exports = parseUri;
|