4 * @author Steven Levithan <stevenlevithan.com> (MIT license)
8 var re = /^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
11 'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'
14 module.exports = function parseuri(str) {
19 if (b != -1 && e != -1) {
20 str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length);
23 var m = re.exec(str || ''),
28 uri[parts[i]] = m[i] || '';
31 if (b != -1 && e != -1) {
33 uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':');
34 uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':');
38 uri.pathNames = pathNames(uri, uri['path']);
39 uri.queryKey = queryKey(uri, uri['query']);
44 function pathNames(obj, path) {
45 var regx = /\/{2,9}/g,
46 names = path.replace(regx, "/").split("/");
48 if (path.substr(0, 1) == '/' || path.length === 0) {
51 if (path.substr(path.length - 1, 1) == '/') {
52 names.splice(names.length - 1, 1);
58 function queryKey(uri, query) {
61 query.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function ($0, $1, $2) {