requireAbsolute
function requireAbsolute(path: unknown, message: string = "Expected an absolute path."): string;
A path that starts at a root: a leading /, or a scheme such as https:// or mailto:. Everything else, the empty string included, is relative.
isX and nonX answer a question and never interrupt control flow; requireX and requireNonX hand the value back or throw. The scheme is explained in Validation conventions.
Parameters
Parameter | Type | Description |
|---|---|---|
|
| The value to validate as an absolute path. |
|
| The message of the exception. A default is used when omitted. |
Returns
string — the same value, typed as an absolute path.
Throws
Exception | Condition |
|---|---|
| the value is not an absolute path. |
Examples
What passes and what does not
requireAbsolute("/var/log"); // => "/var/log"
requireAbsolute("https://example.com/a"); // => "https://example.com/a"
requireAbsolute("docs/readme.md"); // throws IllegalArgumentException
requireAbsolute("./a"); // throws IllegalArgumentException
See also
Source
23 September 2026
This documentation was generated with AI (Claude) from the library's source code.