Skip to content

Commit f53bb14

Browse files
committed
Add definitions for hasSearch()/hasQuery();
1 parent a44529f commit f53bb14

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

urijs/URIjs-tests.ts

+31
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,34 @@ URI('http://user:[email protected]:80/foo/bar.html?foo=bar&bar=baz#frag').equals(
6060
h: "frag"
6161
})
6262
);
63+
64+
/*
65+
Tests for hasSearch(), hasQuery()
66+
From: http://medialize.github.io/URI.js/docs.html#search-has
67+
*/
68+
69+
uri = URI("?string=bar&list=one&list=two&number=123&null&empty=");
70+
71+
uri.hasQuery("string") === true;
72+
uri.hasSearch("nono") === false;
73+
74+
uri.hasQuery("string", true) === true;
75+
uri.hasSearch("string", false) === false;
76+
77+
uri.hasQuery("string", "bar") === true;
78+
uri.hasSearch("number", 123) === true;
79+
80+
uri.hasQuery("list", "two", true) === true;
81+
uri.hasSearch("list", ["two"], true) === true;
82+
uri.hasQuery("list", "three", true) === false;
83+
uri.hasSearch("list", ["two", "three"], true) === false;
84+
uri.hasQuery("list", /ne$/, true) === true;
85+
86+
uri.hasQuery("string", /ar$/) === true;
87+
88+
uri.hasQuery(/^str/) === true;
89+
uri.hasQuery(/^li/, "two") === true;
90+
91+
uri.hasQuery("string", (value : string, name : string, data : string) => {
92+
return true;
93+
}) === true;

urijs/URIjs.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ declare namespace uri {
105105
setQuery(qry: Object): URI;
106106
setSearch(key: string, value: string): URI;
107107
setSearch(qry: Object): URI;
108+
hasQuery(name: string | any, value?: string | number | boolean | Function | Array<string> | Array<number> | Array<boolean> | RegExp, withinArray?: boolean): boolean;
109+
hasSearch(name: string | any, value?: string | number | boolean | Function | Array<string> | Array<number> | Array<boolean> | RegExp, withinArray?: boolean): boolean;
108110
subdomain(): string;
109111
subdomain(subdomain: string): URI;
110112
suffix(): string;

0 commit comments

Comments
 (0)