path
The path module provides path manipulation helpers similar to Node.js.
In JSH, the default export is the POSIX implementation, and the module also exposes path.posix and path.win32 namespaces.
Typical usage looks like this.
const path = require('path');Default export
require('path') returns the POSIX path implementation.
That means:
- path separator is
/ - list delimiter is
: - functions such as
join()andresolve()behave like POSIX path utilities
You can also access:
path.posixpath.win32
Common properties
| Property | POSIX | win32 |
|---|---|---|
sep | / | \\ |
delimiter | : | ; |
resolve()
Resolves a sequence of paths into an absolute path.
Syntax
path.resolve(...segments)The default implementation uses the current working directory when it needs a base path.
normalize()
Normalizes path separators and resolves . and .. segments.
Syntax
path.normalize(value)isAbsolute()
Returns whether a path is absolute.
Syntax
path.isAbsolute(value)join()
Joins path segments using the active path style and normalizes the result.
Syntax
path.join(...segments)relative()
Returns a relative path from one location to another.
Syntax
path.relative(from, to)dirname()
Returns the directory part of a path.
Syntax
path.dirname(value)basename()
Returns the last path component.
If ext is provided, the matching suffix is removed.
Syntax
path.basename(value)
path.basename(value, ext)extname()
Returns the file extension including the leading dot.
Syntax
path.extname(value)parse()
Splits a path into structured fields.
Syntax
path.parse(value)Return value
parse() returns an object with:
rootdirbaseextname
format()
Builds a path string from a parsed path object.
Syntax
path.format(pathObject)pathObject may contain dir, root, base, name, and ext.
Usage example
| |
parse()/format() example
| |
POSIX and win32 namespaces
Use path.posix or path.win32 when you need explicit behavior regardless of the current default.
| |
Behavior notes
- The default JSH export is POSIX-oriented.
- All public functions require string arguments where applicable and throw
TypeErrorfor invalid input. parse()andformat()use a Node.js-like object shape.path.win32is available for Windows path handling even when JSH is running on a non-Windows system.