kea-rails 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kea-rails/version.rb +1 -1
- data/vendor/assets/components/Keypress/LICENSE +191 -0
- data/vendor/assets/components/Keypress/README.md +78 -0
- data/vendor/assets/components/Keypress/bower.json +28 -0
- data/vendor/assets/components/Keypress/keypress-2.1.0.min.js +33 -0
- data/vendor/assets/components/Keypress/keypress.coffee +921 -0
- data/vendor/assets/components/Keypress/keypress.js +1132 -0
- data/vendor/assets/components/Keypress/package.json +15 -0
- data/vendor/assets/components/attachejs/attache-jquery.js +47 -0
- data/vendor/assets/components/attachejs/attache-knockout.js +56 -0
- data/vendor/assets/components/attachejs/attache.css +10 -0
- data/vendor/assets/components/attachejs/attache.js +589 -0
- data/vendor/assets/components/attachejs/bower.json +36 -0
- data/vendor/assets/components/humane-js/bower.json +8 -0
- data/vendor/assets/components/humane-js/changelog.md +165 -0
- data/vendor/assets/components/humane-js/humane.js +238 -0
- data/vendor/assets/components/humane-js/humane.min.js +11 -0
- data/vendor/assets/components/humane-js/index.html +190 -0
- data/vendor/assets/components/humane-js/package.json +25 -0
- data/vendor/assets/components/humane-js/readme.md +85 -0
- data/vendor/assets/components/humane-js/test/issue23.html +11 -0
- data/vendor/assets/components/humane-js/test/issue36.html +9 -0
- data/vendor/assets/components/humane-js/test/issue38.html +15 -0
- data/vendor/assets/components/humane-js/test/issue49.html +9 -0
- data/vendor/assets/components/humane-js/theme-src/bigbox.styl +65 -0
- data/vendor/assets/components/humane-js/theme-src/boldlight.styl +64 -0
- data/vendor/assets/components/humane-js/theme-src/jackedup.styl +69 -0
- data/vendor/assets/components/humane-js/theme-src/libnotify.styl +61 -0
- data/vendor/assets/components/humane-js/theme-src/original.styl +51 -0
- data/vendor/assets/components/humane-js/themes/bigbox.css +123 -0
- data/vendor/assets/components/humane-js/themes/boldlight.css +122 -0
- data/vendor/assets/components/humane-js/themes/flatty.css +94 -0
- data/vendor/assets/components/humane-js/themes/jackedup.css +123 -0
- data/vendor/assets/components/humane-js/themes/libnotify.css +115 -0
- data/vendor/assets/components/humane-js/themes/original.css +72 -0
- data/vendor/assets/components/knockout-sortable/README.md +129 -0
- data/vendor/assets/components/knockout-sortable/bower.json +15 -0
- data/vendor/assets/components/knockout-sortable/build/knockout-sortable.js +358 -0
- data/vendor/assets/components/knockout-sortable/build/knockout-sortable.min.js +2 -0
- data/vendor/assets/components/uri.js/README.md +437 -0
- data/vendor/assets/components/uri.js/URI.jquery.json +38 -0
- data/vendor/assets/components/uri.js/about-uris.html +156 -0
- data/vendor/assets/components/uri.js/build.html +66 -0
- data/vendor/assets/components/uri.js/build.js +78 -0
- data/vendor/assets/components/uri.js/component.json +15 -0
- data/vendor/assets/components/uri.js/contribute.md +11 -0
- data/vendor/assets/components/uri.js/docs.html +1280 -0
- data/vendor/assets/components/uri.js/index.html +173 -0
- data/vendor/assets/components/uri.js/jquery-1.10.2.min.js +6 -0
- data/vendor/assets/components/uri.js/jquery-1.7.2.min.js +4 -0
- data/vendor/assets/components/uri.js/jquery-1.8.2.min.js +2 -0
- data/vendor/assets/components/uri.js/jquery-1.9.1.min.js +5 -0
- data/vendor/assets/components/uri.js/jquery-uri-plugin.html +203 -0
- data/vendor/assets/components/uri.js/package.json +75 -0
- data/vendor/assets/components/uri.js/prettify/lang-apollo.js +2 -0
- data/vendor/assets/components/uri.js/prettify/lang-clj.js +18 -0
- data/vendor/assets/components/uri.js/prettify/lang-css.js +2 -0
- data/vendor/assets/components/uri.js/prettify/lang-go.js +1 -0
- data/vendor/assets/components/uri.js/prettify/lang-hs.js +2 -0
- data/vendor/assets/components/uri.js/prettify/lang-lisp.js +3 -0
- data/vendor/assets/components/uri.js/prettify/lang-lua.js +2 -0
- data/vendor/assets/components/uri.js/prettify/lang-ml.js +2 -0
- data/vendor/assets/components/uri.js/prettify/lang-n.js +4 -0
- data/vendor/assets/components/uri.js/prettify/lang-proto.js +1 -0
- data/vendor/assets/components/uri.js/prettify/lang-scala.js +2 -0
- data/vendor/assets/components/uri.js/prettify/lang-sql.js +2 -0
- data/vendor/assets/components/uri.js/prettify/lang-tex.js +1 -0
- data/vendor/assets/components/uri.js/prettify/lang-vb.js +2 -0
- data/vendor/assets/components/uri.js/prettify/lang-vhdl.js +3 -0
- data/vendor/assets/components/uri.js/prettify/lang-wiki.js +2 -0
- data/vendor/assets/components/uri.js/prettify/lang-xq.js +3 -0
- data/vendor/assets/components/uri.js/prettify/lang-yaml.js +2 -0
- data/vendor/assets/components/uri.js/prettify/prettify.css +1 -0
- data/vendor/assets/components/uri.js/prettify/prettify.js +28 -0
- data/vendor/assets/components/uri.js/prettify/prettify.sunburst.css +52 -0
- data/vendor/assets/components/uri.js/screen.css +167 -0
- data/vendor/assets/components/uri.js/screen.js +39 -0
- data/vendor/assets/components/uri.js/src/IPv6.js +185 -0
- data/vendor/assets/components/uri.js/src/SecondLevelDomains.js +220 -0
- data/vendor/assets/components/uri.js/src/URI.fragmentQuery.js +103 -0
- data/vendor/assets/components/uri.js/src/URI.fragmentURI.js +96 -0
- data/vendor/assets/components/uri.js/src/URI.js +1938 -0
- data/vendor/assets/components/uri.js/src/URI.min.js +81 -0
- data/vendor/assets/components/uri.js/src/URITemplate.js +494 -0
- data/vendor/assets/components/uri.js/src/jquery.URI.js +232 -0
- data/vendor/assets/components/uri.js/src/jquery.URI.min.js +7 -0
- data/vendor/assets/components/uri.js/src/punycode.js +508 -0
- data/vendor/assets/components/uri.js/test/index.html +26 -0
- data/vendor/assets/components/uri.js/test/pre_libs.js +4 -0
- data/vendor/assets/components/uri.js/test/qunit/qunit-composite.css +13 -0
- data/vendor/assets/components/uri.js/test/qunit/qunit-composite.js +167 -0
- data/vendor/assets/components/uri.js/test/qunit/qunit.css +244 -0
- data/vendor/assets/components/uri.js/test/qunit/qunit.js +2212 -0
- data/vendor/assets/components/uri.js/test/test.URI.html +26 -0
- data/vendor/assets/components/uri.js/test/test.fragmentQuery.html +31 -0
- data/vendor/assets/components/uri.js/test/test.fragmentURI.html +31 -0
- data/vendor/assets/components/uri.js/test/test.jQuery-1.10.html +31 -0
- data/vendor/assets/components/uri.js/test/test.jQuery-1.7.html +31 -0
- data/vendor/assets/components/uri.js/test/test.jQuery-1.8.html +31 -0
- data/vendor/assets/components/uri.js/test/test.jQuery-1.9.html +31 -0
- data/vendor/assets/components/uri.js/test/test.js +1409 -0
- data/vendor/assets/components/uri.js/test/test_fragmentQuery.js +57 -0
- data/vendor/assets/components/uri.js/test/test_fragmentURI.js +59 -0
- data/vendor/assets/components/uri.js/test/test_jim.js +143 -0
- data/vendor/assets/components/uri.js/test/test_jquery.js +138 -0
- data/vendor/assets/components/uri.js/test/test_template.js +385 -0
- data/vendor/assets/components/uri.js/test/urls.js +1236 -0
- data/vendor/assets/components/uri.js/uri-template.html +234 -0
- data/vendor/assets/components/uri.js/utils/SLDs.php +37 -0
- data/vendor/assets/components/uri.js/utils/sld.js +101 -0
- data/vendor/assets/components/veiljs/bower.json +36 -0
- data/vendor/assets/components/veiljs/veil-jquery.js +47 -0
- data/vendor/assets/components/veiljs/veil-knockout.js +55 -0
- data/vendor/assets/components/veiljs/veil.js +465 -0
- data/vendor/assets/javascripts/fuse.js +472 -0
- data/vendor/assets/javascripts/jquery-ui.js +3844 -0
- data/vendor/assets/javascripts/knockout-3.2.0-debug.js +5299 -0
- data/vendor/assets/javascripts/moment.js +1902 -0
- data/vendor/assets/javascripts/pikaday.js +896 -0
- data/vendor/assets/stylesheets/pikaday.css +171 -0
- metadata +120 -1
@@ -0,0 +1,1280 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8" />
|
5
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
6
|
+
<title>URI.js - API Documentation</title>
|
7
|
+
<meta name="description" content="URI.js is a Javascript library for working with URLs." />
|
8
|
+
|
9
|
+
<script src="jquery-1.9.1.min.js" type="text/javascript"></script>
|
10
|
+
<script src="prettify/prettify.js" type="text/javascript"></script>
|
11
|
+
<script src="screen.js" type="text/javascript"></script>
|
12
|
+
<link href="screen.css" rel="stylesheet" type="text/css" />
|
13
|
+
<link href="prettify/prettify.sunburst.css" rel="stylesheet" type="text/css" />
|
14
|
+
<script src="src/URI.min.js" type="text/javascript"></script>
|
15
|
+
<script type="text/javascript">
|
16
|
+
|
17
|
+
var _gaq = _gaq || [];
|
18
|
+
_gaq.push(['_setAccount', 'UA-8922143-3']);
|
19
|
+
_gaq.push(['_trackPageview']);
|
20
|
+
|
21
|
+
(function() {
|
22
|
+
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
23
|
+
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
24
|
+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
25
|
+
})();
|
26
|
+
|
27
|
+
</script>
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<a id="github-forkme" href="https://github.com/medialize/URI.js"><img src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" /></a>
|
31
|
+
<div id="container">
|
32
|
+
<h1><a href="https://github.com/medialize/URI.js">URI.js</a></h1>
|
33
|
+
|
34
|
+
<ul class="menu">
|
35
|
+
<li><a href="/URI.js/">Intro</a></li>
|
36
|
+
<li><a href="/URI.js/about-uris.html">Understanding URIs</a></li>
|
37
|
+
<li class="active"><a href="docs.html">API-Documentation</a></li>
|
38
|
+
<li><a href="jquery-uri-plugin.html">jQuery Plugin</a></li>
|
39
|
+
<li><a href="uri-template.html">URI Template</a></li>
|
40
|
+
<li><a href="build.html">Build</a></li>
|
41
|
+
<li><a href="http://rodneyrehm.de/en/">Author</a></li>
|
42
|
+
</ul>
|
43
|
+
|
44
|
+
<ul class="toc">
|
45
|
+
<li>
|
46
|
+
<a href="#constructor">Constructing an URI</a>
|
47
|
+
<ul>
|
48
|
+
<li><a href="#clone">cloning an URI instance</a></li>
|
49
|
+
<li><a href="#href">href()</a></li>
|
50
|
+
<li><a href="#toString">toString(), valueOf()</a></li>
|
51
|
+
</ul>
|
52
|
+
</li>
|
53
|
+
<li>
|
54
|
+
Working with URI parts
|
55
|
+
<ul>
|
56
|
+
<li><a href="#accessors-protocol">protocol(), scheme()</a></li>
|
57
|
+
<li><a href="#accessors-username">username()</a></li>
|
58
|
+
<li><a href="#accessors-password">password()</a></li>
|
59
|
+
<li><a href="#accessors-hostname">hostname()</a></li>
|
60
|
+
<li><a href="#accessors-port">port()</a></li>
|
61
|
+
<li><a href="#accessors-host">host()</a></li>
|
62
|
+
<li><a href="#accessors-userinfo">userinfo()</a></li>
|
63
|
+
<li><a href="#accessors-authority">authority()</a></li>
|
64
|
+
<li><a href="#accessors-subdomain">subdomain()</a></li>
|
65
|
+
<li><a href="#accessors-domain">domain()</a></li>
|
66
|
+
<li><a href="#accessors-tld">tld()</a></li>
|
67
|
+
|
68
|
+
<li><a href="#accessors-pathname">pathname(), path()</a></li>
|
69
|
+
<li><a href="#accessors-directory">directory()</a></li>
|
70
|
+
<li><a href="#accessors-filename">filename()</a></li>
|
71
|
+
<li><a href="#accessors-suffix">suffix()</a></li>
|
72
|
+
<li><a href="#accessors-segment">segment()</a></li>
|
73
|
+
<li><a href="#accessors-segmentCoded">segmentCoded()</a></li>
|
74
|
+
|
75
|
+
<li><a href="#accessors-search">search(), query()</a></li>
|
76
|
+
<li><a href="#accessors-hash">hash(), fragment()</a></li>
|
77
|
+
<li><a href="#accessors-resource">resource()</a></li>
|
78
|
+
<li><a href="#is">determine URL types</a></li>
|
79
|
+
</ul>
|
80
|
+
</li>
|
81
|
+
<li>
|
82
|
+
Working with the query string
|
83
|
+
<ul>
|
84
|
+
<li><a href="#accessors-search">search(), query()</a></li>
|
85
|
+
<li><a href="#search-set">setSearch(), setQuery()</a></li>
|
86
|
+
<li><a href="#search-add">addSearch(), addQuery()</a></li>
|
87
|
+
<li><a href="#search-remove">removeSearch(), removeQuery()</a></li>
|
88
|
+
<li><a href="#search-has">hasSearch(), hasQuery()</a></li>
|
89
|
+
</ul>
|
90
|
+
</li>
|
91
|
+
<li>
|
92
|
+
<a href="#fragment-abuse">Working with the Fragment (Hash)</a>
|
93
|
+
<ul>
|
94
|
+
<li><a href="#fragment-abuse-query">Data in Fragments (Hash)</a></li>
|
95
|
+
<li><a href="#fragment-abuse-uri">URLs in Fragments (Hash)</a></li>
|
96
|
+
</ul>
|
97
|
+
</li>
|
98
|
+
<li>
|
99
|
+
Normalizing URLs
|
100
|
+
<ul>
|
101
|
+
<li><a href="#normalize">normalize()</a></li>
|
102
|
+
<li><a href="#normalize-protocol">normalizeProtocol()</a></li>
|
103
|
+
<li><a href="#normalize-host">normalizeHostname()</a></li>
|
104
|
+
<li><a href="#normalize-port">normalizePort()</a></li>
|
105
|
+
<li><a href="#normalize-path">normalizePathname(), normalizePath()</a></li>
|
106
|
+
<li><a href="#normalize-search">normalizeSearch(), normalizeQuery()</a></li>
|
107
|
+
<li><a href="#normalize-hash">normalizeHash(), normalizeFragment()</a></li>
|
108
|
+
</ul>
|
109
|
+
</li>
|
110
|
+
<li>
|
111
|
+
Charsets / Encodings
|
112
|
+
<ul>
|
113
|
+
<li><a href="#iso8859">iso8859()</a></li>
|
114
|
+
<li><a href="#unicode">unicode()</a></li>
|
115
|
+
</ul>
|
116
|
+
</li>
|
117
|
+
<li><a href="#readable">readable()</a></li>
|
118
|
+
<li>
|
119
|
+
Relative and Absolute URLs
|
120
|
+
<ul>
|
121
|
+
<li><a href="#relativeto">relativeTo()</a></li>
|
122
|
+
<li><a href="#absoluteto">absoluteTo()</a></li>
|
123
|
+
</ul>
|
124
|
+
</li>
|
125
|
+
<li>
|
126
|
+
Comparing URLs
|
127
|
+
<ul>
|
128
|
+
<li><a href="#equals">equals()</a></li>
|
129
|
+
</ul>
|
130
|
+
</li>
|
131
|
+
<li>
|
132
|
+
Parsing URLs
|
133
|
+
<ul>
|
134
|
+
<li><a href="#static-parse">URI.parse()</a></li>
|
135
|
+
<li><a href="#static-parseAuthority">URI.parseAuthority()</a></li>
|
136
|
+
<li><a href="#static-parseUserinfo">URI.parseUserinfo()</a></li>
|
137
|
+
<li><a href="#static-parseHost">URI.parseHost()</a></li>
|
138
|
+
<li><a href="#static-parseQuery">URI.parseQuery()</a></li>
|
139
|
+
</ul>
|
140
|
+
</li>
|
141
|
+
<li>
|
142
|
+
Serializing URLs
|
143
|
+
<ul>
|
144
|
+
<li><a href="#static-build">URI.build()</a></li>
|
145
|
+
<li><a href="#static-buildAuthority">URI.buildAuthority()</a></li>
|
146
|
+
<li><a href="#static-buildUserinfo">URI.buildUserinfo()</a></li>
|
147
|
+
<li><a href="#static-buildHost">URI.buildHost()</a></li>
|
148
|
+
<li><a href="#static-buildQuery">URI.buildQuery()</a></li>
|
149
|
+
</ul>
|
150
|
+
</li>
|
151
|
+
<li>
|
152
|
+
Encoding and Decoding URLs
|
153
|
+
<ul>
|
154
|
+
<li><a href="#static-encode">URI.encode()</a></li>
|
155
|
+
<li><a href="#static-decode">URI.decode()</a></li>
|
156
|
+
|
157
|
+
<li><a href="#static-encodeReserved">URI.encodeReserved()</a></li>
|
158
|
+
|
159
|
+
<li><a href="#static-encodeQuery">URI.encodeQuery()</a></li>
|
160
|
+
<li><a href="#static-decodeQuery">URI.decodeQuery()</a></li>
|
161
|
+
</ul>
|
162
|
+
</li>
|
163
|
+
<li>
|
164
|
+
Static Helper Functions
|
165
|
+
<ul>
|
166
|
+
<li><a href="#static-noConflict">URI.noConflict()</a></li>
|
167
|
+
|
168
|
+
<li><a href="#static-addQuery">URI.addQuery()</a></li>
|
169
|
+
<li><a href="#static-removeQuery">URI.removeQuery()</a></li>
|
170
|
+
<li><a href="#static-commonPath">URI.commonPath()</a></li>
|
171
|
+
|
172
|
+
<li><a href="#static-withinString">URI.withinString()</a></li>
|
173
|
+
|
174
|
+
<li><a href="#static-iso8859">URI.iso8859()</a></li>
|
175
|
+
<li><a href="#static-unicode">URI.unicode()</a></li>
|
176
|
+
|
177
|
+
<li><a href="#static-expand">URI.expand()</a></li>
|
178
|
+
</ul>
|
179
|
+
</li>
|
180
|
+
</ul>
|
181
|
+
|
182
|
+
<h2 id="api-methods">URI.js API</h2>
|
183
|
+
|
184
|
+
<h3 id="constructor">URI Constructor</h3>
|
185
|
+
<pre class="prettyprint lang-js">var uri = new URI(); // same as new URI(location.href)
|
186
|
+
// string
|
187
|
+
var uri = new URI("http://example.org");
|
188
|
+
|
189
|
+
// URI object for cloning
|
190
|
+
var uri = new URI(new URI("http://example.org"));
|
191
|
+
|
192
|
+
// URI parts object
|
193
|
+
var uri = new URI({
|
194
|
+
protocol: "http",
|
195
|
+
host: "example.org"
|
196
|
+
});
|
197
|
+
|
198
|
+
// without new keyword
|
199
|
+
var uri = URI("http://example.org");
|
200
|
+
|
201
|
+
// resolving right in the constructor
|
202
|
+
var uri = URI("../foobar.html", "http://example.org/hello/world.html");
|
203
|
+
// which is exactly the same as
|
204
|
+
URI("../foobar.html").absoluteTo("http://example.org/hello/world.html");
|
205
|
+
// but specified in <a href="http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#constructor">URL constructor</a></pre>
|
206
|
+
|
207
|
+
<p>The following parts can be specified in an object:</p>
|
208
|
+
<pre class="prettyprint lang-js">var uri = new URI({
|
209
|
+
protocol: "http", // no trailing :
|
210
|
+
username: "user",
|
211
|
+
password: "pass",
|
212
|
+
hostname: "example.org",
|
213
|
+
port: "80", // string, please
|
214
|
+
// "path", not "pathname", sorry
|
215
|
+
path: "/foo/bar.html",
|
216
|
+
// "query", not "search", sorry
|
217
|
+
query: "foo=bar&bar=baz", // no leading ?
|
218
|
+
// "fragment", not "hash", sorry
|
219
|
+
fragment: "frag" // no leading #
|
220
|
+
});</pre>
|
221
|
+
|
222
|
+
<p>using only components of URIs:</p>
|
223
|
+
<pre class="prettyprint lang-js">// Look ma! I'm only working the pathname
|
224
|
+
var uri = new URI("some/directory/file.html");
|
225
|
+
|
226
|
+
// Look ma! I'm only working the query string
|
227
|
+
var uri = new URI("?foo=bar");
|
228
|
+
|
229
|
+
// Look ma! I'm only working the fragment / hash
|
230
|
+
var uri = new URI("#call-me-hash");
|
231
|
+
|
232
|
+
// and any combination of the above…</pre>
|
233
|
+
|
234
|
+
<p>using DOM elements:</p>
|
235
|
+
<pre class="prettyprint lang-js">var element = document.createElement('a');
|
236
|
+
element.href = 'http://example.org';
|
237
|
+
var uri = new URI(element);
|
238
|
+
// uri.domain() === 'example.org';</pre>
|
239
|
+
<pre class="prettyprint lang-html">The following DOM elements can be parsed:
|
240
|
+
|
241
|
+
<a href="...">
|
242
|
+
<blockquote cite="...">
|
243
|
+
<link href="...">
|
244
|
+
<base href="...">
|
245
|
+
<script src="...">
|
246
|
+
<form action="...">
|
247
|
+
<input type="image" src="...">
|
248
|
+
<img src="...">
|
249
|
+
<area href="...">
|
250
|
+
<iframe src="...">
|
251
|
+
<embed src="...">
|
252
|
+
<source src="...">
|
253
|
+
<track src="...">
|
254
|
+
|
255
|
+
|
256
|
+
any other element yields URI("")
|
257
|
+
</pre>
|
258
|
+
|
259
|
+
<h3 id="clone">cloning URIs</h3>
|
260
|
+
<p>Get a copy of the current URI instance</p>
|
261
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://example.org"),
|
262
|
+
uri2 = uri.clone();
|
263
|
+
|
264
|
+
uri2.tld("com");
|
265
|
+
uri == "http://example.org/";
|
266
|
+
uri2 == "http://example.com/";</pre>
|
267
|
+
|
268
|
+
<h3 id="href">href()</h3>
|
269
|
+
<p>get and set the entire URI</p>
|
270
|
+
<pre class="prettyprint lang-js">var uri = URI("http://example.com");
|
271
|
+
uri.href() === "http://example.com/";
|
272
|
+
|
273
|
+
uri.href("ftp://google.org");
|
274
|
+
uri.toString() === "ftp://google.org/"</pre>
|
275
|
+
|
276
|
+
<h3 id="toString">toString(), valueOf()</h3>
|
277
|
+
<p>serialize the URI to string. <code>valueOf()</code> is an alias to <code>toString()</code>, as string is the base primitive.</p>
|
278
|
+
<pre class="prettyprint lang-js">var uri = URI("http://example.com");
|
279
|
+
var s = uri.toString();
|
280
|
+
typeof s === "string";
|
281
|
+
s === "http://example.com/";</pre>
|
282
|
+
|
283
|
+
|
284
|
+
<h3 id="accessors-protocol">protocol(), scheme()</h3>
|
285
|
+
<p>.scheme() is an alias of .protocol()</p>
|
286
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://example.org/foo/hello.html");
|
287
|
+
// get protocol
|
288
|
+
uri.protocol(); // returns string "http"
|
289
|
+
// set protocol
|
290
|
+
uri.protocol("ftp"); // returns the URI instance for chaining
|
291
|
+
|
292
|
+
// relative scheme
|
293
|
+
uri.protocol("");
|
294
|
+
uri.toString() === "//example.org/foo/hello.html";</pre>
|
295
|
+
<p>NOTE: Throws a <code>TypeError</code> on illegal input, that is anything but <code>[a-z0-9.+-]</code> and <code>[empty string]</code> and <code>null</code></p>
|
296
|
+
|
297
|
+
<h3 id="accessors-username">username()</h3>
|
298
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://user:pass@example.org/foo/hello.html");
|
299
|
+
// get username
|
300
|
+
uri.username(); // returns string "user"
|
301
|
+
// set username
|
302
|
+
uri.username("user"); // returns the URI instance for chaining</pre>
|
303
|
+
|
304
|
+
<h3 id="accessors-password">password()</h3>
|
305
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://user:pass@example.org/foo/hello.html");
|
306
|
+
// get password
|
307
|
+
uri.password(); // returns string "pass"
|
308
|
+
// set password
|
309
|
+
uri.password("user"); // returns the URI instance for chaining</pre>
|
310
|
+
|
311
|
+
<h3 id="accessors-hostname">hostname()</h3>
|
312
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://example.org/foo/hello.html");
|
313
|
+
// get protocol
|
314
|
+
uri.hostname(); // returns string
|
315
|
+
// set protocol
|
316
|
+
uri.hostname("example.org"); // returns the URI instance for chaining</pre>
|
317
|
+
<p>NOTE: <a href="#accessors-hostname">.hostname()</a> returns the actual hostname, whereas <a href="#accessors-host">.host()</a> returns the hostname including the port</p>
|
318
|
+
|
319
|
+
<h3 id="accessors-port">port()</h3>
|
320
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://example.org:8080/foo/hello.html");
|
321
|
+
// get port
|
322
|
+
uri.port(); // returns string "8080"
|
323
|
+
// set port
|
324
|
+
uri.port("80"); // returns the URI instance for chaining</pre>
|
325
|
+
<p>NOTE: although the port may be considered an integer, within URI it is a string.</p>
|
326
|
+
<p>NOTE: Throws a <code>TypeError</code> on illegal input</p>
|
327
|
+
|
328
|
+
<h3 id="accessors-host">host()</h3>
|
329
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://example.org:80/foo/hello.html");
|
330
|
+
// get host
|
331
|
+
uri.host(); // returns string "example.org:80"
|
332
|
+
// set host
|
333
|
+
uri.host("example.org:80"); // returns the URI instance for chaining</pre>
|
334
|
+
<p>NOTE: <a href="#accessors-hostname">.hostname()</a> returns the actual hostname, whereas <a href="#accessors-host">.host()</a> returns the hostname including the port</p>
|
335
|
+
|
336
|
+
<h3 id="accessors-userinfo">userinfo()</h3>
|
337
|
+
<p>Userinfo is comprised of username and password</p>
|
338
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://user:pass@example.org:88/foo/hello.html");
|
339
|
+
// get userinfo
|
340
|
+
uri.userinfo(); // returns string "user:pass"
|
341
|
+
// set userinfo
|
342
|
+
uri.userinfo("user:pass"); // returns the URI instance for chaining</pre>
|
343
|
+
|
344
|
+
<h3 id="accessors-authority">authority()</h3>
|
345
|
+
<p>Authority is comprised of username, password, hostname and port</p>
|
346
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://user:pass@example.org:88/foo/hello.html");
|
347
|
+
// get authority
|
348
|
+
uri.authority(); // returns string "user:pass@example.org:88"
|
349
|
+
// set authority
|
350
|
+
uri.authority("user:pass@example.org:80"); // returns the URI instance for chaining</pre>
|
351
|
+
<p>NOTE: .authority() will reset any of username, password and port if they're not specified.</p>
|
352
|
+
|
353
|
+
<h3 id="accessors-domain">domain()</h3>
|
354
|
+
<p>.domain() is a convenience method that returns <code>example.org</code> from the hostname <code>www.example.org</code>.</p>
|
355
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://example.org/foo/hello.html");
|
356
|
+
// get domain
|
357
|
+
uri.domain(); // returns string "example.org"
|
358
|
+
// set domain
|
359
|
+
uri.domain("otherdomain.com"); // returns the URI instance for chaining
|
360
|
+
|
361
|
+
// Second Level Domain (SLD) Support (as of URI.js 1.5.0)
|
362
|
+
uri = new URI("http://example.co.uk/foo/hello.html");
|
363
|
+
uri.domain(); // return string "example.co.uk"
|
364
|
+
uri.domain(true); // return string "co.uk"</pre>
|
365
|
+
<p>NOTE: .domain() will throw an error if you pass it an empty string.</p>
|
366
|
+
<p>NOTE: Throws a <code>TypeError</code> on illegal input</p>
|
367
|
+
|
368
|
+
<h3 id="accessors-subdomain">subdomain()</h3>
|
369
|
+
<p>.subdomain() is a convenience method that returns <code>www</code> from the hostname <code>www.example.org</code>.</p>
|
370
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://www.example.org/foo/hello.html");
|
371
|
+
// get subdomain
|
372
|
+
uri.subdomain(); // returns string "www"
|
373
|
+
// set subdomain
|
374
|
+
uri.subdomain("other.subdomain"); // returns the URI instance for chaining</pre>
|
375
|
+
<p>NOTE: Throws a <code>TypeError</code> on illegal input</p>
|
376
|
+
|
377
|
+
<h3 id="accessors-tld">tld()</h3>
|
378
|
+
<p>.tld() is a convenience method that returns <code>org</code> from the hostname <code>www.example.org</code>.</p>
|
379
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://example.org/foo/hello.html");
|
380
|
+
// get tld
|
381
|
+
uri.tld(); // returns string "org"
|
382
|
+
// set tld
|
383
|
+
uri.tld("com"); // returns the URI instance for chaining
|
384
|
+
|
385
|
+
// Second Level Domain (SLD) Support (as of URI.js 1.5.0)
|
386
|
+
uri = new URI("http://example.co.uk/foo/hello.html");
|
387
|
+
uri.tld(); // return string "co.uk"
|
388
|
+
uri.tld(true); // return string "uk"</pre>
|
389
|
+
<p>NOTE: Throws an <code>Error</code> if you pass it an empty string or use it on an IP-host.</p>
|
390
|
+
|
391
|
+
<h3 id="accessors-pathname">pathname(), path()</h3>
|
392
|
+
<p>.path() is an alias of .pathname()</p>
|
393
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://example.org/foo/hello.html");
|
394
|
+
// get pathname
|
395
|
+
uri.pathname(); // returns string "/foo/hello.html"
|
396
|
+
// set pathname
|
397
|
+
uri.pathname("/foo/hello.html"); // returns the URI instance for chaining
|
398
|
+
|
399
|
+
// will encode for you
|
400
|
+
uri.pathname("/hello world/");
|
401
|
+
uri.pathname() === "/hello%20world/";
|
402
|
+
// will decode for you
|
403
|
+
uri.pathname(true) === "/hello world/";
|
404
|
+
|
405
|
+
// will return empty string for empty paths, but:
|
406
|
+
URI("").path() === "";
|
407
|
+
URI("/").path() === "/";
|
408
|
+
URI("http://example.org").path() === "/";
|
409
|
+
</pre>
|
410
|
+
|
411
|
+
<h3 id="accessors-directory">directory()</h3>
|
412
|
+
<p>.directory() is an convenience method for mutating the directory part of a path</p>
|
413
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://example.org/foo/hello.html");
|
414
|
+
// get directory
|
415
|
+
uri.directory(); // returns string "/foo" (no trailing slash)
|
416
|
+
// set directory
|
417
|
+
uri.directory("/bar"); // returns the URI instance for chaining
|
418
|
+
// uri == "http://example.org/bar/hello.html"
|
419
|
+
|
420
|
+
// will encode for you
|
421
|
+
uri.directory("/hello world/");
|
422
|
+
uri.directory() === "/hello%20world";
|
423
|
+
// will decode for you
|
424
|
+
uri.directory(true) === "/hello world";
|
425
|
+
|
426
|
+
uri.href("http://example.com/foo").directory()
|
427
|
+
// -&t; "/"
|
428
|
+
uri.href("/foo").directory()
|
429
|
+
// -&t; "/"
|
430
|
+
uri.href("foo").directory()
|
431
|
+
// -&t; ""</pre>
|
432
|
+
|
433
|
+
<h3 id="accessors-filename">filename()</h3>
|
434
|
+
<p>.filename() is an convenience method for mutating the filename part of a path</p>
|
435
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://example.org/foo/hello.html");
|
436
|
+
// get filename
|
437
|
+
uri.filename(); // returns string "hello.html" (no leading slash)
|
438
|
+
// set filename
|
439
|
+
uri.filename("world.xml"); // returns the URI instance for chaining
|
440
|
+
// uri == "http://example.org/bar/world.xml"
|
441
|
+
|
442
|
+
// will encode for you
|
443
|
+
uri.filename("hello world.html");
|
444
|
+
uri.filename() === "hello%20world.html";
|
445
|
+
// will decode for you
|
446
|
+
uri.filename(true) === "hello world.html";</pre>
|
447
|
+
<p>NOTE: If you pass <code>../file.html</code>, the directory will be changed accordingly</p>
|
448
|
+
|
449
|
+
<h3 id="accessors-suffix">suffix()</h3>
|
450
|
+
<p>.suffix() is an convenience method for mutating the filename part of a path</p>
|
451
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://example.org/foo/hello.html");
|
452
|
+
// get suffix
|
453
|
+
uri.suffix(); // returns string "html" (no leading dot)
|
454
|
+
// set suffix
|
455
|
+
uri.suffix("xml"); // returns the URI instance for chaining
|
456
|
+
// uri == "http://example.org/bar/world.xml"
|
457
|
+
|
458
|
+
// will encode for you
|
459
|
+
uri.suffix("würgh");
|
460
|
+
uri.suffix() === "w%C3%BCrgh";
|
461
|
+
// will decode for you
|
462
|
+
uri.suffix(true) === "würgh";</pre>
|
463
|
+
|
464
|
+
<h3 id="accessors-segment">segment()</h3>
|
465
|
+
<p>.segment() allows convenient access to directory levels / URN segments within the path. See <a href="#accessors-segmentCoded">.segmentCoded()</a> for an interface that transparently encodes and decodes path segments.</p>
|
466
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://example.org/foo/hello.html");
|
467
|
+
// get segments
|
468
|
+
uri.segment(); // returns array ["foo", "hello.html"]
|
469
|
+
// set segments
|
470
|
+
uri.segment(["foo", "bar", "foobar.html"]); // -> http://example.org/foo/bar/foobar.html
|
471
|
+
|
472
|
+
// get specific level
|
473
|
+
uri.segment(0); // returns "foo"
|
474
|
+
uri.segment(1); // returns "bar"
|
475
|
+
uri.segment(-1); // returns "foobar.html"
|
476
|
+
// set specific level
|
477
|
+
uri.segment(0, "bar"); // -> http://example.org/bar/bar/foobar.html
|
478
|
+
// remove specific level
|
479
|
+
uri.segment(0, ""); // -> http://example.org/bar/foobar.html
|
480
|
+
|
481
|
+
// append level
|
482
|
+
uri.segment("appendthis"); // -> http://example.org/bar/foobar.html/appendthis</pre>
|
483
|
+
|
484
|
+
<h3 id="accessors-segmentCoded">segmentCoded()</h3>
|
485
|
+
<p>.segmentCoded() works the same way <a href="#accessors-segment">.segment()</a> does, with the difference of transparently encoding and decoding values.</p>
|
486
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://example.org/foo/hello%20world.html");
|
487
|
+
// get segments
|
488
|
+
uri.segment(); // returns array ["foo", "hello world.html"]
|
489
|
+
// set segments
|
490
|
+
uri.segment(["foo", "bar", "foo bar.html"]); // -> http://example.org/foo/bar/foo%20bar.html
|
491
|
+
|
492
|
+
// get specific level
|
493
|
+
uri.segment(0); // returns "foo"
|
494
|
+
uri.segment(1); // returns "bar"
|
495
|
+
uri.segment(-1); // returns "foo bar.html"
|
496
|
+
// set specific level
|
497
|
+
uri.segment(0, "bar bam"); // -> http://example.org/bar%20bam/bar/foobar.html
|
498
|
+
// remove specific level
|
499
|
+
uri.segment(0, ""); // -> http://example.org/bar/foobar.html
|
500
|
+
|
501
|
+
// append level
|
502
|
+
uri.segment("append this"); // -> http://example.org/bar/foobar.html/append%20this</pre>
|
503
|
+
|
504
|
+
|
505
|
+
<h3 id="accessors-search">search(), query()</h3>
|
506
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://example.org/foo/hello.html?foo=bar&bar=baz");
|
507
|
+
// get search
|
508
|
+
uri.search(); // returns string "?foo=bar&bar=baz" (leading ?)
|
509
|
+
// get query
|
510
|
+
uri.query(); // returns string "foo=bar&bar=baz" (no leading ?)
|
511
|
+
|
512
|
+
// .query() and .search() behave the same for the following:
|
513
|
+
|
514
|
+
// set search
|
515
|
+
uri.search("?foo=bar&bar=baz"); // returns the URI instance for chaining
|
516
|
+
uri.search("foo=bar&bar=baz"); // returns the URI instance for chaining
|
517
|
+
// uri == "http://example.org/bar/world.html?foo=bar&bar=baz"
|
518
|
+
|
519
|
+
// remove query
|
520
|
+
uri.search(""); // returns the URI instance for chaining
|
521
|
+
// uri == "http://example.org/bar/world.html"
|
522
|
+
|
523
|
+
// get data map:
|
524
|
+
uri.search(true); // returns { foo: "bar", hello : ["world", "mars"] }
|
525
|
+
|
526
|
+
// set data map:
|
527
|
+
uri.search({ foo: "bar", hello : ["world", "mars"] });
|
528
|
+
// uri == "http://example.org/bar/world.html?foo=bar&hello=world&hello=mars"
|
529
|
+
|
530
|
+
// overwrite data through callback
|
531
|
+
uri.search(function(data) {
|
532
|
+
return { hello : "world" };
|
533
|
+
});
|
534
|
+
// uri == "http://example.org/bar/world.html?hello=world"
|
535
|
+
|
536
|
+
// augment data through callback
|
537
|
+
uri.search(function(data) {
|
538
|
+
data.foo = "bar";
|
539
|
+
});
|
540
|
+
// uri == "http://example.org/bar/world.html?hello=world&foo=bar"
|
541
|
+
|
542
|
+
// CAUTION: beware of arrays, the following are not quite the same
|
543
|
+
// If you're dealing with PHP, you probably want the latter…
|
544
|
+
uri.search("?foo=bar&bar=baz");
|
545
|
+
uri.search("?foo=bar[]&bar[]=baz");</pre>
|
546
|
+
<p>Note that names and values passed in an object are encoded automatically.
|
547
|
+
The object, resulting from parsing the query string, contains decoded values</p>
|
548
|
+
<p>Hint: If you're using jQuery, have a look at their <a href="http://api.jquery.com/serialize/">.serialize()</a> function.</p>
|
549
|
+
|
550
|
+
<h3 id="accessors-hash">hash(), fragment()</h3>
|
551
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://example.org/foo/hello.html#world");
|
552
|
+
// get hash
|
553
|
+
uri.hash(); // returns string "#world" (leading #)
|
554
|
+
// get fragment
|
555
|
+
uri.fragment(); // returns string "world" (no leading #)
|
556
|
+
|
557
|
+
// remove fragment
|
558
|
+
uri.fragment(""); // returns the URI instance for chaining
|
559
|
+
// uri == "http://example.org/bar/world.html"
|
560
|
+
|
561
|
+
// .hash() and .fragment() behave the same for the following:
|
562
|
+
|
563
|
+
// set hash
|
564
|
+
uri.hash("#mars"); // returns the URI instance for chaining
|
565
|
+
uri.hash("mars"); // returns the URI instance for chaining
|
566
|
+
// uri == "http://example.org/bar/world.xml#mars"</pre>
|
567
|
+
|
568
|
+
<h3 id="accessors-resource">resource()</h3>
|
569
|
+
<p>Resource is comprised of path, query and fragment</p>
|
570
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://example.org/foo/hello.html?query=string#hash");
|
571
|
+
// get resource
|
572
|
+
uri.resource(); // returns string "/foo/hello.html?query=string#hash"
|
573
|
+
// set resource
|
574
|
+
uri.resource("/mars.txt?query=foo#other"); // returns the URI instance for chaining</pre>
|
575
|
+
<p>NOTE: .resource() will reset any of path, query and fragment if they're not specified.</p>
|
576
|
+
|
577
|
+
<h3 id="is">is()</h3>
|
578
|
+
<p>.is() tells what a URL is. It responds with a boolean and can be asked the following questions:</p>
|
579
|
+
<dl>
|
580
|
+
<dt><code>relative</code></dt><dd><code>true</code> if URL doesn't have a hostname</dd>
|
581
|
+
<dt><code>absolute</code></dt><dd><code>true</code> if URL has a hostname</dd>
|
582
|
+
<dt><code>urn</code></dt><dd><code>true</code> if URI is a URN</dd>
|
583
|
+
<dt><code>url</code></dt><dd><code>true</code> if URI is a URL</dd>
|
584
|
+
<dt><code>domain</code>, <code>name</code></dt><dd><code>true</code> if hostname is not an IP</dd>
|
585
|
+
<dt><code>sld</code></dt><dd><code>true</code> if hostname is a second level domain (i.e. "example.co.uk")</dd>
|
586
|
+
<dt><code>idn</code></dt><dd><code>true</code> if hostname contains non-alphanumeric characters and is not an IP</dd>
|
587
|
+
<dt><code>punycode</code></dt><dd><code>true</code> if hostname contains <code>xn--</code></dd>
|
588
|
+
<dt><code>ip</code></dt><dd><code>true</code> if hostname is IPv4 or IPv6</dd>
|
589
|
+
<dt><code>ip4</code>, <code>ipv4</code>, <code>inet4</code></dt><dd><code>true</code> if hostname is IPv4</dd>
|
590
|
+
<dt><code>ip6</code>, <code>ipv6</code>, <code>inet6</code></dt><dd><code>true</code> if hostname is IPv6</dd>
|
591
|
+
</dl>
|
592
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://example.org/");
|
593
|
+
uri.is("relative") === false;
|
594
|
+
uri.is("absolute") === true;
|
595
|
+
uri.is("urn") === false;
|
596
|
+
uri.is("url") === true;
|
597
|
+
uri.is("name") === true;
|
598
|
+
uri.is("sld") === false;
|
599
|
+
uri.is("punycode") === false;
|
600
|
+
uri.is("IDN") === false; // case doesn't matter
|
601
|
+
uri.is("idn") === false; // case doesn't matter
|
602
|
+
uri.is("ip") === false;
|
603
|
+
|
604
|
+
var uri = new URI("http://123.123.123.123/");
|
605
|
+
uri.is("relative") === false;
|
606
|
+
uri.is("absolute") === true;
|
607
|
+
uri.is("urn") === false;
|
608
|
+
uri.is("url") === true;
|
609
|
+
uri.is("name") === false;
|
610
|
+
uri.is("sld") === false;
|
611
|
+
uri.is("IP") === true;
|
612
|
+
uri.is("IPv4") === true;
|
613
|
+
uri.is("IPv6") === false;
|
614
|
+
|
615
|
+
var uri = new URI("http://fe80:0000:0000:0000:0204:61ff:fe9d:f156/");
|
616
|
+
uri.is("IP") === true;
|
617
|
+
uri.is("IPv4") === false;
|
618
|
+
uri.is("IPv6") === true;
|
619
|
+
|
620
|
+
var uri = new URI("/hello/world.html");
|
621
|
+
uri.is("relative") === true;
|
622
|
+
uri.is("absolute") === false;
|
623
|
+
uri.is("urn") === false;
|
624
|
+
uri.is("url") === true;
|
625
|
+
uri.is("name") === false;
|
626
|
+
uri.is("IP") === false;
|
627
|
+
|
628
|
+
var uri = new URI("http://example.co.uk/");
|
629
|
+
uri.is("name") === true;
|
630
|
+
uri.is("sld") === true;
|
631
|
+
|
632
|
+
var uri = new URI("mailto:mail@example.org");
|
633
|
+
uri.is("relative") === false;
|
634
|
+
uri.is("absolute") === false;
|
635
|
+
uri.is("urn") === true;
|
636
|
+
uri.is("url") === false;
|
637
|
+
uri.is("name") === false;
|
638
|
+
uri.is("sld") === false;
|
639
|
+
uri.is("punycode") === false;
|
640
|
+
uri.is("idn") === false;
|
641
|
+
uri.is("ip") === false;</pre>
|
642
|
+
|
643
|
+
|
644
|
+
<h2 id="querystrings">Working with the query string</h2>
|
645
|
+
|
646
|
+
<h3 id="search-set">setSearch(), setQuery()</h3>
|
647
|
+
<p>.setQuery() is an alias of .setSearch()</p>
|
648
|
+
<pre class="prettyprint lang-js">var uri = new URI("?hello=world");
|
649
|
+
uri.setSearch("hello", "mars"); // returns the URI instance for chaining
|
650
|
+
// uri == "?hello=mars"
|
651
|
+
|
652
|
+
uri.setSearch({ foo: "bar", goodbye : ["world", "mars"] });
|
653
|
+
// uri == "?hello=mars&foo=bar&goodbye=world&goodbye=mars"
|
654
|
+
|
655
|
+
uri.setSearch("goodbye", "sun");
|
656
|
+
// uri == "?hello=mars&foo=bar&goodbye=sun"
|
657
|
+
|
658
|
+
// CAUTION: beware of arrays, the following are not quite the same
|
659
|
+
// If you're dealing with PHP, you probably want the latter…
|
660
|
+
uri.setSearch("foo", ["bar", "baz"]);
|
661
|
+
uri.setSearch("foo[]", ["bar", "baz"]);</pre>
|
662
|
+
<p>Note that names and values passed in are encoded automatically.</p>
|
663
|
+
|
664
|
+
<h3 id="search-add">addSearch(), addQuery()</h3>
|
665
|
+
<p>.addQuery() is an alias of .addSearch()</p>
|
666
|
+
<pre class="prettyprint lang-js">var uri = new URI("?hello=world");
|
667
|
+
uri.addSearch("hello", "mars"); // returns the URI instance for chaining
|
668
|
+
// uri == "?hello=world&hello=mars"
|
669
|
+
|
670
|
+
uri.addSearch({ foo: "bar", goodbye : ["world", "mars"] });
|
671
|
+
// uri == "?hello=world&hello=mars&foo=bar&goodbye=world&goodbye=mars"
|
672
|
+
|
673
|
+
uri.addSearch("no-value");
|
674
|
+
// uri == "?hello=world&hello=mars&foo=bar&goodbye=world&goodbye=mars&no-value"
|
675
|
+
|
676
|
+
// CAUTION: beware of arrays, the following are not quite the same
|
677
|
+
// If you're dealing with PHP, you probably want the latter…
|
678
|
+
uri.addSearch("foo", ["bar", "baz"]);
|
679
|
+
uri.addSearch("foo[]", ["bar", "baz"]);</pre>
|
680
|
+
<p>Note that names and values passed in are encoded automatically.</p>
|
681
|
+
|
682
|
+
<h3 id="search-remove">removeSearch(), removeQuery()</h3>
|
683
|
+
<p>.removeQuery() is an alias of .removeSearch()</p>
|
684
|
+
<pre class="prettyprint lang-js">var uri = new URI("?hello=world&hello=mars&foo=bar");
|
685
|
+
// remove an attribute
|
686
|
+
uri.removeSearch("hello"); // returns the URI instance for chaining
|
687
|
+
// uri == "?foo=bar"
|
688
|
+
|
689
|
+
// remove an attribute with value filter
|
690
|
+
uri.search("?hello=world&hello=mars&foo=bar");
|
691
|
+
uri.removeSearch("hello", "world"); // returns the URI instance for chaining
|
692
|
+
// uri == "?hello=mars&foo=bar"
|
693
|
+
|
694
|
+
// remove multiple values
|
695
|
+
uri.search("?hello=world&hello=mars&foo=bar&mine=true");
|
696
|
+
uri.removeSearch(["hello", "foo"]);
|
697
|
+
// uri == "?mine=true"
|
698
|
+
|
699
|
+
// remove multiple values with value filter
|
700
|
+
uri.search("?hello=world&hello=mars&foo=bar&mine=true&a=1&a=2&a=3");
|
701
|
+
uri.removeSearch({hello: "world", foo: undefined, a: ["1", "3"]});
|
702
|
+
// uri == "?hello=mars&mine=true&a=2"</pre>
|
703
|
+
|
704
|
+
<h3 id="search-has">hasSearch(), hasQuery()</h3>
|
705
|
+
<p>.hasQuery() is an alias of .hasSearch(). The method checks the existence and value of a given parameter within the query string.</p>
|
706
|
+
<pre class="prettyprint lang-js">var uri = URI("?string=bar&list=one&list=two&number=123&null&empty=");
|
707
|
+
|
708
|
+
// check if parameter exists (regardless of value)
|
709
|
+
u.hasQuery("string") === true;
|
710
|
+
u.hasQuery("nono") === false;
|
711
|
+
|
712
|
+
// check if parameter has a truthy / falsy value
|
713
|
+
u.hasQuery("string", true) === true;
|
714
|
+
u.hasQuery("string", false) === false;
|
715
|
+
u.hasQuery("empty", true) === false;
|
716
|
+
u.hasQuery("empty", false) === true;
|
717
|
+
|
718
|
+
// check if parameter has a given value
|
719
|
+
u.hasQuery("string", "bar") === true;
|
720
|
+
u.hasQuery("number", 123) === true;
|
721
|
+
|
722
|
+
// check if value is contained in parameter list
|
723
|
+
u.hasQuery("list", "two", true) === true;
|
724
|
+
u.hasQuery("list", ["two"], true) === true;
|
725
|
+
u.hasQuery("list", "three", true) === false;
|
726
|
+
u.hasQuery("list", ["two", "three"], true) === false;
|
727
|
+
u.hasQuery("list", /ne$/, true) === true;
|
728
|
+
|
729
|
+
// check if parameter matches an expression
|
730
|
+
u.hasQuery("string", /ar$/) === true;
|
731
|
+
|
732
|
+
// check by comparison function
|
733
|
+
u.hasQuery("string", function(value, name, data) {
|
734
|
+
// value === "bar";
|
735
|
+
// name === "string";
|
736
|
+
// data === u.query(true);
|
737
|
+
return true;
|
738
|
+
}) === true;</pre>
|
739
|
+
|
740
|
+
<h2 id="fragment-abuse">Working with the Fragment (Hash)</h2>
|
741
|
+
|
742
|
+
<p>
|
743
|
+
There are virtually no limits to what you might do with fragments (hash).
|
744
|
+
Every system has their own bag of tricks.
|
745
|
+
As a result URI.js cannot offer any of the following tools right out of the box.
|
746
|
+
The most common <em>abuse of fragments</em> are storing URLs or query string like data.
|
747
|
+
</p>
|
748
|
+
|
749
|
+
<p>
|
750
|
+
Usually a prefix is used to identify data with special meaning. This prefix can be pretty much what you want.
|
751
|
+
For URIs it's usually <code>!</code> and for query-like data it often is <code>?</code>.
|
752
|
+
But they don't have to, which is why you can define a global default: <code>URI.fragmentPrefix = "$";</code>
|
753
|
+
</p>
|
754
|
+
|
755
|
+
<h3 id="fragment-abuse-query">Query String Fragments</h3>
|
756
|
+
<p>The file <a href="https://github.com/medialize/URI.js/blob/gh-pages/src/URI.fragmentQuery.js">src/URI.fragmentQuery.js</a> is a "plugin" that allows you to store data in hashes in the same manner the .query() functions provide.</p>
|
757
|
+
|
758
|
+
<pre class="prettyprint lang-js">var uri = new URI("#?hello=world");
|
759
|
+
uri.addFragment("hello", "mars"); // returns the URI instance for chaining
|
760
|
+
// uri == "#?hello=world&hello=mars"
|
761
|
+
|
762
|
+
// to change the fragment prefix on an instance level:
|
763
|
+
uri.fragmentPrefix("!");
|
764
|
+
|
765
|
+
// to change the fragment prefix on a global level:
|
766
|
+
URI.fragmentPrefix = "!";</pre>
|
767
|
+
|
768
|
+
|
769
|
+
<h3 id="fragment-abuse-uri">URL Fragments</h3>
|
770
|
+
<p>The file <a href="https://github.com/medialize/URI.js/blob/gh-pages/src/URI.fragmentURI.js">src/URI.fragmentURI.js</a> is a "plugin" that allows you to store URLs in hashes.</p>
|
771
|
+
|
772
|
+
<pre class="prettyprint lang-js">var uri = URI("http://example.org/#!/foo/bar/baz.html"),
|
773
|
+
furi = uri.fragment(true);
|
774
|
+
|
775
|
+
// manipulating the fragment URI
|
776
|
+
furi.pathname() === "/foo/bar/baz.html";
|
777
|
+
furi.pathname("/hello.html");
|
778
|
+
|
779
|
+
// has direct effect on the actual URI
|
780
|
+
uri.toString() === "http://example.org/#!/hello.html"
|
781
|
+
|
782
|
+
// to change the fragment prefix on an instance level:
|
783
|
+
uri.fragmentPrefix("?");
|
784
|
+
|
785
|
+
// to change the fragment prefix on a global level:
|
786
|
+
URI.fragmentPrefix = "?";</pre>
|
787
|
+
|
788
|
+
<h2 id="normalizing">Normalizing URLs</h2>
|
789
|
+
|
790
|
+
<h3 id="normalize">normalize()</h3>
|
791
|
+
<p>executes normalizeProtocol(), normalizeHostname(), normalizePort(), normalizePath(), normalizeSearch(), normalizeHash()</p>
|
792
|
+
|
793
|
+
<h3 id="normalize-protocol">normalizeProtocol()</h3>
|
794
|
+
<pre class="prettyprint lang-js">var uri = new URI("hTTp://www.example.org/");
|
795
|
+
// normalize protocol
|
796
|
+
uri.normalizeProtocol(); // returns the URI instance for chaining
|
797
|
+
// uri == "http://www.example.org/"</pre>
|
798
|
+
|
799
|
+
<h3 id="normalize-host">normalizeHostname()</h3>
|
800
|
+
<p>For IDN conversion <a href="https://github.com/bestiejs/punycode.js">punycode.js</a> must be available (bundled in URI.js).
|
801
|
+
For IPv6-best-notation conversion IPv6.js must be available (bundled in URI.js). Also lower-cases hostnames.</p>
|
802
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://www.exämple.org/");
|
803
|
+
// normalize IDN host
|
804
|
+
uri.normalizeHostname(); // returns the URI instance for chaining
|
805
|
+
// uri == "http://www.xn--exmple-cua.org/"
|
806
|
+
|
807
|
+
// normalize IPv6 host
|
808
|
+
uri.hostname("fe80:0000:0000:0000:0204:61ff:fe9d:f156");
|
809
|
+
uri.normalizeHostname(); // returns the URI instance for chaining
|
810
|
+
// uri == "http://fe80::204:61ff:fe9d:f156/"
|
811
|
+
|
812
|
+
// normalize hostname to lower case
|
813
|
+
uri.hostname("wWw.eXample.Org");
|
814
|
+
uri.normalizeHostname(); // returns the URI instance for chaining
|
815
|
+
// uri == "http://www.example.org/"</pre>
|
816
|
+
<p>There is no .normalizeHost(), as <a href="#accessors-host">.host()</a> is a property comprised of <a href="#accessors-hostname">.hostname()</a> and <a href="#accessors-port">.port()</a></p>
|
817
|
+
|
818
|
+
<h3 id="normalize-port">normalizePort()</h3>
|
819
|
+
<p>Removes the port, if it's the default for the given protocol (http: 80, https: 443, ftp: 21).</p>
|
820
|
+
<p>The list of default ports can be modified at <code>URI.defaultPorts</code></p>
|
821
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://example.org:80/foo.html");
|
822
|
+
// normalize port
|
823
|
+
uri.normalizePort(); // returns the URI instance for chaining
|
824
|
+
// uri == "http://example.org/foo.html"</pre>
|
825
|
+
|
826
|
+
<h3 id="normalize-path">normalizePathname(), normalizePath()</h3>
|
827
|
+
<p>.normalizePath() is an alias of .normalizePathname(), they resolve relative hierarchies</p>
|
828
|
+
<pre class="prettyprint lang-js">var uri = new URI("/hello/foo/woo/.././../world.html");
|
829
|
+
// normalize path
|
830
|
+
uri.normalizePathname(); // returns the URI instance for chaining
|
831
|
+
// uri == "/hello/world.html"</pre>
|
832
|
+
|
833
|
+
<h3 id="normalize-search">normalizeSearch(), normalizeQuery()</h3>
|
834
|
+
<p>Turns <code>?&foo=bar&&foo=bar&foo=baz&</code> into <code>?foo=bar&foo=baz</code> and removes ? if there is no query string.</p>
|
835
|
+
<pre class="prettyprint lang-js">var uri = new URI("?&foo=bar&&foo=bar&foo=baz&");
|
836
|
+
// normalize search
|
837
|
+
uri.normalizeSearch(); // returns the URI instance for chaining
|
838
|
+
// uri == "?foo=bar&foo=baz"</pre>
|
839
|
+
|
840
|
+
<h3 id="normalize-hash">normalizeHash(), normalizeFragment()</h3>
|
841
|
+
<p>removes # if there is no hash</p>
|
842
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://example.org/foo/hello.html#");
|
843
|
+
// normalize hash
|
844
|
+
uri.normalizeHash(); // returns the URI instance for chaining
|
845
|
+
// uri == "http://example.org/bar/world.xml"</pre>
|
846
|
+
|
847
|
+
|
848
|
+
<h2 id="charsets">Charsets / Encodings</h2>
|
849
|
+
|
850
|
+
<h3 id="iso8859">iso8859()</h3>
|
851
|
+
<p>.iso8859() converts unicode-encoded escape sequences to ISO8859-encoded escape sequences. It does this by calling <a href="#normalize">.normalize()</a> internally.</p>
|
852
|
+
<pre class="prettyprint lang-js">var uri = new URI("/%C3%A4.html");
|
853
|
+
uri.iso8859(); // returns the URI instance for chaining
|
854
|
+
// uri == "/%E4.html"</pre>
|
855
|
+
<p>NOTE: You can make URI work with ISO8859 encoding by default by calling <a href="#static-iso8859">URI.iso8859()</a>.
|
856
|
+
|
857
|
+
<h3 id="unicode">unicode()</h3>
|
858
|
+
<p>.unicode() converts ISO8859-encoded escape sequences to unicode-encoded escape sequences. It does this by calling <a href="#normalize">.normalize()</a> internally.</p>
|
859
|
+
<pre class="prettyprint lang-js">var uri = new URI("/%E4.html");
|
860
|
+
uri.unicode(); // returns the URI instance for chaining
|
861
|
+
// uri == "/%C3%A4.html"</pre>
|
862
|
+
|
863
|
+
|
864
|
+
<h2 id="formatting">Formatting URLs</h2>
|
865
|
+
|
866
|
+
<h3 id="readable">readable()</h3>
|
867
|
+
<p>Formats URLs to be human readable (much like your browser does nowadays).</p>
|
868
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://foo:bar@www.xn--exmple-cua.org/"
|
869
|
+
+ "hello%20world/ä.html?foo%5B%5D=b+är#fragment");
|
870
|
+
|
871
|
+
uri.readable() === "http://www.exämple.org/"
|
872
|
+
+ "hello world/ä.html?foo[]=b är#fragment";</pre>
|
873
|
+
|
874
|
+
|
875
|
+
<h2 id="relative-and-absolute">Relative and Absolute URLs</h2>
|
876
|
+
|
877
|
+
<h3 id="relativeto">relativeTo()</h3>
|
878
|
+
<p>.relativeTo() compares two paths an makes one relative to the other</p>
|
879
|
+
<pre class="prettyprint lang-js">var uri = new URI("/relative/path");
|
880
|
+
// make path relative
|
881
|
+
var relUri = uri.relativeTo("/relative/sub/foo/sub/file"); // returns a new URI instance
|
882
|
+
// relUri == "../../../path"
|
883
|
+
|
884
|
+
// also works for relative directories
|
885
|
+
URI("../world.html").absoluteTo("foo/bar/baz.html");
|
886
|
+
// -> "foo/world.html"
|
887
|
+
|
888
|
+
// absolute URLs are passed through unchanged
|
889
|
+
URI("http://example.org/world.html")
|
890
|
+
.absoluteTo("http://google.com/baz");
|
891
|
+
// -> "http://example.org/world.html"
|
892
|
+
|
893
|
+
// absolute URLs relative to absolute URLs
|
894
|
+
URI("http://example.org/world.html").clone().authority("")
|
895
|
+
.absoluteTo("http://google.com/baz");
|
896
|
+
// -> "http://google.com/world.html"
|
897
|
+
|
898
|
+
// equal URLs are relative by empty string
|
899
|
+
URI("http://www.example.com:8080/dir/file")
|
900
|
+
.relativeTo('http://www.example.com:8080/dir/file')
|
901
|
+
.toString();
|
902
|
+
// -> ""
|
903
|
+
|
904
|
+
// relative on fragment and query string as well
|
905
|
+
URI("http://www.example.com:8080/dir/file?foo=bar#abcd")
|
906
|
+
.relativeTo('http://www.example.com:8080/dir/file')
|
907
|
+
.toString();
|
908
|
+
// -> "?foo=bar#abcd"</pre>
|
909
|
+
<p>.relativeTo() and .absoluteTo() reverse each other.</p>
|
910
|
+
|
911
|
+
<h3 id="absoluteto">absoluteTo()</h3>
|
912
|
+
<p>.absoluteTo() makes a relative path absolute based on another path</p>
|
913
|
+
<pre class="prettyprint lang-js">var uri = new URI("../../../path");
|
914
|
+
// make path absolute
|
915
|
+
var relUri = uri.absoluteTo("/relative/sub/foo/sub/file"); // returns a new URI instance
|
916
|
+
// relUri == "/relative/path"</pre>
|
917
|
+
<p>.relativeTo() and .absoluteTo() reverse each other.</p>
|
918
|
+
|
919
|
+
|
920
|
+
<h2 id="comparison">Comparing URLs</h2>
|
921
|
+
|
922
|
+
<h3 id="equals">equals()</h3>
|
923
|
+
<p>.equals() determines if the given URLs are the same - disregarding default ports, capitalization, dot-pathnames, query-parameter order, etc.</p>
|
924
|
+
<pre class="prettyprint lang-js">var a = "http://example.org/foo/bar.html"
|
925
|
+
+ "?foo=bar&hello=world&hello=mars#fragment",
|
926
|
+
b;
|
927
|
+
|
928
|
+
// normalizing URI before comparison:
|
929
|
+
b = "http://exAMPle.org:80/foo/../foo/bar.html"
|
930
|
+
+ "?foo=bar&hello=world&hello=mars#fragment";
|
931
|
+
|
932
|
+
a !== b;
|
933
|
+
URI(a).equals(b) === true;
|
934
|
+
|
935
|
+
|
936
|
+
// comparing query string parameters:
|
937
|
+
b = "http://example.org/foo/bar.html"
|
938
|
+
+ "?hello=mars&foo=bar&hello=world&#fragment";
|
939
|
+
|
940
|
+
a !== b;
|
941
|
+
URI(a).equals(b) === true;
|
942
|
+
|
943
|
+
// shorthand for comparing to window.location.href:
|
944
|
+
URI(a).equals();</pre>
|
945
|
+
|
946
|
+
|
947
|
+
<h2 id="parsing-urls">Parsing URLs</h2>
|
948
|
+
|
949
|
+
<h3 id="static-parse">URI.parse(<em>string</em> url)</h3>
|
950
|
+
<p>parses a string into its URI components. returns an object containing the found components</p>
|
951
|
+
<pre class="prettyprint lang-js">var result = URI.parse("http://example.org/foo.html");
|
952
|
+
result === {
|
953
|
+
protocol: "http",
|
954
|
+
username: null,
|
955
|
+
password: null,
|
956
|
+
hostname: "example.org",
|
957
|
+
port: null,
|
958
|
+
path: "/foo.html",
|
959
|
+
query: null,
|
960
|
+
fragment: null
|
961
|
+
};</pre>
|
962
|
+
|
963
|
+
<h3 id="static-parseAuthority">URI.parseAuthority(<em>string</em> url, <em>object</em> parts)</h3>
|
964
|
+
<p>parses a string's beginning into its URI components username, password, hostname, port.
|
965
|
+
Found components are appended to the <code>parts</code> parameter.
|
966
|
+
Remaining string is returned</p>
|
967
|
+
<pre class="prettyprint lang-js">var parts = {},
|
968
|
+
result = URI.parseAuthority("user:pass@example.org:8080/foo.html", parts);
|
969
|
+
result === "/foo.html";
|
970
|
+
parts === {
|
971
|
+
username: "user",
|
972
|
+
password: "pass",
|
973
|
+
hostname: "example.org",
|
974
|
+
port: "8080"
|
975
|
+
};</pre>
|
976
|
+
|
977
|
+
<h3 id="static-parseUserinfo">URI.parseUserinfo(<em>string</em> url, <em>object</em> parts)</h3>
|
978
|
+
<p>parses a string's beginning into its URI components username, password.
|
979
|
+
Found components are appended to the <code>parts</code> parameter.
|
980
|
+
Remaining string is returned</p>
|
981
|
+
<pre class="prettyprint lang-js">var parts = {},
|
982
|
+
result = URI.parseUserinfo("user:pass@example.org:8080/foo.html", parts);
|
983
|
+
result === "example.org:8080/foo.html";
|
984
|
+
parts === {
|
985
|
+
username: "user",
|
986
|
+
password: "pass"
|
987
|
+
};</pre>
|
988
|
+
|
989
|
+
<h3 id="static-parseHost">URI.parseHost(<em>string</em> url, <em>object</em> parts)</h3>
|
990
|
+
<p>parses a string's beginning into its URI components hostname, port.
|
991
|
+
Found components are appended to the <code>parts</code> parameter.
|
992
|
+
Remaining string is returned</p>
|
993
|
+
<pre class="prettyprint lang-js">var parts = {},
|
994
|
+
result = URI.parseAuthority("example.org:8080/foo.html", parts);
|
995
|
+
result === "/foo.html";
|
996
|
+
parts === {
|
997
|
+
hostname: "example.org",
|
998
|
+
port: "8080"
|
999
|
+
};</pre>
|
1000
|
+
|
1001
|
+
<h3 id="static-parseQuery">URI.parseQuery(<em>string</em> querystring)</h3>
|
1002
|
+
<p>Parses the passed query string into an object. Returns object <code>{propertyName: propertyValue}</code></p>
|
1003
|
+
<pre class="prettyprint lang-js">var result = URI.parseQuery("?foo=bar&hello=world&hello=mars&bam=&yup");
|
1004
|
+
result === {
|
1005
|
+
foo: "bar",
|
1006
|
+
hello: ["world", "mars"],
|
1007
|
+
bam: "",
|
1008
|
+
yup: null
|
1009
|
+
};</pre>
|
1010
|
+
|
1011
|
+
<h2 id="serializing-urls">Serializing URLs</h2>
|
1012
|
+
|
1013
|
+
<h3 id="static-build">URI.build(<em>object</em> parts)</h3>
|
1014
|
+
<p>serializes the URI components passed in <code>parts</code> into a URI string</p>
|
1015
|
+
<pre class="prettyprint lang-js">var parts = {
|
1016
|
+
protocol: "http",
|
1017
|
+
username: null,
|
1018
|
+
password: null,
|
1019
|
+
hostname: "example.org",
|
1020
|
+
port: null,
|
1021
|
+
path: "/foo.html",
|
1022
|
+
query: null,
|
1023
|
+
fragment: null
|
1024
|
+
};
|
1025
|
+
URI.build(parts) === "http://example.org/foo.html";</pre>
|
1026
|
+
|
1027
|
+
<h3 id="static-buildAuthority">URI.buildAuthority(<em>object</em> parts)</h3>
|
1028
|
+
<p>serializes the URI components username, password, hostname, port passed in <code>parts</code> into a URI string</p>
|
1029
|
+
<pre class="prettyprint lang-js">var parts = {
|
1030
|
+
username: "user",
|
1031
|
+
password: "pass",
|
1032
|
+
hostname: "example.org",
|
1033
|
+
port: "8080"
|
1034
|
+
};
|
1035
|
+
URI.buildAuthority(parts) === "user:pass@example.org:8080";</pre>
|
1036
|
+
|
1037
|
+
<h3 id="static-buildUserinfo">URI.buildUserinfo(<em>object</em> parts)</h3>
|
1038
|
+
<p>serializes the URI components username, password passed in <code>parts</code> into a URI string</p>
|
1039
|
+
<pre class="prettyprint lang-js">var parts = {
|
1040
|
+
username: "user",
|
1041
|
+
password: "pass"
|
1042
|
+
};
|
1043
|
+
URI.buildUserinfo(parts) === "user:pass@";</pre>
|
1044
|
+
|
1045
|
+
<h3 id="static-buildHost">URI.buildHost(<em>object</em> parts)</h3>
|
1046
|
+
<p>serializes the URI components hostname, port passed in <code>parts</code> into a URI string</p>
|
1047
|
+
<pre class="prettyprint lang-js">var parts = {
|
1048
|
+
hostname: "example.org",
|
1049
|
+
port: "8080"
|
1050
|
+
};
|
1051
|
+
URI.buildHost(parts) === "example.org:8080";</pre>
|
1052
|
+
|
1053
|
+
<h3 id="static-buildQuery">URI.buildQuery(<em>object</em> data, [<em>boolean</em> duplicateQueryParameters], [<em>boolean</em> escapeQuerySpace])</h3>
|
1054
|
+
<p>serializes the query string parameters</p>
|
1055
|
+
<pre class="prettyprint lang-js">var data = {
|
1056
|
+
foo: "bar",
|
1057
|
+
hello: ["world", "mars", "mars"],
|
1058
|
+
bam: "",
|
1059
|
+
yup: null,
|
1060
|
+
removed: undefined
|
1061
|
+
}
|
1062
|
+
|
1063
|
+
// Note: duplicate hello=mars is dropped (default behavior!)
|
1064
|
+
URI.buildQuery(data) === "foo=bar&hello=world&hello=mars&bam=&yup";
|
1065
|
+
|
1066
|
+
// Note: duplicate hello=mars is preserved
|
1067
|
+
URI.buildQuery(data, true) === "foo=bar&hello=world&hello=mars&hello=mars&bam=&yup";</pre>
|
1068
|
+
<p>To preserve duplicate values, use URI.buildQuery() directly:</p>
|
1069
|
+
<pre class="prettyprint lang-js">var uri = new URI("http://example.org/foo.html?bar=baz"),
|
1070
|
+
data = uri.query(true);
|
1071
|
+
|
1072
|
+
data.some = "new data";
|
1073
|
+
uri.query(URI.buildQuery(data, true));
|
1074
|
+
|
1075
|
+
// you can also use the static <a href="#static-addQuery">URI.addQuery()</a> and <a href="#static-removeQuery">URI.removeQuery()</a>
|
1076
|
+
URI.addQuery(data, "hello", "world");
|
1077
|
+
uri.query(URI.buildQuery(data, true));</pre>
|
1078
|
+
|
1079
|
+
<p id="setting-duplicateQueryParameters">As of v1.8.0 you can configure query parameter de/duplication:</p>
|
1080
|
+
<pre class="prettyprint lang-js">// make all new URI instances allow duplicates:
|
1081
|
+
URI.duplicateQueryParameters = true; // default is false
|
1082
|
+
|
1083
|
+
// make a specific URI instance allow duplicates:
|
1084
|
+
var withDuplicates = URI("?bar=1&bar=1")
|
1085
|
+
.duplicateQueryParameters(true)
|
1086
|
+
.normalizeQuery()
|
1087
|
+
.toString();
|
1088
|
+
|
1089
|
+
// make a specific URI instance avoid duplicates (default):
|
1090
|
+
var noDuplicates = URI("?bar=1&bar=1")
|
1091
|
+
.duplicateQueryParameters(false)
|
1092
|
+
.normalizeQuery()
|
1093
|
+
.toString();
|
1094
|
+
|
1095
|
+
withDuplicates === "?bar=1&bar=1";
|
1096
|
+
noDuplicates === "?bar=1";</pre>
|
1097
|
+
|
1098
|
+
<p id="setting-escapeQuerySpace">As of v1.11.0 you can configure query space en/decoding:</p>
|
1099
|
+
<pre class="prettyprint lang-js">// prevent all new URI instances from escaping spaces in query strings:
|
1100
|
+
URI.escapeQuerySpace = false; // default is true
|
1101
|
+
|
1102
|
+
// make a specific URI instance allow duplicates:
|
1103
|
+
var withPlus = URI("?bar=hello+world")
|
1104
|
+
.escapeQuerySpace(true)
|
1105
|
+
.query(true).bar;
|
1106
|
+
|
1107
|
+
// make a specific URI instance avoid duplicates (default):
|
1108
|
+
var withPercent = URI("?bar=hello%20world")
|
1109
|
+
.escapeQuerySpace(false)
|
1110
|
+
.query(true).bar;
|
1111
|
+
|
1112
|
+
withPlus === "hello world";
|
1113
|
+
withPercent === "hello world";</pre>
|
1114
|
+
|
1115
|
+
<h2 id="encoding-decoding">Encoding and Decoding URLs</h2>
|
1116
|
+
|
1117
|
+
<h3 id="static-encode">URI.encode()</h3>
|
1118
|
+
<p>Encode an URI component with strict compliance to RFC3986</p>
|
1119
|
+
<pre class="prettyprint lang-js">URI.encode("hä lo#w*rl:d!") === "h%C3%A4%20lo%23w%2Arl%3Ad%21";
|
1120
|
+
// vs.
|
1121
|
+
encodeURIComponent("hä lo#w*rl:d!") === "h%C3%A4%20lo%23w*rl%3Ad!";
|
1122
|
+
// not how * and ! were not encoded</pre>
|
1123
|
+
|
1124
|
+
<h3 id="static-decode">URI.decode()</h3>
|
1125
|
+
<p>Decode an URI component</p>
|
1126
|
+
<pre class="prettyprint lang-js">URI.encode("h%C3%A4%20lo%23w%2Arl%3Ad%21") === "hä lo#w*rl:d!";
|
1127
|
+
// note:
|
1128
|
+
URI.decode === decodeURIComponent;</pre>
|
1129
|
+
|
1130
|
+
<h3 id="static-encodeReserved">URI.encodeReserved()</h3>
|
1131
|
+
<p>Encode an URI component whilst preserving <a href="http://tools.ietf.org/html/rfc3986#section-2.2">reserved characters</a></p>
|
1132
|
+
<pre class="prettyprint lang-js">URI.encodeReserved("ä:/?#[]@!$&'()*+,;=") === "%C3%A4:/?#[]@!$&'()*+,;=";
|
1133
|
+
// vs.
|
1134
|
+
URI.encode("ä:/?#[]@!$&'()*+,;=") ===
|
1135
|
+
"%C3%A4%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D";</pre>
|
1136
|
+
|
1137
|
+
<h3 id="static-encodeQuery">URI.encodeQuery()</h3>
|
1138
|
+
<p>Decode a query string component. Works like <a href="#static-encode">encode()</a>, except it handles <code>%20</code> as <code>+</code> (space).</p>
|
1139
|
+
<pre class="prettyprint lang-js">URI.encodeQuery(" ") === "+";
|
1140
|
+
// vs.
|
1141
|
+
URI.encode(" ") === "%20";</pre>
|
1142
|
+
|
1143
|
+
<h3 id="static-decodeQuery">URI.decodeQuery()</h3>
|
1144
|
+
<p>Decode a query string component. Works like <a href="#static-decode">decode()</a>, except it handles <code>+</code> as <code>%20</code> (space).</p>
|
1145
|
+
<pre class="prettyprint lang-js">URI.decodeQuery("+") === " ";
|
1146
|
+
// vs.
|
1147
|
+
URI.decode("+") === "+";</pre>
|
1148
|
+
|
1149
|
+
|
1150
|
+
<h2 id="static-functions">Static Helper Functions</h2>
|
1151
|
+
|
1152
|
+
<h3 id="static-noConflict">URI.noConflict()</h3>
|
1153
|
+
<p>removes URI variables from global scope</p>
|
1154
|
+
<pre class="prettyprint lang-js">// restores window.URI to its previous state and returns URI
|
1155
|
+
URI.noConflict();
|
1156
|
+
// restores the global variable to its previous state and returns the object itself
|
1157
|
+
URITemplate.noConflict();
|
1158
|
+
IPv6.noConflict();
|
1159
|
+
SecondLevelDomains.noConflict();
|
1160
|
+
|
1161
|
+
// restore all objects and return them as a map {URI: ..., IPv6: ..., ....}
|
1162
|
+
URI.noConflict(true);</pre>
|
1163
|
+
|
1164
|
+
<h3 id="static-addQuery">URI.addQuery()</h3>
|
1165
|
+
<p>adds data to a map</p>
|
1166
|
+
<pre class="prettyprint lang-js">var data = {};
|
1167
|
+
|
1168
|
+
URI.addQuery(data, "hello", "mars");
|
1169
|
+
data === {hello: "mars"};
|
1170
|
+
|
1171
|
+
URI.addQuery(data, "hello", "world");
|
1172
|
+
data === {hello: ["mars", "world"]};
|
1173
|
+
|
1174
|
+
URI.addQuery(data, {foo: "bar", goodbye : ["world", "mars"]});
|
1175
|
+
data === {hello: ["mars", "world"], foo: "bar", goodbye : ["world", "mars"]};</pre>
|
1176
|
+
|
1177
|
+
<h3 id="static-removeQuery">URI.removeQuery()</h3>
|
1178
|
+
<p>removes data from a map</p>
|
1179
|
+
<pre class="prettyprint lang-js">var data === {hello: ["mars", "world"], foo: "bar", goodbye : ["world", "mars"]};
|
1180
|
+
|
1181
|
+
URI.removeQuery(data, "hello");
|
1182
|
+
data === {foo: "bar", goodbye : ["world", "mars"]};
|
1183
|
+
|
1184
|
+
// remove an attribute with value filter
|
1185
|
+
data = {hello: ["world", "mars"], foo: "bar"};
|
1186
|
+
URI.removeQuery(data, "hello", "world");
|
1187
|
+
data === {hello: ["mars"], foo: "bar"} // yes, still an array
|
1188
|
+
|
1189
|
+
// remove multiple values
|
1190
|
+
data = {hello: ["world", "mars"], foo: "bar", mine: "true"}
|
1191
|
+
URI.removeQuery(["hello", "foo"]);
|
1192
|
+
data === {mine: "true"};
|
1193
|
+
|
1194
|
+
// remove multiple values with value filter
|
1195
|
+
data = {hello: ["world", "mars"], foo: "bar", mine: "true", a: ["1", "2", "3"]}
|
1196
|
+
URI.removeQuery({hello: "world", foo: undefined, a: ["1", "3"]});
|
1197
|
+
data === {hello: ["mars"], mine: "true", a: ["2"]}</pre>
|
1198
|
+
|
1199
|
+
<h3 id="static-commonPath">URI.commonPath()</h3>
|
1200
|
+
<p>URI.commonPath() determines the common base directory of two paths.</p>
|
1201
|
+
<pre class="prettyprint lang-js">URI.commonPath("/foo/bar/baz.html", "/foo/bar/world.html");
|
1202
|
+
// returns "/foo/bar/"
|
1203
|
+
|
1204
|
+
URI.commonPath("/foo/bar/baz.html", "/foo/bazz/world.html");
|
1205
|
+
// returns "/foo/"
|
1206
|
+
|
1207
|
+
URI.commonPath("/foo/bar/baz.html", "/other/world.html");
|
1208
|
+
// returns "/"
|
1209
|
+
|
1210
|
+
URI.commonPath("/foo", "bar");
|
1211
|
+
// returns ""</pre>
|
1212
|
+
|
1213
|
+
<h3 id="static-withinString">URI.withinString()</h3>
|
1214
|
+
<p>URI.withinString() identifies URIs within text, e.g. to translate them to <a>-Tags. (Obviously you'd want to put the urls inside the href-Attribute and escape them properly…)</p>
|
1215
|
+
<pre class="prettyprint lang-js">var source = "Hello www.example.com,\n"
|
1216
|
+
+ "http://google.com is a search engine, like http://www.bing.com\n"
|
1217
|
+
+ "http://exämple.org/foo.html?baz=la#bumm is an IDN URL,\n"
|
1218
|
+
+ "http://123.123.123.123/foo.html is IPv4 and "
|
1219
|
+
+ "http://fe80:0000:0000:0000:0204:61ff:fe9d:f156/foobar.html is IPv6.\n"
|
1220
|
+
+ "links can also be in parens (http://example.org) "
|
1221
|
+
+ "or quotes »http://example.org«.";
|
1222
|
+
|
1223
|
+
var result = URI.withinString(source, function(url) {
|
1224
|
+
// callback needs to return a string
|
1225
|
+
// feel free to URI(url).normalize().toString() or something
|
1226
|
+
return "<a>" + url + "</a>";
|
1227
|
+
});
|
1228
|
+
|
1229
|
+
/* result is:
|
1230
|
+
Hello <strong><a>www.example.com</a></strong>,
|
1231
|
+
<strong><a>http://google.com</a></strong> is a search engine, like <strong><a>http://www.bing.com</a></strong>
|
1232
|
+
<strong><a>http://exämple.org/foo.html?baz=la#bumm</a></strong> is an IDN URL,
|
1233
|
+
<strong><a>http://123.123.123.123/foo.html</a></strong> is IPv4 and <strong><a>http://fe80:0000:0000:0000:0204:61ff:fe9d:f156/foobar.html</a></strong> is IPv6.
|
1234
|
+
links can also be in parens (<strong><a>http://example.org</a></strong>) or quotes »<strong><a>http://example.org</a></strong>«.
|
1235
|
+
*/
|
1236
|
+
|
1237
|
+
// a proper replacement could look like the following:
|
1238
|
+
var escapeHtml = function(string) {
|
1239
|
+
return string
|
1240
|
+
.replace(/&/g, "&amp;")
|
1241
|
+
.replace(/</g, "&lt;")
|
1242
|
+
.replace(/>/g, "&gt;")
|
1243
|
+
.replace(/"/g, "&quot;");
|
1244
|
+
}
|
1245
|
+
result = URI.withinString(source, function(url) {
|
1246
|
+
var uri = new URI(url);
|
1247
|
+
uri.normalize();
|
1248
|
+
return "<a href="" + escapeHtml(uri) + "">"
|
1249
|
+
+ escapeHtml(url.<a href="#readable">readable</a>()) + "</a>";
|
1250
|
+
});
|
1251
|
+
</pre>
|
1252
|
+
|
1253
|
+
<h3 id="static-iso8859">URI.iso8859()</h3>
|
1254
|
+
<p>URI.iso8859() tells URI.js to use the older escape/unescape methods, for backwards compatibility with non-unicode platforms.</p>
|
1255
|
+
<pre class="prettyprint lang-js">URI.iso8859();
|
1256
|
+
|
1257
|
+
var uri = new URI("http://example.org/foo/æ.html");
|
1258
|
+
// http://example.org/foo/%E6.html</pre>
|
1259
|
+
|
1260
|
+
<h3 id="static-unicode">URI.unicode()</h3>
|
1261
|
+
<p>URI.unicode() restores the default unicode-encoded URLs.</p>
|
1262
|
+
<pre class="prettyprint lang-js">URI.unicode();
|
1263
|
+
|
1264
|
+
var uri = new URI("http://example.org/foo/æ.html");
|
1265
|
+
// http://example.org/foo/%C3%A6.html</pre>
|
1266
|
+
|
1267
|
+
<h3 id="static-expand">URI.expand()</h3>
|
1268
|
+
<p>URI.expand() is a convenience wrapper for <a href="uri-template.html"><code>URITemplate</code></a>.
|
1269
|
+
While <code>URITemplate#expand</code> returns a string, <code>URI.expand()</code> returns an <code>URI</code> instance.</p>
|
1270
|
+
<pre class="prettyprint lang-js">URI.expand("/foo/{var}/{iable}", {
|
1271
|
+
"var": "bar",
|
1272
|
+
"iable": "hello world.html"
|
1273
|
+
});
|
1274
|
+
|
1275
|
+
// returns URI("/foo/bar/hello%20world.html")</pre>
|
1276
|
+
|
1277
|
+
|
1278
|
+
</div>
|
1279
|
+
</body>
|
1280
|
+
</html>
|