README
Object-oriented Filepath Operations in Javascript & Typescript
๐ Table of Contents
- Why pathlib-js
- Usage & API Links
- The Wonderful Libraries that this wraps around
- Testing
- Authors
- Acknowledgments
๐ค Why pathlib-js?
If you're coming from Python, think of it this way: this library is to NodeJS's fs
and path
modules as Python's pathlib
is to its own os
module.
Avoids the hassle of string preprocessing, filepath normalization, and passing filepaths between the multitude of functions found in nodeJS filesystem
and path
modules.
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.
This is not the first package to take an OOP approach to filepaths in Javascript, but hopes to be more feature-rich than others from 5-6 years ago.
Prerequisites
NodeJS v12 or greater
Installing
You know the drill
npm i pathlib-js
or
yarn add pathlib-js
๐ ๏ธ Usage & API Links
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 example.basename
.
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
๐งช Testing
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,
makeSymlink()
andmakeSymlinkSync()
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.
๐ฅ The Wonderful Libraries that this wraps around
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
โ๏ธ Authors
๐ Acknowledgements
A thank you to the individuals who actually read README file from start to finish.