deno.com

method URL.canParse

#URL.canParse(
url: string | URL,
base?: string | URL,
): boolean

Returns a boolean value indicating if a URL string is valid and can be parsed.

Examples #

#
// Check if an absolute URL string is valid
console.log(URL.canParse('https://example.org'));  // Logs true
console.log(URL.canParse('https:://example.org'));  // Logs false

// Check if a relative URL string with a base is valid
console.log(URL.canParse('/foo', 'https://example.org'));  // Logs true
console.log(URL.canParse('/foo', 'https:://example.org'));  // Logs false

Parameters #

#url: string | URL
#base: string | URL
optional

Return Type #

boolean

See #