-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathparseuri.js
More file actions
78 lines (65 loc) · 2.33 KB
/
parseuri.js
File metadata and controls
78 lines (65 loc) · 2.33 KB
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
;(function(yam, undefined) {
// This is the yammer fork of parseuri.js.
// Any changes MUST BE IMMEDIATELY pushed back upstream, as this will be
// copy pasted over.
// To prevent jsmin from removing copyright, /*! */ is added.
// =============== BEGIN parseUri =========================
/*!
// a node.js module fork of
// parseUri 1.2.2
// (c) Steven Levithan <stevenlevithan.com>
// MIT License
// see: http://blog.stevenlevithan.com/archives/parseuri
// see: http://stevenlevithan.com/demo/parseuri/js/
*/
function parseUri (str) {
var o = parseUri.options,
m = o.parser[o.strictMode ? "strict" : "loose"].exec(str||''),
uri = {},
i = o.key.length;
while (i--) uri[o.key[i]] = m[i] || "";
uri[o.q.name] = {};
uri["query"].replace(o.q.parser, function ($0, $1, $2) {
if ($1) uri[o.q.name][$1] = $2;
});
return uri;
};
parseUri.options = {
strictMode: false,
key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
q: {
name: "queryKey",
parser: /(?:^|&)([^&=]*)=?([^&]*)/g
},
parser: {
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
}
};
// =========== END parseUri ===========
yam.ns('yam.uri');
/**
* Parse a URI string into an object with keys representing the relevant parts.
* See parseUri
* @param String The uri to parse
*/
yam.uri.parse = parseUri
/**
* Join the parts of an object created by yam.uri.parse into a valid uri. This is
* not guaranteed to work with custom objects. Also, if you have not modified the
* parsed object, just use uriObj.source which contains the original string.
* @param Object an object returned from yam.uri.parse
*/
yam.uri.stringify = function(uriObj) {
var keys = parseUri.options.key
uri = '';
for(var i = 0, len = keys.length; i < len; i++) {
// For the query, use the queryKey object because it may have been modified
if(keys[i] === 'query') {
uri += yam.paramify( uriObj['queryKey'] );
} else {
uri += uriObj[ keys[i] ];
}
}
}
})(yam);