url-parse-utility
Version:
A simple RegEx based utility for parsing each part of the URL. This would help to get the different constituents of the URL.
60 lines (44 loc) • 1.13 kB
JavaScript
var url = require('url');
function URL(urlString){
this.url=urlString;
}
URL.prototype.getProtocol = function(){
return url.parse(this.url).protocol;
}
URL.prototype.getSlashes = function(){
return url.parse(this.url).slashes;
}
URL.prototype.getAuth = function(){
return url.parse(this.url).auth;
}
URL.prototype.getHost = function(){
return url.parse(this.url).host;
}
URL.prototype.getPort = function(){
return url.parse(this.url).port;
}
URL.prototype.getHostname = function(){
return url.parse(this.url).hostname;
}
URL.prototype.getHash = function(){
return url.parse(this.url).hash;
}
URL.prototype.getSearch = function(){
return url.parse(this.url).search;
}
URL.prototype.getQuery = function(){
return url.parse(this.url).query;
}
URL.prototype.getPathname = function(){
return url.parse(this.url).pathname;
}
URL.prototype.getPath = function(){
return url.parse(this.url).path;
}
URL.prototype.getHref = function(){
return url.parse(this.url).href;
}
URL.prototype.getParsedObject = function(){
return url.parse(this.url);
}
module.exports = URL;