I would like to take a string
var a = \"http://example.com/aa/bb/\"
and process it into an object such that
a.hostname == \
var loc = window.location; // => "http://example.com:3000/pathname/?search=test#hash"
returns the currentUrl.
If you want to pass your own string as a url (doesn't work in IE11):
var loc = new URL("http://example.com:3000/pathname/?search=test#hash")
Then you can parse it like:
loc.protocol; // => "http:"
loc.host; // => "example.com:3000"
loc.hostname; // => "example.com"
loc.port; // => "3000"
loc.pathname; // => "/pathname/"
loc.hash; // => "#hash"
loc.search; // => "?search=test"