path
Pure helpers for building and taking apart file paths: join, resolve, basename, dirname, extname, relative, and isAbsolute. None of these touch the filesystem.
import { join, extname } from "std::path"
node main() {
const p = join("src", "main.agency")
print(extname(p))
}Functions
join
join(...parts: string[]): stringJoin path segments using the platform separator and normalize the result.
@param parts - Path segments to join
Parameters:
| Name | Type | Default |
|---|---|---|
| parts | string[] |
Returns: string
(source)
resolve
resolve(...parts: string[]): stringResolve path segments into an absolute path, relative to the current working directory.
@param parts - Path segments to resolve
Parameters:
| Name | Type | Default |
|---|---|---|
| parts | string[] |
Returns: string
(source)
basename
basename(p: string, ext: string): stringReturn the last portion of a path.
@param p - The file path @param ext - If given and the path ends with this extension, it is trimmed off the result
Parameters:
| Name | Type | Default |
|---|---|---|
| p | string | |
| ext | string | "" |
Returns: string
(source)
dirname
dirname(p: string): stringReturn the directory portion of a path.
@param p - The file path
Parameters:
| Name | Type | Default |
|---|---|---|
| p | string |
Returns: string
(source)
extname
extname(p: string): stringReturn the extension of a path (including the leading dot), or an empty string if there is none.
@param p - The file path
Parameters:
| Name | Type | Default |
|---|---|---|
| p | string |
Returns: string
(source)
relative
relative(from: string, to: string): stringReturn the relative path from one path to another.
@param from - The starting path @param to - The target path
Parameters:
| Name | Type | Default |
|---|---|---|
| from | string | |
| to | string |
Returns: string
(source)
isAbsolute
isAbsolute(p: string): booleanReturn true if the path is absolute.
@param p - The path to check
Parameters:
| Name | Type | Default |
|---|---|---|
| p | string |
Returns: boolean
(source)