Path class is an immutable abstraction around file/module paths and the Node.js
modules. It aims to solve cross platform and operating system related issues in a straight forward
way. To begin, import and instantiate the
Path class, with either a single path, or a list of path
parts that will be joined.
By default, the
Path class operates on the defined path parts as-is. If you would prefer to
operate against real or resolved paths, use the
respectively. The current path is
resolved against the defined current
working directory (
Path.resolve() methods can be used to factory a
from a string or an existing instance. Especially useful when used in combination with the
The following methods are available on the class instance. In the examples below, the
type is a union of
FilePath | Path, and
FilePath is a
Path.create(filePath: PortablePath): Path
Create and return a new
Path instance if a string. If already a
Path, return as is.
Path.resolve(filePath: PortablePath, cwd?: PortablePath): Path
create() but also resolves the path against the current working directory (defaults to
Path#append(...parts: PortablePath): Path
Append path parts to the end of the current path and return a new
Path#equals(path: PortablePath): boolean
Returns true if both paths are equal using strict equality.
Path#ext(withoutPeriod?: boolean): string
Return the extension (if applicable) with or without leading period.
Return true if the current path exists on the file system.
Return true if the current path is absolute. Does not verify existence on the file system.
Return true if the current path is a folder.
Return true if the current path is a file.
Path#name(withoutExtension?: boolean): string
Return the file name (with optional extension) or folder name.
Return the parent folder as a new
Return the current path as a normalized string. Is also triggered when the
Path instance is cast
to a string.
Path#prepend(...parts: PortablePath): Path
Prepend path parts to the beginning of the current path and return a new
Path#relativeTo(to: PortablePath): Path
Return a new relative
Path instance from the current "from" path to the defined "to" path.
Return the current path as a normalized string. See path().