{ } qjs-modules

path

Source: quickjs-path.c — module exports a flat list of functions.

Filesystem path manipulation (Node path-like, with extra POSIX helpers). Most functions take a path string as the first argument.

Components & names

FunctionArgsDescription
basename(path)1Final path component.
basepos(path)1Character offset where the basename begins.
baselen(path)1Length of the basename.
dirname(path)1Directory portion of the path.
dirlen(path)1Length of the directory portion.
extname(path)1File extension (with dot).
extpos(path)1Offset of the extension.
extlen(path)1Length of the extension.
length(path)1Number of path components.
components(path)1Splits into an array of components.
at(path, index)2Returns the component at index.
right(path)1Tail portion of the path.
skip(path)1Skips the leading component.
skipSeparator(path)1Skips a leading separator.
isSeparator(ch)1Whether a character is a path separator.

Filesystem queries

FunctionArgsDescription
exists(path)1Whether the path exists.
isAbsolute(path) / isRelative(path)1Path kind.
isDirectory / isFile / isCharDev / isBlockDev / isFIFO / isSocket / isSymlink1stat-based type predicates.
getcwd(buf)1Current working directory.
gethome(buf)1Home directory.
getsep(buf)1Platform path separator.
readlink(path)1Reads a symbolic link target.
fnmatch(pattern)1Glob-style pattern match.

Normalization (return newly built strings)

FunctionArgsDescription
absolute(path)1Resolves to an absolute path.
canonical(path)1Canonical form (resolving ./..).
normalize(path)1Normalizes separators and ./...
realpath(path)1Resolves all symlinks.
search(path, list)2Searches for a file across a path list.
relative(from, to)2Relative path from from to to.

Node-style helpers

FunctionArgsDescription
slice(path, start, end)0Sub-range of components.
join(...parts)1Joins components with the separator.
parse(path)1Returns {root, dir, base, ext, name}.
format(obj)1Inverse of parse.
resolve(...parts)1Resolves to an absolute path from segments.

Constants

delimiter (path-list separator) and sep (path separator) strings.