-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (37 loc) · 943 Bytes
/
index.js
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
var URI = require('URIjs');
var URL = function (url, base) {
var uri = URI(url);
if (typeof base === 'string') {
uri = uri.absoluteTo(base);
}
var url = Object.create(URL.prototype);
Object.defineProperty(url, 'origin', {
get: function () {
return uri.protocol() + '://' + uri.host();
}
});
Object.defineProperty(url, 'protocol', {
get: function () {
return uri.protocol() + ':';
}
});
'hash host hostname href password pathname port search username'
.split(/\s+/)
.forEach(function (property) {
Object.defineProperty(url, property, {
get: function () {
return uri[property]();
},
set: function (value) {
uri[property](value);
return uri[property]();
}
});
});
url.prototype = this.prototype;
return url;
};
URL.prototype.toString = function () {
return this.href;
};
module.exports = URL;