A javascript object that helps get, set, and remove parameters from a url
Dependens on Underscore.js http://underscorejs.org/
var urlQueryHelper = new UrlQueryHelper("http://www.example.com/?name=Todd&location=Beach&activity=Surfing");
urlQueryHelper.getParam("location") // returns "Beach"
urlQueryHelper.setParam("location", "city");
urlQueryHelper.getUrl() // returns "http://www.example.com/?name=Todd&location=city&activity=Surfing"
urlQueryHelper.setParams({"location": "home", "activity": "reading"});
urlQueryHelper.getUrl() // returns "http://www.example.com/?name=Todd&location=home&activity=reading"
urlQueryHelper.removeParam("location");
urlQueryHelper.getUrl() // returns "http://www.example.com/?name=Todd&activity=reading"
urlQueryHelper.removeParams("name", "activity", "location", "any", "number", "of", "things");
urlQueryHelper.getUrl() // returns "http://www.example.com/"
// You may also set new params inline
var urlQueryHelper = new UrlQueryHelper("http://www.example.com/?name=Todd", {name: "Ted", location: "beach"});
urlQueryHelper.getUrl() // returns "http://www.example.com/?name=Ted&location=beach"
Creates an instance of UrlQueryHelper
Parameters
url: string, The url that we will be parseing
updatedParams: object, An optional object of new or updated parameters that will modify the url
The initializing script that gets all of the params from the url query string
Parameters
url: string, The url that we will be parseing
updatedParams: object, An optional object of new or updated parameters that will modify the url
Builds and returns a url with the current params for this instance
Returns
string, The url
Returns the params object which shows the current state of params for this instance
Returns
object, All of the params for this helper
Return s a single param from this instance
Parameters
param: string, The name of the parameter to get
Returns
string, The value of the requested param
Update or add a param to this instance
Parameters
param: string, The name of the parameter to add
value: string, The desired value for the given parameter
Update or add multiple parameters at once
Parameters
paramsHash: object, An object with all of the paremters to update or add
Remove a parameter from this instance
Parameters
param: string, the name of the parameter to remove
Remove a list of paremters from this instance
Parameters
Arguments: ...string, as a list of param names to remove from this instance
Create a String representation of the UrlQueryHelper
Returns
string, Human-readable representation of UrlQuerHelper