joinPath()function
joinPath(first: AbsolutePath, ...rest: PathPart[]): AbsolutePath
joinPath(...parts: PathPart[]): string
| Param | Type | |
|---|---|---|
first | AbsolutePath | Absolute path string starting with a / slash. required |
rest | PathPart[] | required |
parts | PathPart[] | required |
| Return | |
|---|---|
AbsolutePath | Absolute path string starting with a / slash. |
string |
Join one or more path parts into a single path string.
- Each part can be a string (e.g.
"/foo/bar","foo") or an array of segments (e.g.["foo", "bar"]). String parts may themselves contain/separators — they're flattened and normalised. - Runs of
//are collapsed and trailing slashes stripped (viacleanPath());\Windows slashes are converted too. - If the first argument is an
AbsolutePathstring (starts with/), the result is also anAbsolutePath; otherwise the return type isstring.
Examples
joinPath("/foo", "bar") // → "/foo/bar"joinPath("/foo", ["bar", "baz"]) // → "/foo/bar/baz"joinPath(["foo", "bar"], "baz") // → "foo/bar/baz" (relative — no leading slash)
joinPath("/a/", "/b/") // → "/a/b" (slashes normalised)joinPath("/") // → "/"