predictype

predictype v0.13.0


predictype / predicates/urls/urlProtocol / urlProtocol

Function: urlProtocol()

urlProtocol(source, oper, target): boolean

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

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

Parameters

source

URL

The URL to inspect.

oper

UrlProtocolOper

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

target

string

The string to compare against source.protocol.

Returns

boolean

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

Throws

If the operation is not recognized.

Example

const source = new URL('https://example.com/docs');
const targetA = 'https:';
const targetB = 'http';

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

Remarks

Supported Operators: