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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@humanfs/core

v0.17.0

Published

The core of the humanfs library.

Downloads

2,519

Readme

@humanfs/core

by Nicholas C. Zakas

If you find this useful, please consider supporting my work with a donation or nominate me for a GitHub Star.

Description

The core functionality for humanfs that is shared across all implementations for all runtimes. The contents of this package are intentionally runtime agnostic and are not intended to be used alone.

Currently, this package simply exports the Hfs class, which is an abstract base class intended to be inherited from in runtime-specific hfs packages (like @humanfs/node).

[!WARNING] This project is experimental and may change significantly before v1.0.0. Use at your own caution and definitely not in production!

Installation

Node.js

Install using your favorite package manager for Node.js:

npm install @humanfs/core

# or

pnpm install @humanfs/core

# or

yarn add @humanfs/core

# or

bun install @humanfs/core

Then you can import the Hfs and Path classes like this:

import { Hfs, Path } from "@humanfs/core";

Deno

Install using JSR:

deno add @humanfs/core

# or

jsr add @humanfs/core

Then you can import the Hfs class like this:

import { Hfs, Path } from "@humanfs/core";

Browser

It's recommended to import the minified version to save bandwidth:

import { Hfs, Path } from "https://cdn.skypack.dev/@humanfs/core?min";

However, you can also import the unminified version for debugging purposes:

import { Hfs, Path } from "https://cdn.skypack.dev/@humanfs/core";

Usage

Hfs Class

The Hfs class contains all of the basic functionality for an Hfs instance without a predefined impl. This class is mostly used for creating runtime-specific impls, such as NodeHfs and DenoHfs.

You can create your own instance by providing an impl directly:

const hfs = new Hfs({ impl: { async text() {} }});

The specified impl becomes the base impl for the instance, meaning you can always reset back to it using resetImpl().

You can also inherit from Hfs to create your own class with a preconfigured impl, such as:

class MyHfs extends Hfs {
	constructor() {
		super({
			impl: myImpl
		});
	}
}

Path Class

The Path class represents the path to a directory or file within a file system. It's an abstract representation that can be used even outside of traditional file systems where string paths might not make sense.

const myPath = new Path(["dir", "subdir"]);
console.log(myPath.toString());		// "dir/subdir"

// add another step
myPath.push("file.txt");
console.log(myPath.toString());		// "dir/subdir/file.txt"

// get just the last step
console.log(myPath.name);			// "file.txt"

// change just the last step
myPath.name = "file.json";
console.log(myPath.name);			// "file.json"
console.log(myPath.toString());		// "dir/subdir/file.json"

// get the size of the path
console.log(myPath.size);			// 3

// remove the last step
myPath.pop();
console.log(myPath.toString());		// "dir/subdir"

// iterate over the steps
for (const step of myPath) {
	// do something
}

// create a new path from a string
const newPath = Path.fromString("/foo/bar");

License

Apache 2.0