getBasedURI()function
getBasedURI(input: Nullish<PossibleURL>, base?: PossibleURL): ImmutableURI | undefined
| Param | Type | |
|---|---|---|
input | Nullish<PossibleURL> | URI string, URL object, or path to resolve — falsy values return undefined. required |
base | PossibleURL | Base URL to resolve a relative input against. |
| Return | |
|---|---|
ImmutableURI | undefined | Resolved ImmutableURI, or undefined if conversion fails. |
Resolve a possible URI relative to a base, or return undefined if conversion fails.
- Returns any kind of URI — not just hierarchical
scheme://hostURLs. UsegetURL()when a true URL is specifically required. - A
URLinstance is returned as-is (already absolute, base ignored).
Note: the base is normalised with getBaseURL(), so it is always treated as if it ends in a slash.
- e.g. if
baseishttp://p.com/a/b/cthe path resolves relative toc/as if a trailing slash was present. - This differs from the default behaviour of
new URL(), but is the more natural expected result.
Examples
getBasedURI("path/to/page", "http://example.com/base/"); // `http://example.com/base/path/to/page`