jQuery.queryString

Parses querystrings. For example, the following querystring:

"name=John&address=1%202%20West%20St&phone=(123)%20123-1234"

can be transformed into a JavaScript object:

    {
        "name": "John",
        "address": "12 West St",
        "phone": "(123) 123-1234"
    }

This is the inverse of jQuery.param()

Usage

$.deparam(queryString)

Parse a querystring to a JavaScript object:

    var qs = $.deparam("icecream=vanilla&brownie=chocolate");
    qs.brownie === "chocolate";  // true

$.currentQueryString()

Get the querystring from the current document.location as a parsed object:

    // Current document.location: http://www.foo.com?icecream=vanilla&brownie=chocolate
    var qs = $.currentQueryString();
    qs.icecream === "vanilla"; // true

$.appendQueryString(url, parsedQueryString)

There’s also a method to append a parsed querystring to a URL:

    var url = $.appendQueryString("http://www.foo.com", { "icecream": "vanilla", "brownie": "chocolate"});
    url === "http://www.foo.com?icecream=vanilla&brownie=chocolate";  // true

Dependencies

This library uses jquery.delimitedString (part of skinny.js), which abstracts encoding/decoding of key-value pairs.