predictype

predictype v0.13.0


predictype / predicates/urls/urlHostname / urlHostname

Function: urlHostname()

urlHostname(source, oper, target): boolean

Defined in: predicates/urls/urlHostname.ts:30

Checks the hostname component of a URL against a string operation.

Parameters

source

URL

The URL to inspect.

oper

UrlHostnameOper

The hostname operation to perform (e.g. ‘equals’, ‘excludes’).

target

string

The string to compare against source.hostname.

Returns

boolean

True if the hostname comparison is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example

const source = new URL('https://blog.example.com/posts');
const targetA = 'blog.example.com';
const targetB = 'internal';

urlHostname(source, 'equals', targetA); // true
urlHostname(source, 'excludes', targetB); // true

Remarks

Supported Operators: