can-deparam
Deserialize a query string into an array or object.
deparam(params)
Parameters
- params
{String}
:a form-urlencoded string of key-value pairs
Returns
{Object}
:
The params formatted into an object
Takes a string of name value pairs and returns a Object literal that represents those params.
var deparam = require("can-deparam");
console.log(JSON.stringify(deparam("?foo=bar&number=1234"))); // -> '{"foo" : "bar", "number": 1234}'
console.log(JSON.stringify(deparam("#foo[]=bar&foo[]=baz"))); // -> '{"foo" : ["bar", "baz"]}'
console.log(JSON.stringify(deparam("foo=bar%20%26%20baz"))); // -> '{"foo" : "bar & baz"}'
Try it
Use this JS Bin to play around with this package: