predictype

predictype v0.13.0


predictype / predicates/urls/urlHref / urlHref

Function: urlHref()

urlHref(source, oper, target): boolean

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

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

Parameters

source

URL

The URL to inspect.

oper

UrlHrefOper

The href operation to perform (e.g. ‘equals’, ‘includes’).

target

string

The string to compare against source.href.

Returns

boolean

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

Throws

If the operation is not recognized.

Example

const source = new URL('https://docs.example.com:443/path?q=1#intro');
const targetA = 'https://docs.example.com/path?q=1#intro';
const targetB = 'docs.example.com';

urlHref(source, 'equals', targetA); // true
urlHref(source, 'includes', targetB); // true

Remarks

Supported Operators: