Skip to content
Warlock.js v4.7.0

@warlock.js/fs

A pocket-size filesystem toolkit — one fs object with everything: files, directories, handles, hashing. The shape you wish node:fs had, minus the graveyard of single-purpose dependencies (fs-extra, rimraf, mkdirp, write-file-atomic, hasha) you’d otherwise reach for.

You import one thing and reach for it the way you’d reach for console. fs.files.* handles files, fs.dirs.* handles directories, fs.file() and fs.dir() give you lazy handle objects, and fs.hash.* fingerprints anything. No factory, no config, no setup.

Write JSON, read it back typed, patch it in place, then walk a tree — all through fs:

src/build.ts
import { fs } from "@warlock.js/fs";
// Write JSON — parent dirs auto-created, pretty-printed.
await fs.files.putJson("./build/manifest.json", { version: "1.0.0" });
// Read it back, fully typed.
const manifest = await fs.files.getJson<{ version: string }>("./build/manifest.json");
// Read → transform → write, atomically, in one call.
await fs.files.editJson("./build/manifest.json", m => ({ ...m, built: Date.now() }));
// Walk the whole tree (recursive by default), files and folders alike.
for await (const entry of fs.dirs.walk("./build")) {
console.log(entry.type, entry.path);
}

That’s the entire vocabulary: nouns (files, dirs) and verbs (putJson, editJson, walk). No naming ceremony to memorize.

  1. Introduction — what fs gives you over raw node:fs/promises.
  2. Installation — one yarn add, no wiring.
  3. Your first write — a five-minute fs.files.put + fs.files.get walkthrough.

Then dip into the guides for task-oriented walkthroughs, or the reference for the full surface.