predictype

predictype v0.13.0


predictype / predicates/urls / urlPathname

Function: urlPathname()

urlPathname(source, oper, target): boolean

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

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

Parameters

source

URL

The URL to inspect.

oper

UrlPathnameOper

The pathname operation to perform (e.g. ‘starts_with’, ‘includes’).

target

string

The string to compare against source.pathname.

Returns

boolean

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

Throws

If the operation is not recognized.

Example

const source = new URL('https://example.com/products/books/42');
const targetA = '/products';
const targetB = '/42';

urlPathname(source, 'starts_with', targetA); // true
urlPathname(source, 'ends_with', targetB); // true

Remarks

Supported Operators: