Table of Contents

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

ParameterTypeDescription
options
Required
ObjectThe 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

ParameterTypeDescription
routeInfo
Required
ObjectThe Route information object. Has the following keys:
“href”StringThe whole URL.
“protocol”StringThe protocol part of the URL.
“username”StringThe username part of the URL.
“password”StringThe password part of the URL.
“host”StringThe host part of the URL. Can include a port.
“hostname”StringThe host part of the URL. Can not include a port.
“port”StringThe port part of the URL.
“pathname”StringThe path part of the URL.
“search”StringThe query part of the URL.
“hash”StringThe hash part of the URL.
“queryParameters”ObjectThe query part of the URL that is converted to an object.
optionsObjectOptions. Has the following keys:
“mergeParameters”StringIf 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

ParameterTypeDescription
urlStringThe 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:

KeyTypeDescription
“href”StringThe whole URL.
“protocol”StringThe protocol part of the URL.
“username”StringThe username part of the URL.
“password”StringThe password part of the URL.
“host”StringThe host part of the URL. If a port is specified, the port is also included.
“hostname”StringThe host part of the URL. A port is not included.
“port”StringThe port part of the URL.
“pathname”StringThe path part of the URL.
“path”StringThe path part of the URL without the filename part.
“search”StringThe query part of the URL.
“searchParams”URLSearchParamsThe query part of the URL.
“query”StringThe query part of the URL.
“hash”StringThe hash part of the URL.
“filename”StringThe filename part of the URL.
“filenameWithoutExtension”StringThe filename part of the URL without extension.
“extension”StringThe filename extension part of the URL.
“queryParameters”ObjectThe query part of the URL, converted to an object.

Parameters

ParameterTypeDescription
urlStringThe target URL. If not specified, the current URL will be used.

Return Value

URL information object.