URLUtil
Overview
URLUtil is a utility class that performs URL-related tasks.
Methods
buildQuery(options)
Type:String
Static
Generates the query part of a URL from the object given in the argument. Each key and value is URLEncoded. If an item in the options is an array, each element is concatenated with a comma.
Parameters
Parameter | Type | Description |
---|---|---|
options Required | Object | The URL query parameter object. |
Return Value
Returns the URL query string. If the query string is not empty, a leading ? is prepended to the query string.
buildURL(routeInfo, options)
Type:String
Static
Generates a URL based on the specified route information object.
First, “href” is used as a whole URL if the “href” key exists in the route info object, otherwise “pathname” and the current base URL (document.baseURI) are used to generate a URL. “pathname” can be either an absolute or a relative path. If neither “href” or “pathname” exists in the route info object, the current URL is used.
Then, if any of the following, “protocol”, “username”, “password”, “host”, “hostname”, “port”, “search” or “hash” are included in the route info object, the URL is modified by those parameters.
Finally, if the route info object includes the “queryParameters”, the query part of the URL is overwritten by the query generated by “queryParameters”. If the “mergeParameters” option is set to True, the query part is merged into the current URL's query parameters.
Parameters
Parameter | Type | Description |
---|---|---|
routeInfo Required | Object | The Route information object. Has the following keys: |
“href” | String | The whole URL. |
“protocol” | String | The protocol part of the URL. |
“username” | String | The username part of the URL. |
“password” | String | The password part of the URL. |
“host” | String | The host part of the URL. Can include a port. |
“hostname” | String | The host part of the URL. Can not include a port. |
“port” | String | The port part of the URL. |
“pathname” | String | The path part of the URL. |
“search” | String | The query part of the URL. |
“hash” | String | The hash part of the URL. |
“queryParameters” | Object | The query part of the URL that is converted to an object. |
options | Object | Options. Has the following keys: |
“mergeParameters” | String | If true, merges the generated query into the current URL query. |
Return Value
The generated URL.
loadParameters(url)
Type:Object
Static
Converts the query part of the specified URL into a Javascript object.
Parameters
Parameter | Type | Description |
---|---|---|
url | String | The target URL. If not specified, the current URL is used. |
Return Value
The query object.
parseURL(url)
Type:Object
Static
Returns the object that decomposes the given URL. The object has the following information:
Key | Type | Description |
---|---|---|
“href” | String | The whole URL. |
“protocol” | String | The protocol part of the URL. |
“username” | String | The username part of the URL. |
“password” | String | The password part of the URL. |
“host” | String | The host part of the URL. If a port is specified, the port is also included. |
“hostname” | String | The host part of the URL. A port is not included. |
“port” | String | The port part of the URL. |
“pathname” | String | The path part of the URL. |
“path” | String | The path part of the URL without the filename part. |
“search” | String | The query part of the URL. |
“searchParams” | URLSearchParams | The query part of the URL. |
“query” | String | The query part of the URL. |
“hash” | String | The hash part of the URL. |
“filename” | String | The filename part of the URL. |
“filenameWithoutExtension” | String | The filename part of the URL without extension. |
“extension” | String | The filename extension part of the URL. |
“queryParameters” | Object | The query part of the URL, converted to an object. |
Parameters
Parameter | Type | Description |
---|---|---|
url | String | The target URL. If not specified, the current URL will be used. |
Return Value
URL information object.