Skip to main content

Path

An immutable class for operating on file system paths. Will normalize path separators based on the operating system, "/" on Linux/MacOS, and "\" on Windows.

Hierarchy

Implements

Index

Constructors

constructor

Properties

staticDELIMITER

DELIMITER: ; | : = path.delimiter

staticSEP

SEP: \ | / = path.sep

Methods

append

  • Append path parts to the end of the current path and return a new Path instance.

equals

  • Returns true if both paths are equal using strict equality.

exists

  • exists(): boolean
  • Return true if the current path exists.

ext

  • ext(withoutPeriod?: boolean): string
  • Return the extension (if applicable) with or without leading period.

isAbsolute

  • isAbsolute(): boolean
  • Return true if the current path is absolute.

isDirectory

  • isDirectory(): boolean
  • Return true if the current path is a folder.

isFile

  • isFile(): boolean
  • Return true if the current path is a file.

name

  • name(withoutExtension?: boolean): string
  • Return the file name (with optional extension) or folder name.

parent

  • Return the parent folder as a new Path instance.

path

  • path(): string
  • Return the current path as a normalized string.

prepend

  • Prepend path parts to the beginning of the current path and return a new Path instance.

realPath

  • realPath(): string
  • Returns a canonical path by resolving directories and symlinks.

relativeTo

  • Return a new relative Path instance from the current "from" path to the defined "to" path.

resolve

  • Return a new Path instance where the current path is accurately resolved against the defined working directory.

toJSON

  • toJSON(): string

toString

  • toString(): string

staticcreate

  • Create and return a new Path instance.

staticpath

  • Convert a path-like value to a formatted path string.

staticresolve

  • Like create() but also resolves the path against a working directory.