forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathURIjs-tests.ts
93 lines (76 loc) · 2.4 KB
/
URIjs-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/// <reference path="URIjs.d.ts" />
URI();
URI('http://user:[email protected]:80/foo/bar.html?foo=bar&bar=baz#frag');
URI({
protocol: 'http',
username: 'user',
password: 'pass',
hostname: 'example.org',
port: '80',
path: '/foo/bar.html',
query: 'foo=bar&bar=baz',
fragment: 'frag'
});
URI(document.createElement('a'));
new URI();
new URI('http://user:[email protected]:80/foo/bar.html?foo=bar&bar=baz#frag');
new URI({
protocol: 'http',
username: 'user',
password: 'pass',
hostname: 'example.org',
port: '80',
path: '/foo/bar.html',
query: 'foo=bar&bar=baz',
fragment: 'frag'
});
new URI(document.createElement('a'));
URI('').setQuery('foo', 'bar');
URI('').setQuery({ foo: 'bar' });
URI('').setSearch('foo', 'bar');
URI('').setSearch({ foo: 'bar' });
var uri: uri.URI = $('a').uri();
URI('http://example.org/foo/hello.html').segment('bar');
URI('http://example.org/foo/hello.html').segment(0, 'bar');
URI('http://example.org/foo/hello.html').segment(['foo', 'bar', 'foobar.html']);
var withDuplicates = URI("?bar=1&bar=1")
.duplicateQueryParameters(true)
.normalizeQuery()
.toString();
/*
To enable `URI.expand` when using `URI.js` via `npm`, include the following:
```
import * as URI from "urijs";
import * as URITemplate from "urijs/src/URITemplate";
void URITemplate;
```
*/
URI('http://user:[email protected]:80/foo/bar.html?foo=bar&bar=baz#frag').equals(
URI.expand('http://user:[email protected]:80{/p*}{?q*}{#h}', {
p: ["foo", "bar.html"],
q: {foo: "bar", bar: "baz"},
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;