npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

path-class

v0.10.0

Published

A semantic `Path` class for `node` and `bun`. Inspired by `bun`'s [`file(…)`](https://bun.com/docs/runtime/file-io) API, but `node`-compatible.

Downloads

3,539

Readme

path-class

A semantic Path class for node and bun. Inspired by bun's file(…) API, but node-compatible.

Usage examples

import { PrintableShellCommand } from "printable-shell-command";
import { Path } from "path-class";

// Traverse files
console.log(new Path("foo/bar").parent.join("baz.txt").path);

// Functions on files
console.log(await new Path("./src").readDir());

// Read text
const knownHosts = await Path.homedir.join(".ssh/known_hosts").readText();
console.log(knownHosts);

// Resolve paths
const distDir = Path.resolve("../dist", import.meta.url);
console.log(`Building to: ${distDir}`);

// Get XDG dirs, read JSON with fallback, write JSON
const info = Path.xdg.data.join("my-tool/info.json");
const config: { counter?: number } = await info.readJSON({ fallback: {} });
config.counter = (config.counter ?? 0) + 1;
await info.writeJSON(config);

// Extensive example: create temp dirs and files, fetch into path, chaining,
// spawn subprocess, read JSON, and clean up.
//
// In this case the GitHub API supports direct file download, and you could
// unzip in memory. However, the steps are a good illustration of diverse tasks
// in a typical script.
const tempDir = await Path.makeTempDir();
const zipFile = await tempDir.join("file.zip").write(fetch("https://github.com/lgarron/path-class/archive/refs/tags/v0.7.2.zip"));
await new PrintableShellCommand("unzip", [zipFile]).shellOut({ cwd: tempDir });
const packageJSON = await tempDir.join("path-class-0.7.2/package.json").readJSON();
console.log(packageJSON.exports);
tempDir.rm_rf();

Differences from node functions

This implementation differs from similar functions in node in a few ways:

  • Function names are more clear where possible.
  • Writing to a file creates intermediate directories by default.
  • .mkdir(…) creates intermediate directories by default.
  • .rm_rf(…) is provided as an explicit function as a convenience.
  • Async .exists(…) is implemented. Go knock yourself out with race conditions.
  • .exists(…) has options/variants to ensure the existing path is a dir/file.
  • Supported in packages like printable-shell-command and lockfile-mutex.

Also note:

  • Path sometimes uses a the presence of a trailing slash / to disallow file-specific operations on directory paths.
  • Path preserves relative resolution prefixes like . and ... For example, new Path("./@biomejs/biome") is not the same as new Path("@biomejs/biome").