requireLink()function
requireLink(href: PossibleLink, url?: ImmutableURL, root?: ImmutableURL, caller: AnyCaller = requireLink): ImmutableURI
| Param | Type | |
|---|---|---|
href | PossibleLink | The link to resolve. required |
url | ImmutableURL | The current page URL — base for relative refs and scheme-prefixed URIs. |
.href | URLString | A URL string has a protocol and a //. required readonly |
.origin | URLString | A URL string has a protocol and a //. required readonly |
.pathname | AbsolutePath | Absolute path string starting with a / slash. required readonly |
root | ImmutableURL | The site root URL — base for absolute paths. Defaults to url. |
.href | URLString | A URL string has a protocol and a //. required readonly |
.origin | URLString | A URL string has a protocol and a //. required readonly |
.pathname | AbsolutePath | Absolute path string starting with a / slash. required readonly |
caller | AnyCaller | Function to attribute a thrown error to (defaults to requireLink itself). Defaults to requireLink |
| Return | |
|---|---|
ImmutableURI | An absolute URI string. |
| Throws | |
|---|---|
RequiredError | If href cannot be resolved. |
Resolve a possible link to an absolute URI string, or throw RequiredError if resolution fails.
Same classification and defaults as getLink(). Use when an absolute URI is required and there's no sensible "do nothing" path for the caller.
Examples
requireLink("mailto:a@b") // → "mailto:a@b"