Skip to content

@caido/quickjs-types / llrt/path

llrt/path

Namespaces

NamespaceDescription
export=-

Interfaces

FormatInputPathObject

Properties

base?

optional base: string

The file name including extension (if any) such as 'index.html'

dir?

optional dir: string

The full directory path such as '/home/user/dir' or 'c:\path\dir'

ext?

optional ext: string

The file extension (if any) such as '.html'

name?

optional name: string

The file name without extension (if any) such as 'index'

root?

optional root: string

The root of the path such as '/' or 'c:'


ParsedPath

A parsed path object generated by path.parse() or consumed by path.format().

Properties

base

base: string

The file name including extension (if any) such as 'index.html'

dir

dir: string

The full directory path such as '/home/user/dir' or 'c:\path\dir'

ext

ext: string

The file extension (if any) such as '.html'

name

name: string

The file name without extension (if any) such as 'index'

root

root: string

The root of the path such as '/' or 'c:'


PlatformPath

Properties

delimiter

readonly delimiter: ";" | ":"

The platform-specific file delimiter. ';' or ':'.

sep

readonly sep: "\" | "/"

The platform-specific file separator. '\' or '/'.

Methods

basename()

basename(path: string, suffix?: string): string

Return the last portion of a path. Similar to the Unix basename command. Often used to extract the file name from a fully qualified path.

Parameters
ParameterTypeDescription
pathstringthe path to evaluate.
suffix?stringoptionally, an extension to remove from the result.
Returns

string

dirname()

dirname(path: string): string

Return the directory name of a path. Similar to the Unix dirname command.

Parameters
ParameterTypeDescription
pathstringthe path to evaluate.
Returns

string

extname()

extname(path: string): string

Return the extension of the path, from the last '.' to end of string in the last portion of the path. If there is no '.' in the last portion of the path or the first character of it is '.', then it returns an empty string.

Parameters
ParameterTypeDescription
pathstringthe path to evaluate.
Returns

string

format()

format(pathObject: FormatInputPathObject): string

Returns a path string from an object - the opposite of parse().

Parameters
ParameterTypeDescription
pathObjectFormatInputPathObjectpath to evaluate.
Returns

string

isAbsolute()

isAbsolute(path: string): boolean

Determines whether {path} is an absolute path. An absolute path will always resolve to the same location, regardless of the working directory.

If the given {path} is a zero-length string, false will be returned.

Parameters
ParameterTypeDescription
pathstringpath to test.
Returns

boolean

join()

join(...paths: string[]): string

Join all arguments together and normalize the resulting path.

Parameters
ParameterTypeDescription
...pathsstring[]paths to join.
Returns

string

Throws

if any of the path segments is not a string.

normalize()

normalize(path: string): string

Normalize a string path, reducing '..' and '.' parts. When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used.

Parameters
ParameterTypeDescription
pathstringstring path to normalize.
Returns

string

Throws

if path is not a string.

parse()

parse(path: string): ParsedPath

Returns an object from a path string - the opposite of format().

Parameters
ParameterTypeDescription
pathstringpath to evaluate.
Returns

ParsedPath

Throws

if path is not a string.

resolve()

resolve(...paths: string[]): string

The right-most parameter is considered {to}. Other parameters are considered an array of {from}.

Starting from leftmost {from} parameter, resolves {to} to an absolute path.

If {to} isn't already absolute, {from} arguments are prepended in right to left order, until an absolute path is found. If after using all {from} paths still no absolute path is found, the current working directory is used as well. The resulting path is normalized, and trailing slashes are removed unless the path gets resolved to the root directory.

Parameters
ParameterTypeDescription
...pathsstring[]A sequence of paths or path segments.
Returns

string

Throws

if any of the arguments is not a string.

Variables

export=

export=: PlatformPath