add method for case-insensitive query parameter existence check
While according to RFC spec, query params are case-sensitive, there should be a method allowing for case-insensitive search for query params when just checking for existence.
var uri = "http://www.acme.com?test=1"
uri.hasQuery("TEST"); //returns false
New function signature would look like this:
URI.hasQueryParameter = function (data, name, caseSensitive) {
//force undefined params
var param3, param4;
return URI.hasQuery(data, name, param3, param4, caseSensitive);
}
...with new param to main hasQuery method:
URI.hasQuery = function (data, name, value, withinArray, caseSensitive) {
// SNIP...
switch (getType(value)) {
case 'Undefined':
// true if exists (but may be empty)
return !caseSensitive ? name in data : return data[name] !== undefined;
// SNIP...
}
uri.hasQueryParameter("TEST", false); //returns true
uri.hasQueryParameter("TEST", true); //returns false
This approach maintains backwards compatibility without ugly calls from client script.
Thank you for your feedback! I have yet to see a system that treats query data case-insensitive. I'll leave this to the community to decide…
Not a problem with the data... the key is the problem. I can see the key often being case-insensitive in many systems
Realized I can use RegExp in the latest URI.js for hasQuery and removeQuery... I can pass a regex like /TEST/i to get what I want.
In the version we were on, RegEx option did not yet exist for the name property (only the value). That works for hasQuery and removeQuery... doesn't really work for getting the value of the param though.