Skip to content

path

Pure helpers for building and taking apart file paths: join, resolve, basename, dirname, extname, relative, and isAbsolute. None of these touch the filesystem.

ts
import { join, extname } from "std::path"

node main() {
  const p = join("src", "main.agency")
  print(extname(p))
}

Functions

join

ts
join(...parts: string[]): string

Join path segments using the platform separator and normalize the result.

@param parts - Path segments to join

Parameters:

NameTypeDefault
partsstring[]

Returns: string

(source)

resolve

ts
resolve(...parts: string[]): string

Resolve path segments into an absolute path, relative to the current working directory.

@param parts - Path segments to resolve

Parameters:

NameTypeDefault
partsstring[]

Returns: string

(source)

basename

ts
basename(p: string, ext: string): string

Return 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:

NameTypeDefault
pstring
extstring""

Returns: string

(source)

dirname

ts
dirname(p: string): string

Return the directory portion of a path.

@param p - The file path

Parameters:

NameTypeDefault
pstring

Returns: string

(source)

extname

ts
extname(p: string): string

Return the extension of a path (including the leading dot), or an empty string if there is none.

@param p - The file path

Parameters:

NameTypeDefault
pstring

Returns: string

(source)

relative

ts
relative(from: string, to: string): string

Return the relative path from one path to another.

@param from - The starting path @param to - The target path

Parameters:

NameTypeDefault
fromstring
tostring

Returns: string

(source)

isAbsolute

ts
isAbsolute(p: string): boolean

Return true if the path is absolute.

@param p - The path to check

Parameters:

NameTypeDefault
pstring

Returns: boolean

(source)