📝 Table of Contents
- Why pathlib-js
- Usage & API Links
- The Wonderful Libraries that this wraps around
If you're coming from Python, think of it this way: this library is to NodeJS's
path modules as Python's
pathlib is to its own
Avoids the hassle of string preprocessing, filepath normalization, and passing filepaths between the multitude of functions found in nodeJS
A single class
Path wraps around a filepath and exposes an API for accessing its components, globbing, watching, reading, writing, traversing a tree structure, etc.
NodeJS v12 or greater
You know the drill
npm i pathlib-js
yarn add pathlib-js
Understanding parts of a Path
Path instances carry properties that tie in with the typically-used components of a filepath.
For example, if a particular Path instance was located in a variable
example and you wished to retrieve the basename of the underlying filepath, you can simply access it by
Defining a path
Paths can be defined from a single string or multiple strings which are resolved into a single path.
import Path from "pathlib-js" const fp1 = new Path("/home/Documents/Yougetthepoint.json"); const fp2 = new Path("/", "home/watch_this_disappear", "../Documents/Yougetthepoint.json"); console.log(fp1.path === fp2.path); > true
More concrete usages & API
- Manipulating filepath strings
- Determinine filepath type, stats, existence.
- File Structure Traversal - Individual Directories
- File Structure Traversal - Tree Structures
- Copying, moving, deleting, and changing permissions
- Filepath Creation - Directories, Files, and Symlinks
- Reading, Writing, Globbing, and Watching
This library is regularly updating its test suite with additional case scenarios.
At the current time, please anticipate the following conditional test failures:
- On Windows,
makeSymlinkSync()methods will fail if the environment they are used in lacks administrator priveleges (i.e. testing in VScode without starting it up with admin priveleges). This caveat has not been seen on Unix-based systems.
This wouldn't be possible without these awesome libraries. Give them a star.
- node-fs-extra - Enhanced filesystem operations.
- chokidar - Robust and efficient filesystem watching.
- fast-glob - Robust and fast globbing potential.
- path-normalize - Workhorse function for robustly normalizing filepaths
A thank you to the individuals who actually read README file from start to finish.