{ } 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.

The Node functions (basename, dirname, extname, format, isAbsolute, join, normalize, parse, relative, resolve) throw TypeError with code: 'ERR_INVALID_ARG_TYPE' and Node's message for a non-string argument (basename also for a non-string suffix, relative also for a missing to). The other functions coerce their arguments to strings.

toNamespacedPath(path) returns path unchanged (POSIX); _makeLong is the same function. path/posix and node:path/posix import this module.

Components & names

FunctionArgsDescription
basename(path)1Final path component.
dirname(path)1Directory portion of the path.
extname(path)1File extension (with dot).
skip(path, pos?)1Offset after the component at pos and its separators, -1 at the end.

Filesystem queries

FunctionArgsDescription
exists(path)1Whether the path exists. Follows symlinks like fs.existsSync: a dangling link is false.
isAbsolute(path)1Whether the path starts at the root; !isAbsolute(p) for a relative one.
isDirectory / isFile / isSymlink1Type predicates on the S_IF* bits. isDirectory and isFile follow symlinks (stat, like fs.statSync), isSymlink tests the link itself (lstat). false if the entry is missing. Other types: fs.statSync(p).isFIFO() and the like.
getcwd(buf)1Current working directory.
gethome(buf)1Home directory.
fnmatch(pattern)1Glob-style pattern match.

Normalization (return newly built strings)

FunctionArgsDescription
normalize(path)1Normalizes separators and ./...
realpath(path)1Resolves all symlinks.
relative(from, to)2Relative path from from to to.

Node-style helpers

FunctionArgsDescription
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.

posix and default export

path.posix and the default export are the module's own functions (`import path from 'path'; path.posix === path). There is no path.win32. join()` does not normalize (join('a', '..', 'b') is 'a/../b', Node gives 'b') and an absolute argument restarts the result.

Removed

These qjsm-only functions had no user and no standard counterpart, or one that does the same:

RemovedUse instead
absolute(p)resolve(p)
isRelative(p)!isAbsolute(p)
readlink(p)fs.readlinkSync(p)
isCharDev isBlockDev isFIFO isSocketfs.statSync(p).isCharacterDevice() and the like
toArray(p), slice(p, a, b), length(p)p.split('/') and array methods
at components right skipSeparator isSeparator getsep basepos baselen dirlen extpos extlen canonical isin equal searchnone

Export list

Generated by utilities/doc-api.js from the path dump of utilities/api-surface.sh: 85 members. Edit the text above this block, not the block.

Functions: _makeLong(), basename(), dirname(), exists(), extname(), fnmatch(), format(), getcwd(), gethome(), isAbsolute(), isDirectory(), isFile(), isSymlink(), join(), normalize(), parse(), realpath(), relative(), resolve(), skip(), toNamespacedPath()

Values: FNM_NOESCAPE = 2, FNM_NOMATCH = 1, FNM_PATHNAME = 1, FNM_PERIOD = 4, delimiter, sep

default

object

  • static methods: _makeLong(), basename(), dirname(), exists(), extname(), fnmatch(), format(), getcwd(), gethome(), isAbsolute(), isDirectory(), isFile(), isSymlink(), join(), normalize(), parse(), realpath(), relative(), resolve(), skip(), toNamespacedPath()
  • static values: FNM_NOESCAPE = 2, FNM_NOMATCH = 1, FNM_PATHNAME = 1, FNM_PERIOD = 4, delimiter, posix, sep

posix

object

  • static methods: _makeLong(), basename(), dirname(), exists(), extname(), fnmatch(), format(), getcwd(), gethome(), isAbsolute(), isDirectory(), isFile(), isSymlink(), join(), normalize(), parse(), realpath(), relative(), resolve(), skip(), toNamespacedPath()
  • static values: FNM_NOESCAPE = 2, FNM_NOMATCH = 1, FNM_PATHNAME = 1, FNM_PERIOD = 4, delimiter, posix, sep