getURL()function

getURL(target: Nullish<PossibleURL>, base?: PossibleURL): ImmutableURL | undefined
ParamType
targetNullish<PossibleURL>
URL string, URL object, or path to resolve — falsy values return undefined. required
basePossibleURL
Base URL to resolve a relative target against.
Return
ImmutableURL | undefined
Resolved ImmutableURL, or undefined if conversion fails or the result is not a true URL.

Resolve a possible URL relative to a base URL, or return undefined if conversion fails.

  • Like getBasedURI() but only succeeds for true scheme://host URLs — other URIs (e.g. mailto:) return undefined.

Examples

getURL("/page", "http://example.com/"); // `http://example.com/page`
getURL("mailto:[email protected]"); // `undefined` — not a hierarchical URL