-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME
128 lines (104 loc) · 5.81 KB
/
README
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
jquery.uri(uriString) - A JQuery plugin for inspecting and manipulating a URI or a URL.
Typical usage example:
var uri = $.uri(window.location.href);
// Assuming current url is "http://api.jquery.com"
var newUri = uri.at({path: "main/index.html", query: { format: "xml" }};
window.location.replace(newUri);
// Will forward the browser to "http://api.jquery.com/main/index.html?format=xml"
Parameters: uriString - Input string
Returns: An immutable object, providing the following methods:
- at: function(part)
Return the value of the specified URI part. part can be any one
of the following strings: "protocol", "domain", "port", "path", "query",
"fragment". Any other value yields an exception.
The "query" part returns an object that maps parameter names to their values,
as specified by at the query part of the URI. All names and values are
decoded via decodeURIComponent(). A "defensive getter" semantics is used so
the returned object can be subsequently mutated by the caller without
affecting this.
Example:
var uri = $.uri('http://jquery.com:8080/main/index.html?format=json#top');
assert uri.at('protocol') == 'http'
assert uri.at('domain') == 'jquery.com'
assert uri.at('port') == '8080'
assert uri.at('path') == 'main/index.html'
assert uri.at('query') == { 'format': 'json' }
assert uri.at('fragment') == 'top'
- at: function(part, value)
Set the value of a URI part.
Returns a new instance similar to this one except that the specified URI
part is now set to value. The receiving object is unchanged. part can
be any one of the following strings: "protocol", "domain", "port", "path",
"query", "fragment". Any other value yields an exception.
Example:
var uri = $.uri('http://api.jquery.com:8080/main/index.html?format=json');
uri = uri.at('port', '2020').at('path', 'welcome.html');
assert uri.at('port') == '2020'
assert uri.at('path') == 'welcome.html'
if part == "query" then value should be an object. Properties of this object
provide new name,value mapping for the "query" part at the returned object.
A new mapping will override an existing mapping (with the same name). Existing
mapping that were not overridden will be available in the new instance. A
"defensive setter" semantics is used so value can be subsequently mutated
by the caller without affecting this.
Example:
var uri = $.uri('http://api.jquery.com?a=1&b=2');
uri = uri.at('query', { b:200, c:300 });
assert uri.at('query').a == 1;
assert uri.at('query').b == 200;
assert uri.at('query').c == 300;
- at: function(object)
Set the values of several URI parts and/or query parameters.
Returns a new instance similar to this one except that all name,value
mappings specified by the parameter are applied the new instance
in a manner similar to at(name,value). The receiving object is unchanged.
A "defensive setter" semantics is used so object can be subsequently mutated
by the caller without affecting this.
Example:
var uri = $.uri('http://api.jquery.com:8080/main/index.html?format=json');
uri = uri.at({ port: '2020', path: 'welcome.html' });
assert uri.at('port') == '2020'
assert uri.at('path') == 'welcome.html'
If object.query is defined, then the query part of the result is the same
as if .at("query", object.query) were called.
Example:
var uri = $.uri('http://api.jquery.com?a=1&b=2');
uri = uri.at({ query: { b:200, c:300 }});
assert uri.at('query').a == 1;
assert uri.at('query').b == 200;
assert uri.at('query').c == 300;
- toString([compareFunction])
Return a well-formed URL representing this object.
Unspecified components (e.g., if .at('port') == '') do not appear at the result.
Names and value of parameters at the query part are encoded via encodeURIComponent().
Caller can pass an optional compareFunction to affect the order of parameters
at the query part of the result. If compareFunction is not specified, order is
undefined.
parameter: compareFunction
A function taking two arguments, a and b, each of which is an object
with two properties - name, value - representing a query parameter.
Returns
-1 if a should appear before b,
+1 if a should appear after b,
0 otherwise.
- retain(name1, name2, ...)
Keep the specified query parmas, discard all others.
Return a new instance similar to this one except that its query
part contains only the params whose names are specified by name1, name2,
etc. All other params are discarded from the result. The receiving object
is unchanged.
Example:
var uri = $.uri('http://api.jquery.com?a=1&b=2&c=3&d=4');
assert uri.retain('b', 'c').at('query') == { b:2, c: 3 }
- defaults(anObject)
Provide defaults for query parameters.
Properties of anObject provide new name,value mappings for the query part
of the returned object. A mapping will be ignored if an existing parameter
(with the same name) is already defined.
The receiving object is unchanged.
Example:
var uri = $.uri('http://api.jquery.com?a=1&b=2');
uri = uri.at({ query: { b:200, c:300 }});
assert uri.at('query').a == 1;
assert uri.at('query').b == 2;
assert uri.at('query').c == 300;