requirePath()function
requirePath(path: PossiblePath, base?: AbsolutePath, caller: AnyCaller = requirePath): AbsolutePath
| Param | Type | |
|---|---|---|
path | PossiblePath | Absolute path e.g. /a/b/c, relative path e.g. ./a or b or ../c, URL string e.g. http://shax.com/a/b/c, or URL instance. required |
base | AbsolutePath | Absolute path used for resolving relative paths in path. |
caller | AnyCaller | Function to attribute a thrown error to (defaults to requirePath itself). Defaults to requirePath |
| Return | |
|---|---|
AbsolutePath | Absolute path with a leading slash but no trailing slash, e.g. /a/c/b. |
| Throws | |
|---|---|
RequiredError | If path is not a valid path. |
Resolve a relative or absolute path and return the path, or throw RequiredError if not a valid path.
- Internally uses
new URLto do path processing but shouldn't ever reveal that fact. - Returned paths are cleaned with
cleanPath()so runs of slashes and trailing slashes are removed.
Examples
requirePath("./a", "/b") // "/b/a"