deno.com

method URL.parse

#URL.parse(
url: string | URL,
base?: string | URL,
): URL | null

Parses a URL string or URL object and returns a URL object.

Examples #

#
const myURL = URL.parse('https://example.org');
console.log(myURL.href);  // Logs "https://example.org/"
console.log(myURL.hostname);  // Logs "example.org"
console.log(myURL.pathname);  // Logs "/"
console.log(myURL.protocol);  // Logs "https:"

const baseURL = new URL('https://example.org');
const myNewURL = URL.parse('/foo', baseURL);
console.log(myNewURL.href);  // Logs "https://example.org/foo"
console.log(myNewURL.hostname);  // Logs "example.org"
console.log(myNewURL.pathname);  // Logs "/foo"
console.log(myNewURL.protocol);  // Logs "https:"

Parameters #

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

Return Type #

URL | null

See #