createElement() with javascript enables you to have all the necessary properties easily
Below example shows the reference to get protocol, host, hostname, port, pathname, hash, search and its origin.
pathinfo = function(url) { a = document.createElement('a'); a.href = url; return a; } parser = pathinfo( "https://test.com:8080/pathname/?param=foo#hash"); parser.protocol; // => "https:" parser.host; // => "test.com:8080" parser.hostname; // => "test.com" parser.port; // => "8080" parser.pathname; // => "/pathname/" parser.hash; // => "#hash" parser.search; // => "?param=foo" parser.origin; // => "https://test.com:8080"