Node Module & Browser Library for parsing, formatting and serializing URLs
In the browser, you can use UrlTool
to access urltool
However in node.js, you have to use require('urltool')
to access urltool
This class is used to parse and format URLs.
const url = new UrlTool.Url('http://example.com/path/to/file.html?param=value#hash')
Format the URL.
url.format()
You can use custom templates by passing it as an argument. The default template is: {protocol}://{host}/{path}/{query}{hash}
. Available properties are protocol
, host
, path
, query
, hostWithoutPort
, port
and hash
.
The protocol of the URL.
e.g.: http
The host of the URL.
If the port isn't the default port for the given protocol, it will be included.
e.g.: example.com
, example.com:8080
The host of the URL ALWAYS without the port.
e.g.: example.com
The port of the URL.
e.g.: 80
The path of the URL.
e.g.: /path/to/file.html
The query of the URL.
e.g.: ?param=value
The hash of the URL.
e.g.: #hash
Parse a querystring into an object.
UrlTool.parseQuerystring('param=value¶m2=value2') // { param: 'value', param2: 'value2' }
Stringify a query object into a querystring.
UrlTool.stringifyQuerystring({ param: 'value', param2: 'value2' }) // 'param=value¶m2=value2'