1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-09 08:45:55 +02:00
joplin/packages/lib/parseUri.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-10-09 21:35:13 +02:00
/* eslint no-useless-escape: 0*/
/* eslint prefer-const: 0*/
2017-11-28 23:49:58 +02:00
// parseUri 1.2.2
// (c) Steven Levithan <stevenlevithan.com>
// MIT License
2019-07-29 15:43:53 +02:00
function parseUri(str) {
let o = parseUri.options,
2019-07-29 15:43:53 +02:00
m = o.parser[o.strictMode ? 'strict' : 'loose'].exec(str),
2017-11-28 23:49:58 +02:00
uri = {},
2019-07-29 15:43:53 +02:00
i = 14;
2017-11-28 23:49:58 +02:00
2019-07-29 15:43:53 +02:00
while (i--) uri[o.key[i]] = m[i] || '';
2017-11-28 23:49:58 +02:00
uri[o.q.name] = {};
2019-07-29 15:43:53 +02:00
uri[o.key[12]].replace(o.q.parser, function($0, $1, $2) {
2017-11-28 23:49:58 +02:00
if ($1) uri[o.q.name][$1] = $2;
});
return uri;
2019-07-29 15:43:53 +02:00
}
2017-11-28 23:49:58 +02:00
parseUri.options = {
strictMode: false,
2019-07-29 15:43:53 +02:00
key: ['source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'],
q: {
name: 'queryKey',
parser: /(?:^|&)([^&=]*)=?([^&]*)/g,
2017-11-28 23:49:58 +02:00
},
parser: {
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
2019-07-29 15:43:53 +02:00
loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,
},
2017-11-28 23:49:58 +02:00
};
2019-07-29 15:43:53 +02:00
module.exports = parseUri;