Module: url

Classes

URLRequest
URLInfo

Members

(inner) domainsCache :Map.<string, Map.<string, boolean>>

Cache of domain maps.

The domains part of filter text (e.g. example.com,~mail.example.com) is often repeated across filters. This cache enables deduplication of the Map objects that specify on which domains the filter does and does not apply, which reduces memory usage and improves performance.

Type:
  • Map.<string, Map.<string, boolean>>
Source:

Methods

(generator, package, static) domainSuffixes(domain, includeBlankopt) → {string}

Yields all suffixes for a domain.

For example, given the domain www.example.com, this function yields www.example.com, example.com, and com, in that order.

If the domain ends with a dot, the dot is ignored.

Parameters:
Name Type Attributes Description
domain string

The domain.

includeBlank boolean <optional>

Whether to include the blank suffix at the end.

Source:
Yields:
The next suffix for the domain.
Type
string

(package, static) getBaseDomain(hostname) → {string}

Gets the base domain for the given hostname.

Parameters:
Name Type Description
hostname string
Source:
Returns:
Type
string

(package, static) isLocalhost(hostname) → {boolean}

Checks whether the given hostname refers to localhost.

If the hostname is localhost, 127.0.0.1, or [::1], the function returns true; otherwise, it returns false.

Parameters:
Name Type Description
hostname string

The hostname.

Source:
Returns:

Whether the hostname refers to localhost.

Type
boolean

(static) isValidHostname(hostname) → {boolean}

Checks whether a given hostname is valid.

This function is used for filter validation.

A hostname occurring in a filter must be normalized. For example, 🙂 (slightly smiling face) should be normalized to xn--938h; otherwise this function returns false for such a hostname. Similarly, IP addresses should be normalized.

Parameters:
Name Type Description
hostname string

The hostname to check.

Source:
Returns:

Whether the hostname is valid.

Type
boolean

(package, static) parseDomains(source, separator) → (nullable) {Map.<string, boolean>}

Parses the domains part of a filter text (e.g. example.com,~mail.example.com) into a Map object.

Parameters:
Name Type Description
source string

The domains part of a filter text.

separator string

The string used to separate two or more domains in the domains part of a filter text.

Source:
Returns:
Type
Map.<string, boolean>

(static) parseURL(url) → {module:url~URLInfo}

Parses a URL to extract the protocol and the hostname.

This is a lightweight alternative to the native URL object intended for use primarily within Adblock Plus. Unlike the URL object, the parseURL() function is not robust and will give incorrect results for invalid URLs. Use this function with valid, normalized, properly encoded (IDNA, etc.) URLs only.

Parameters:
Name Type Description
url string

The URL.

Source:
Returns:

Information about the URL.

Type
module:url~URLInfo

(inner) isIPAddress(hostname) → {boolean}

Checks whether the given hostname is an IP address.

Unlike isValidIPv4Address(), this function only checks whether the hostname looks like an IP address. Use this function with valid, normalized, properly encoded (IDNA) hostnames only.

Parameters:
Name Type Description
hostname string

An IDNA-encoded hostname.

Source:
Returns:

Whether the hostname is an IP address.

Type
boolean

(inner) isThirdParty(requestHostname, documentHostname) → {boolean}

Checks whether a request's origin is different from its document's origin.

Parameters:
Name Type Description
requestHostname string

The IDNA-encoded hostname of the request.

documentHostname string

The IDNA-encoded hostname of the document.

Source:
Returns:
Type
boolean

(inner) isValidIPv4Address(address) → {boolean}

Checks whether a given address is a valid IPv4 address.

Only a normalized IPv4 address is considered valid. e.g. 0x7f.0x0.0x0.0x1 is invalid, whereas 127.0.0.1 is valid.

Parameters:
Name Type Description
address string

The address to check.

Source:
Returns:

Whether the address is a valid IPv4 address.

Type
boolean