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 |
Throws:
error if given url is not usable
Returns:
- 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]}