The following module handles parsing a URL in JavaScript. If this script is run outside of a browser, where the DOM is inaccessible, a regular expression will be executed to parse the provided URL.
{
"protocol": "https:",
"host": "www.example.org:5887",
"hostname": "www.example.org",
"port": "5887",
"pathname": "/foo/bar",
"search": "?a=1&b=-2",
"hash": "section-1",
"href": "https://www.example.org:5887/foo/bar?a=1&b=-2#section-1",
"requestUri": "/foo/bar?a=1&b=-2",
"parameters": {
"a": 1,
"b": -2
}
}
ftp://www.files.com:22/folder?version=2.31&type=doc
{
"protocol": "ftp:",
"host": "www.files.com:22",
"hostname": "www.files.com",
"port": "22",
"pathname": "/folder",
"search": "?version=2.31&type=doc",
"hash": "",
"href": "ftp://www.files.com:22/folder?version=2.31&type=doc",
"requestUri": "/folder?version=2.31&type=doc",
"parameters": {
"version": 2.31,
"type": "doc"
}
}