Add definitions for hasSearch()/hasQuery();

This commit is contained in:
Matthieu Maitre
2016-03-25 23:50:22 -07:00
parent a44529fcb1
commit f53bb14ade
2 changed files with 33 additions and 0 deletions

View File

@@ -60,3 +60,34 @@ URI('http://user:pass@example.org:80/foo/bar.html?foo=bar&bar=baz#frag').equals(
h: "frag"
})
);
/*
Tests for hasSearch(), hasQuery()
From: http://medialize.github.io/URI.js/docs.html#search-has
*/
uri = URI("?string=bar&list=one&list=two&number=123&null&empty=");
uri.hasQuery("string") === true;
uri.hasSearch("nono") === false;
uri.hasQuery("string", true) === true;
uri.hasSearch("string", false) === false;
uri.hasQuery("string", "bar") === true;
uri.hasSearch("number", 123) === true;
uri.hasQuery("list", "two", true) === true;
uri.hasSearch("list", ["two"], true) === true;
uri.hasQuery("list", "three", true) === false;
uri.hasSearch("list", ["two", "three"], true) === false;
uri.hasQuery("list", /ne$/, true) === true;
uri.hasQuery("string", /ar$/) === true;
uri.hasQuery(/^str/) === true;
uri.hasQuery(/^li/, "two") === true;
uri.hasQuery("string", (value : string, name : string, data : string) => {
return true;
}) === true;

2
urijs/URIjs.d.ts vendored
View File

@@ -105,6 +105,8 @@ declare namespace uri {
setQuery(qry: Object): URI;
setSearch(key: string, value: string): URI;
setSearch(qry: Object): URI;
hasQuery(name: string | any, value?: string | number | boolean | Function | Array<string> | Array<number> | Array<boolean> | RegExp, withinArray?: boolean): boolean;
hasSearch(name: string | any, value?: string | number | boolean | Function | Array<string> | Array<number> | Array<boolean> | RegExp, withinArray?: boolean): boolean;
subdomain(): string;
subdomain(subdomain: string): URI;
suffix(): string;