Skip to content

Latest commit

 

History

History
51 lines (28 loc) · 1.38 KB

README.md

File metadata and controls

51 lines (28 loc) · 1.38 KB

querystring.node.js

This node module provides robust querystring parsing and stringifying. It is based heavily on the YUI QueryString module located here.

Acknowledgements

Thanks to Isaac Schlueter for pointing me to the YUI code and allowing me to tweak it for node.js.

querystring.js

Exports the parse and stringify methods from the querystring-parse and querystring-stringify sub-modules, repsectively.

parse example

var sys = require("util");
var qs = require("./querystring");

var str = qs.parse("foo=bar&baz=qux");
sys.puts(JSON.stringify(str)); // => {"foo":"bar","baz":"qux"}

str = qs.parse("foo[bar][][bla]=baz");
sys.puts(JSON.stringify(str)); // => {"foo":{"bar":[{"bla":"baz"}]}}

stringify example

var sys = require("util");
var qs = require("./querystring");

var obj = {"foo":"bar","baz":"qux"};
sys.puts(qs.stringify(obj)); // => foo=bar&baz=qux

obj = {"foo":{"bar":[{"bla":"baz"}]}};
sys.puts(qs.stringify(obj)); // => foo%5Bbar%5D%5B%5D%5Bbla%5D=baz

querystring-parse.js

Provides a parse function which takes a string and returns a javascript object

querystring-stringify.js

Provides a stringify function which takes a javascript object and returns a query string

Other

See test.js for a few more examples.