We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
It would be nice to have a very simple helper to check for existing/matching query parameters, except I missed something in the code :-D
My approach for now, I was not sure if it makes sense to implement the same argument structure as in add/remove Query.
@@ -551,6 +551,24 @@ URI.removeQuery = function(data, name, value) { throw new TypeError("URI.addQuery() accepts an object, string as the first parameter"); } }; +URI.hasQuery = function(data, name, value) { + var i, length, key; + + if (!typeof name == "string") { + throw new TypeError("URI.hasQuery accepts a string as first parameter"); + } + + if (typeof name == "string") { + if (value !== undefined && data[name] === value) { + return true + } else if (value === undefined && name in data) { + return true + } + } + + return false; +}; + URI.commonPath = function(one, two) { var length = Math.min(one.length, two.length); @@ -1293,9 +1311,14 @@ p.removeQuery = function(name, value, build) { this.build(!build); return this; }; +p.hasQuery = function(name, value, build) { + var data = URI.parseQuery(this._parts.query); + return URI.hasQuery(data, name, value); +}; p.setSearch = p.setQuery; p.addSearch = p.addQuery; p.removeSearch = p.removeQuery; +p.hasSearch = p.hasQuery; // sanitizing URLs p.normalize = function() {
The text was updated successfully, but these errors were encountered:
Your value test doesn't quite cut it yet:
value
?foo=1&foo=2
{foo: ["1", "2"]}
["a"] !== ["a"]
URI("?foo=1").hasQuery("foo", 1) === false
value should probably also be treated as a callback function to allow custom comparison.
Sorry, something went wrong.
Ah, okay. Thanks @rodneyrehm for the review, I'll change that.
cc18c99
No branches or pull requests
It would be nice to have a very simple helper to check for existing/matching query parameters, except I missed something in the code :-D
My approach for now, I was not sure if it makes sense to implement the same argument structure as in add/remove Query.
The text was updated successfully, but these errors were encountered: