Skip to main content
URL.canParse - node__url.d.ts - Node documentation
method URL.canParse

Usage in Deno

```typescript import { URL } from "node:node__url.d.ts"; ```
URL.canParse(
input: string,
base?: string,
): boolean
Checks if an `input` relative to the `base` can be parsed to a `URL`. ```js const isValid = URL.canParse('/foo', 'https://example.org/'); // true const isNotValid = URL.canParse('/foo'); // false ```

Parameters

input: string
The absolute or relative input URL to parse. If `input` is relative, then `base` is required. If `input` is absolute, the `base` is ignored. If `input` is not a string, it is `converted to a string` first.
optional
base: string
The base URL to resolve against if the `input` is not absolute. If `base` is not a string, it is `converted to a string` first.

Return Type

boolean