Nectar of the Programming Masses

    TypeScript icon, indicating that this package has built-in type declarations

    1.3.0 • Public • Published

    Project logo

    Object-oriented Filepath Operations in Javascript & Typescript

    Status GitHub Issues License

    📝 Table of Contents

    🤔 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.


    NodeJS v12 or greater


    You know the drill

    npm i pathlib-js


    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.

    File Components of a Windows system

    File Components of a Unix system

    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

    🧪 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() and 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.

    🥇 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.


    npm i pathlib-js

    DownloadsWeekly Downloads






    Unpacked Size

    158 kB

    Total Files


    Last publish


    • maurice.pasternak