path
Build file paths and extract their directory, filename, or extension. These helpers work on path strings without checking whether a file exists.
import { join, extname } from "std::path"
node main() {
const p = join("src", "main.agency")
print(extname(p))
}Use join to combine path segments. Use resolve when you need an absolute path, or relative to express one path relative to another.
Functions
join
join(...parts: string[]): stringJoin path segments using the platform separator and normalize the result.
Parameters:
| Name | Type | Default |
|---|---|---|
| parts | string[] |
Returns: string
(source)
resolve
resolve(...parts: string[]): stringResolve path segments into an absolute path using the run's working directory.
Relative paths start at the run's working directory. An absolute segment replaces the segments before it: resolve("src", "/tmp", "out") returns "/tmp/out" on macOS and Linux. With no segments, returns the run's working directory.
Parameters:
| Name | Type | Default |
|---|---|---|
| parts | string[] |
Returns: string
(source)
basename
basename(p: string, ext: string = ""): stringReturn the last portion of a path.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
| p | string | ||
| ext | string | "" | Exact suffix to remove from the filename, including any leading dot |
Returns: string
(source)
dirname
dirname(p: string): stringReturn the directory portion of a path.
Parameters:
| Name | Type | Default |
|---|---|---|
| p | string |
Returns: string
(source)
extname
extname(p: string): stringReturn the file extension, including the leading dot, or an empty string if there is none.
Parameters:
| Name | Type | Default |
|---|---|---|
| p | string |
Returns: string
(source)
relative
relative(from: string, to: string): stringReturn the path from from to to, resolving relative inputs from the run's working directory.
Both paths resolve from the run's working directory. For example, relative("src", "src/lib/main.agency") returns "lib/main.agency" on macOS and Linux. Identical resolved paths produce an empty string.
Parameters:
| Name | Type | Default |
|---|---|---|
| from | string | |
| to | string |
Returns: string
(source)
isAbsolute
isAbsolute(p: string): booleanReturn true if the path is absolute.
Parameters:
| Name | Type | Default |
|---|---|---|
| p | string |
Returns: boolean
(source)