predictype

predictype v0.13.0


predictype / predicates/urls/urlOrigin / urlOrigin

Function: urlOrigin()

urlOrigin(source, oper, target): boolean

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

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

Parameters

source

URL

The URL to inspect.

oper

UrlOriginOper

The origin operation to perform (e.g. ‘equals’, ‘starts_with’).

target

string

The string to compare against source.origin.

Returns

boolean

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

Throws

If the operation is not recognized.

Example

const source = new URL('https://api.example.com:8443/v1/users');
const targetA = 'https://api.example.com:8443';
const targetB = 'https://api.';

urlOrigin(source, 'equals', targetA); // true
urlOrigin(source, 'starts_with', targetB); // true

Remarks

Supported Operators: