tiny-parse
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -16,6 +16,6 @@ "use strict"; | ||
function queryString (arg = "") { | ||
const obj = {}, | ||
result = (arg.split("?")[1] || "").split("&"); | ||
const result = {}, | ||
items = arg.replace(/^\?/, "").split("&"); | ||
each(result, prop => { | ||
each(items, prop => { | ||
const aitem = prop.replace(/\+/g, " ").split("="), | ||
@@ -31,9 +31,9 @@ item = aitem.length > 2 ? [aitem.shift(), aitem.join("=")] : aitem; | ||
if (obj[item[0]] === undefined) { | ||
obj[item[0]] = item[1]; | ||
} else if (obj[item[0]] instanceof Array === false) { | ||
obj[item[0]] = [obj[item[0]]]; | ||
obj[item[0]].push(item[1]); | ||
if (result[item[0]] === undefined) { | ||
result[item[0]] = item[1]; | ||
} else if (result[item[0]] instanceof Array === false) { | ||
result[item[0]] = [result[item[0]]]; | ||
result[item[0]].push(item[1]); | ||
} else { | ||
obj[item[0]].push(item[1]); | ||
result[item[0]].push(item[1]); | ||
} | ||
@@ -43,3 +43,3 @@ } | ||
return obj; | ||
return result; | ||
} | ||
@@ -66,3 +66,3 @@ | ||
parsed.path = parsed.pathname + (parsed.search || ""); | ||
parsed.query = parsed.search ? queryString(parsed.search) : {}; | ||
parsed.query = parsed.search !== "" ? queryString(parsed.search) : {}; | ||
@@ -69,0 +69,0 @@ return parsed; |
{ | ||
"name": "tiny-parse", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "URL parsing with coercion of `query`", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
4492