predictype

predictype v0.13.0


predictype / predicates/urls / urlState

Function: urlState()

urlState(source, oper): boolean

Defined in: predicates/urls/urlState.ts:36

Checks state flags of a URL (presence and protocol checks).

Parameters

source

URL

The URL to inspect.

oper

UrlStateOper

The state operation to perform (e.g. ‘has_hash’, ‘is_https’).

Returns

boolean

True if the state check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example

const source = new URL('https://user:pass@example.com:8443/docs?q=1#intro');

urlState(source, 'has_hash'); // true
urlState(source, 'has_search'); // true
urlState(source, 'has_port'); // true
urlState(source, 'is_https'); // true

Remarks

Supported Operators: