document querystring apis
This commit is contained in:
parent
66aa9ce818
commit
6514a38162
6 changed files with 107 additions and 10 deletions
|
|
@ -10,10 +10,7 @@ module.exports = function(string) {
|
|||
var key = decodeURIComponent(entry[0])
|
||||
var value = entry.length === 2 ? decodeURIComponent(entry[1]) : ""
|
||||
|
||||
//TODO refactor out
|
||||
var number = Number(value)
|
||||
if (value !== "" && !isNaN(number) || value === "NaN") value = number
|
||||
else if (value === "true") value = true
|
||||
if (value === "true") value = true
|
||||
else if (value === "false") value = false
|
||||
|
||||
var levels = key.split(/\]\[?|\[/)
|
||||
|
|
|
|||
|
|
@ -72,13 +72,13 @@ o.spec("parseQueryString", function() {
|
|||
var data = parseQueryString("a=true&b=false")
|
||||
o(data).deepEquals({a: true, b: false})
|
||||
})
|
||||
o("casts numbers", function() {
|
||||
o("does not cast numbers", function() {
|
||||
var data = parseQueryString("a=1&b=-2.3&c=0x10&d=1e2&e=Infinity")
|
||||
o(data).deepEquals({a: 1, b: -2.3, c: 16, d: 100, e: Infinity})
|
||||
o(data).deepEquals({a: "1", b: "-2.3", c: "16", d: "1e2", e: "Infinity"})
|
||||
})
|
||||
o("casts NaN", function() {
|
||||
o("does not cast NaN", function() {
|
||||
var data = parseQueryString("a=NaN")
|
||||
o(isNaN(data.a)).equals(true)
|
||||
o(data.a).equals("NaN")
|
||||
})
|
||||
o("does not casts Date", function() {
|
||||
var data = parseQueryString("a=1970-01-01")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue