From f53bb14ade77cbce5c8860c0efbcfef11221ab7c Mon Sep 17 00:00:00 2001 From: Matthieu Maitre Date: Fri, 25 Mar 2016 23:50:22 -0700 Subject: [PATCH] Add definitions for hasSearch()/hasQuery(); --- urijs/URIjs-tests.ts | 31 +++++++++++++++++++++++++++++++ urijs/URIjs.d.ts | 2 ++ 2 files changed, 33 insertions(+) diff --git a/urijs/URIjs-tests.ts b/urijs/URIjs-tests.ts index 2e1e1eacd4..502fb0e5e2 100644 --- a/urijs/URIjs-tests.ts +++ b/urijs/URIjs-tests.ts @@ -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; diff --git a/urijs/URIjs.d.ts b/urijs/URIjs.d.ts index 4ab2ea9f9d..c7a2630370 100644 --- a/urijs/URIjs.d.ts +++ b/urijs/URIjs.d.ts @@ -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 | Array | Array | RegExp, withinArray?: boolean): boolean; + hasSearch(name: string | any, value?: string | number | boolean | Function | Array | Array | Array | RegExp, withinArray?: boolean): boolean; subdomain(): string; subdomain(subdomain: string): URI; suffix(): string;