Namespace: Urls:urlParameter

Urls:urlParameter

Source:

Methods

urlParameter(urlopt, parameteropt, nullable) → {null|true|String|Array|Object}

Searches for and returns parameters embedded in the provided url containing a query string (make sure all values are url encoded).

You may also just provide the query string.

Returns a single parameter's value if a parameter name is given, otherwise returns dictionary with all parameters as keys and the associated parameter value.

If a parameter has more than one value the values are returned as an array, whether being requested by name or in the dictionary containing all params.

If a parameter is set, but has no defined value (name present, but no = before next param) the value is returned as boolean true.

Parameters:
Name Type Attributes Default Description
url String | URL <optional>
null

the url containing the parameter string, will use current URL if nullish

parameter String <optional>
<nullable>
null

the name of the parameter to extract

Source:
See:
Throws:

error if given url is not usable

Returns:
null in case the parameter doesn't exist, true in case it exists but has no value, a string in case the parameter has one value, or an array of values, or a dictionary object of all available parameters with corresponding values
Type
null | true | String | Array | Object
Example
const hasKittens = urlParameter('//foobar.com/bar?has_kittens', 'has_kittens');
=> true
const hasDoggies = urlParameter('has_doggies=yes&has_doggies', 'has_doggies');
=> ['yes', true]
const allTheData = urlParameter('?foo=foo&bar=bar&bar=barbar&bar');
=> {foo : 'foo', bar : ['bar', 'barbar', true]}