Class

base/QueryString

base/QueryString(urlopt)

Constructor

# new base/QueryString(urlopt)

Utility class on the query strings of current URL.

Parameters:
Name Type Attributes Default Description
url String <optional>
window.location.href

The url used to parse the query string. Query string with leading "?" sign are also accepted.

Example
var queryString = new QueryString("http://127.0.0.1/queryStringExample?a=1");
var anotherQueryString = new QueryString("?a=1");

Methods

# getQueryString(optionsopt) → {String}

Retrieves the query string, where the result is processed by the options. The result can be altered to exclude some parameters, and/or be overrided. Whenever they have conflict, exclusion dominates overriding. Note:

  • the sequence of the parameters may not be preserved
  • the query string is not url encoded, if the input was not
Parameters:
Name Type Attributes Description
options Object <optional>

An option object

exclude Object <optional>

An array that specified a list of parameters to exclude from the result

extendFrom Object <optional>

An object that extends the final result should extend from. Eventally this will overrides some parameters.

The constructed query string without the leading "?" sign

String
Example
var queryString = new QueryString("http://127.0.0.1/queryStringExample?a=1&b=2");

queryString.getQueryString(); // "a=1&b=2"
// exclude __a__
queryString.getQueryString({"exclude": ["a"]}); // "b=2"
// override __a__
queryString.getQueryString({"extendFrom": {"a": "lower_a"}}); // "a=lower_a&b=2"
// exclude __a__ & override __c__
queryString.getQueryString({"exclude": ["a"], "extendFrom": {"c": "lower_c"}}); // "b=2&c=lower_c"

# getValue(key) → {String}

Retrieves the value of a parameter in the query string using a specified key.

Parameters:
Name Type Description
key String

The key of the parameter to ask for

Mapped value of the key, or null if none exists

String
Example
var queryString = new QueryString("http://127.0.0.1/queryStringExample?a=1&b=2");

queryString.getValue("a"); // "1"
queryString.getValue("c"); // null

# toObject() → {Object}

Extracts the parameters from this query string to a key-value paired object.

An string-string key-value paired object

Object
Example
var queryString = new QueryString("http://127.0.0.1/queryStringExample?a=1&b=2");

queryString.toObject(); // {"a": "1", "b": "2"}

# static parse(queryString) → {Object}

Extracts the parameters from the specified query string to a key-value paired object.

Parameters:
Name Type Description
queryString String

The query string to be processed

An string-string key-value paired object

Object
Example
var queryString = new QueryString("http://127.0.0.1/queryStringExample?a=1&b=2"),
    strQueryString = queryString.getQueryString(); // "a=1&b=2"

QueryString.parse(strQueryString); // {"a": "1", "b": "2"}