urlq
A lightweight library to get/set url query string values.
Usage
const urlq = ;const q1 = '?sections=carbs,dessert&diets=gluten-free'; urlq 'carbs' 'dessert' urlq 'gluten-free' urlq var q2 = urlq;q2; '?sections=carbs,dessert,soups&diets=gluten-free' urlq;urlq; 'carbs' 'dessert' 'soups' var q3 = urlq;urlq;q3; '?diets=vegetarian,pescepescetarian'
Functions
- addVal(q, p, v) ⇒
String
Returns a new query string with values added to a query parameter.
- getParam(q, p) ⇒
Array
Returns an array of values for a query parameter.
- makeValidQuery(q) ⇒
String
Returns a valid formatted url query string
- removeVal(q, p, v) ⇒
String
Returns a new query string with a value removed from a parameter.
- removeParam(q, p) ⇒
String
Returns a new query string with a parameter removed.
- updateParam(q, p, vs) ⇒
String
Returns a new query string with updated values from a parameter. If newVals.length = 0 the parameter is removed.
- updateQuery(q)
Updates the browser history with a new query string.
String
addVal(q, p, v) ⇒ Returns a new query string with values added to a query parameter.
Kind: global function
Param | Type | Description |
---|---|---|
q | String |
The query string. |
p | String |
The query parameter to update. |
v | * |
The value to add. |
Array
getParam(q, p) ⇒ Returns an array of values for a query parameter.
Kind: global function
Param | Type | Description |
---|---|---|
q | String |
The query string. |
p | String |
The query parameter. |
String
makeValidQuery(q) ⇒ Returns a valid formatted url query string
Kind: global function
Param | Type | Description |
---|---|---|
q | String |
The query string to format. |
String
removeVal(q, p, v) ⇒ Returns a new query string with a value removed from a parameter.
Kind: global function
Param | Type | Description |
---|---|---|
q | String |
The query string to update. |
p | String |
The parameter to remove the value. |
v | String |
The value to remove from a parameter. |
String
removeParam(q, p) ⇒ Returns a new query string with a parameter removed.
Kind: global function
Param | Type | Description |
---|---|---|
q | String |
The query string to update. |
p | String |
The parameter to remove. |
String
updateParam(q, p, vs) ⇒ Returns a new query string with updated values from a parameter. If newVals.length = 0 the parameter is removed.
Kind: global function
Param | Type | Description |
---|---|---|
q | String |
The query string to update. |
p | String |
The param to update. |
vs | Array |
The new values for the param. |
updateQuery(q)
Updates the browser history with a new query string.
Kind: global function
Param | Type | Description |
---|---|---|
q | String |
The new query string. |
Test
npm test