Module: common/query

Methods

(static) fromObject(o) → {string}

fromObject takes an object and encodes it into a query string. The reverse of this function is toObject.
Parameters:
Name Type Description
o Object The object to encode.
Source:
Returns:
Type
string

(static) fromParamSet(o) → {string}

fromParamSet encodes an object of the form:
{
  a:["2", "4"],
  b:["3"]
}
to a query string like:
"a=2&a=4&b=3"
This function handles URI encoding of both keys and values.
Parameters:
Name Type Description
o Object The object to encode.
Source:
Returns:
Type
string

(static) splitAmp(queryStropt, separatoropt) → {string}

splitAmp returns the given query string as a newline separated list of key value pairs. If sepator is not provided newline will be used.
Parameters:
Name Type Attributes Default Description
queryStr string <optional>
'' A query string.
separator string <optional>
'\n' The separator to use when joining.
Source:
Returns:
Type
string

(static) toObject(s, target) → {Object}

toObject decodes a query string into an object. Uses the 'target' as a source for hinting on the types of the values. For example:
  "a=2&b=true"
decodes to:
  {
    a: 2,
    b: true,
  }
When given a target of:
  {
    a: 1.0,
    b: false,
  }
Note that a target of {} would decode the same query string into:
  {
    a: "2",
    b: "true",
  }
Only Number, String, Boolean, Object, and Array of String hints are supported.
Parameters:
Name Type Description
s string The query string.
target Object The object that contains the type hints.
Source:
Returns:
Type
Object

(static) toParamSet(s) → {Object}

toParamSet parses a query string into an object with arrays of values for the values. I.e.
  "a=2&b=3&a=4"
decodes to
  {
    a:["2", "4"],
    b:["3"],
  }
This function handles URI decoding of both keys and values.
Parameters:
Name Type Description
s string The query string to decode.
Source:
Returns:
Type
Object