CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
README.md141 linesDownload Raw Back to core
1# `@humanfs/core`2 3by [Nicholas C. Zakas](https://humanwhocodes.com)4 5If you find this useful, please consider supporting my work with a [donation](https://humanwhocodes.com/donate) or [nominate me](https://stars.github.com/nominate/) for a GitHub Star.6 7## Description8 9The 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.10 11Currently, 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`).12 13> [!WARNING]14> This project is **experimental** and may change significantly before v1.0.0. Use at your own caution and definitely not in production!15 16## Installation17 18### Node.js19 20Install using your favorite package manager for Node.js:21 22```shell23npm install @humanfs/core24 25# or26 27pnpm install @humanfs/core28 29# or30 31yarn add @humanfs/core32 33# or34 35bun install @humanfs/core36```37 38Then you can import the `Hfs` and `Path` classes like this:39 40```js41import { Hfs, Path } from "@humanfs/core";42```43 44### Deno45 46Install using [JSR](https://jsr.io):47 48```shell49deno add @humanfs/core50 51# or52 53jsr add @humanfs/core54```55 56Then you can import the `Hfs` class like this:57 58```js59import { Hfs, Path } from "@humanfs/core";60```61 62### Browser63 64It's recommended to import the minified version to save bandwidth:65 66```js67import { Hfs, Path } from "https://cdn.skypack.dev/@humanfs/core?min";68```69 70However, you can also import the unminified version for debugging purposes:71 72```js73import { Hfs, Path } from "https://cdn.skypack.dev/@humanfs/core";74```75 76## Usage77 78### `Hfs` Class79 80The `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`.81 82You can create your own instance by providing an `impl` directly:83 84```js85const hfs = new Hfs({ impl: { async text() {} }});86```87 88The specified `impl` becomes the base impl for the instance, meaning you can always reset back to it using `resetImpl()`.89 90You can also inherit from `Hfs` to create your own class with a preconfigured impl, such as:91 92```js93class MyHfs extends Hfs {94	constructor() {95		super({96			impl: myImpl97		});98	}99}100```101 102### `Path` Class103 104The `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.105 106```js107const myPath = new Path(["dir", "subdir"]);108console.log(myPath.toString());		// "dir/subdir"109 110// add another step111myPath.push("file.txt");112console.log(myPath.toString());		// "dir/subdir/file.txt"113 114// get just the last step115console.log(myPath.name);			// "file.txt"116 117// change just the last step118myPath.name = "file.json";119console.log(myPath.name);			// "file.json"120console.log(myPath.toString());		// "dir/subdir/file.json"121 122// get the size of the path123console.log(myPath.size);			// 3124 125// remove the last step126myPath.pop();127console.log(myPath.toString());		// "dir/subdir"128 129// iterate over the steps130for (const step of myPath) {131	// do something132}133 134// create a new path from a string135const newPath = Path.fromString("/foo/bar");136```137 138## License139 140Apache 2.0141 
basant307/AI_Governance_Project · CoolFace