predictype / predicates/urls / urlPathname
urlPathname(
source,oper,target):boolean
Defined in: predicates/urls/urlPathname.ts:30
Checks the pathname component of a URL against a string operation.
URL
The URL to inspect.
The pathname operation to perform (e.g. ‘starts_with’, ‘includes’).
string
The string to compare against source.pathname.
boolean
True if the pathname comparison is valid according to the operator, otherwise false.
If the operation is not recognized.
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
Supported Operators: