Type guard to check if a value is a URL object.
Checks both for instanceof URL and for objects with URL-like properties (searchParams object with sort method, hash string), allowing it to work with URL objects from different execution contexts.
The value to check
True if the value is a URL or URL-like object
const value: unknown = new URL('https://example.com');if (isURL(value)) { console.log(value.hostname); // "example.com"} Copy
const value: unknown = new URL('https://example.com');if (isURL(value)) { console.log(value.hostname); // "example.com"}
Type guard to check if a value is a URL object.
Checks both for instanceof URL and for objects with URL-like properties (searchParams object with sort method, hash string), allowing it to work with URL objects from different execution contexts.