parse-uri
Advanced tools
Comparing version
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://github.com/Kikobeats/parse-uri", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"main": "src/index.js", | ||
@@ -8,0 +8,0 @@ "author": { |
@@ -28,15 +28,38 @@ 'use strict' | ||
parser: { | ||
strict: /^(?:([^:/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:/?#]*)(?::(\d*))?))?((((?:[^?#/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, | ||
loose: /^(?:(?![^:@]+:[^:@/]*@)([^:/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#/]*\.[^?#/.]+(?:[?#]|$)))*\/?)?([^?#/]*))(?:\?([^#]*))?(?:#(.*))?)/ | ||
strict: | ||
/^(?:([^:/?#]+):)?(?:\/\/([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/, | ||
loose: | ||
/^(?:(?![^:@]+:[^:@/]*@)([^:/?#.]+):)?(?:\/\/)?([^/?#]*)([^?#]*)(?:\?([^#]*))?(?:#(.*))?/ | ||
} | ||
} | ||
const m = o.parser[opts.strictMode ? 'strict' : 'loose'].exec(str) | ||
const pattern = opts.strictMode ? o.parser.strict : o.parser.loose | ||
const matches = pattern.exec(str) | ||
if (!matches) return undefined | ||
const uri = {} | ||
let i = 14 | ||
uri[o.key[0]] = str | ||
uri[o.key[1]] = matches[1] || '' | ||
uri[o.key[2]] = matches[2] || '' | ||
uri[o.key[8]] = matches[3] || '' | ||
uri[o.key[12]] = matches[4] || '' | ||
uri[o.key[13]] = matches[5] || '' | ||
while (i--) uri[o.key[i]] = m[i] || '' | ||
// Further breakdown and parsing can be done here if needed | ||
// For example, splitting authority into userInfo, host, and port | ||
if (uri[o.key[2]]) { | ||
const authorityPattern = | ||
/^(?:(([^:@]*)(?::([^:@]*))?)?@)?([^:/?#]*)(?::(\d*))?/ | ||
const authorityMatches = authorityPattern.exec(uri[o.key[2]]) | ||
if (authorityMatches) { | ||
uri[o.key[3]] = authorityMatches[1] || '' | ||
uri[o.key[4]] = authorityMatches[2] || '' | ||
uri[o.key[5]] = authorityMatches[3] || '' | ||
uri[o.key[6]] = authorityMatches[4] || '' | ||
uri[o.key[7]] = authorityMatches[5] || '' | ||
} | ||
} | ||
uri[o.q.name] = {} | ||
uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) { | ||
uri[o.key[12]].replace(o.q.parser, function (_, $1, $2) { | ||
if ($1) uri[o.q.name][$1] = $2 | ||
@@ -43,0 +66,0 @@ }) |
6059
12.1%61
56.41%