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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@context-fs/core

v0.1.4

Published

Virtual filesystem core - tree router and path-based APIs

Downloads

1,122

Readme

@context-fs/core

Virtual filesystem core library with a tree-based router for defining path-based APIs. Browser-safe with full TypeScript inference.

Installation

npm install @context-fs/core

Quick Start

import { createFileSystem, read, list } from "@context-fs/core";

const vfs = createFileSystem({
  "config.json": {
    [read]: (c) => c.json({ version: "1.0.0" }),
  },
  users: {
    ":userId": {
      [list]: () => [{ userId: "alice" }, { userId: "bob" }],
      "profile.json": {
        [read]: (c) => c.json({ id: c.params.userId }),
      },
    },
  },
});

// Read files
const config = await vfs.readText("/config.json");
const profile = await vfs.readText("/users/alice/profile.json");

// List directories
const users = await vfs.ls("/users"); // ["alice", "bob"]

Concepts

Tree Structure

Define your filesystem as a nested object. Each key is a path segment, and leaf nodes contain handler symbols.

const tree = {
  // Static file
  "readme.txt": {
    [read]: () => "Hello, world!",
  },
  // Directory with nested content
  docs: {
    "guide.md": {
      [read]: (c) => c.markdown("# Guide\n\nWelcome!"),
    },
  },
};

Dynamic Path Segments

Use :param syntax for dynamic segments. Parameters are fully typed and available via c.params.

const tree = {
  // Simple param
  ":id": {
    [read]: (c) => c.params.id, // { id: string }
  },
  // Param with suffix
  ":slug.md": {
    [read]: (c) => c.params.slug, // { slug: string }
  },
  // Param with prefix
  "issue-:num": {
    [read]: (c) => c.params.num, // { num: string }
  },
  // Multiple params
  ":year-:month-:day.json": {
    [read]: (c) => c.params, // { year, month, day: string }
  },
};

Handler Symbols

read - File Content

Return file content when read. Use context helpers for common formats.

import { read } from "@context-fs/core";

{
  [read]: (c) => "plain text",
  [read]: (c) => new Uint8Array([...]),
  [read]: (c) => c.json({ key: "value" }),
  [read]: (c) => c.text("text content"),
  [read]: (c) => c.markdown("# Heading"),
}

write - File Writes

Handle file writes. Return { error: string } to reject.

import { write } from "@context-fs/core";

{
  [read]: (c) => currentValue,
  [write]: (c, data) => {
    const text = new TextDecoder().decode(data);
    // Process write...
    return {}; // Success
    // return { error: "Write failed" }; // Failure
  },
}

list - Directory Enumeration

Return an array of parameter objects for dynamic directories.

import { list } from "@context-fs/core";

{
  ":userId": {
    [list]: async () => {
      const users = await fetchUsers();
      return users.map((u) => ({ userId: u.id }));
    },
    "profile.json": {
      [read]: (c) => c.json({ id: c.params.userId }),
    },
  },
}

link - Symlinks

Create symbolic links to other paths.

import { link } from "@context-fs/core";

{
  "latest.json": {
    [link]: () => "/versions/v2.0.0.json",
  },
  // Dynamic symlink
  ":alias": {
    [link]: (c) => `/targets/${c.params.alias}`,
  },
}

exists - Validation

Control whether a dynamic path exists. Useful for open-ended patterns.

import { exists } from "@context-fs/core";

{
  ":slug": {
    [exists]: async (c) => {
      return await isValidSlug(c.params.slug);
    },
    [read]: (c) => getContent(c.params.slug),
  },
}

stats - Custom File Stats

Override default file statistics.

import { stats } from "@context-fs/core";

{
  "data.bin": {
    [stats]: () => ({
      size: 1024,
      mtime: new Date("2024-01-01"),
      mode: 0o644,
    }),
    [read]: () => getData(),
  },
}

Mounting Subtrees

Use withParams() to create reusable filesystem fragments with inherited parameters.

import { createFileSystem, withParams, read, list } from "@context-fs/core";

// Reusable subtree factory
const createUserFiles = withParams<{ userId: string }>()({
  "profile.json": {
    [read]: (c) => c.json({ id: c.params.userId }),
  },
  "settings.json": {
    [read]: (c) => c.json({ theme: "dark" }),
  },
});

// Mount in main tree
const vfs = createFileSystem({
  users: {
    ":userId": {
      [list]: () => [{ userId: "alice" }],
      ...createUserFiles(),
    },
  },
});

API Reference

createFileSystem(tree)

Creates a VirtualFileSystem from a tree definition.

const vfs = createFileSystem(tree);

VirtualFileSystem

Reading

// List directory contents
const entries: string[] = await vfs.ls("/path");

// Read as Uint8Array
const data: Uint8Array = await vfs.read("/file.bin");

// Read as string
const text: string = await vfs.readText("/file.txt");

// Check existence
const exists: boolean = await vfs.exists("/path");

// Get file stats
const stat: VfsStat = await vfs.stat("/path");
const lstat: VfsStat = await vfs.lstat("/symlink"); // Don't follow symlinks

Writing

// Write file (if handler supports it)
const result = await vfs.write("/file.txt", new Uint8Array([...]));
if (result.error) {
  console.error(result.error);
}

// Check if path is writable
const writable: boolean = await vfs.isWritable("/path");

Symlinks

// Read symlink target
const target: string = await vfs.readlink("/symlink");

// Resolve path (follows symlinks)
const resolved: string = await vfs.resolve("/path/../other/./file");

Types

type FileContent = string | Uint8Array;

interface FileStats {
  size?: number;
  mtime?: Date;
  ctime?: Date;
  mode?: number;
}

interface VfsStat {
  type: "file" | "directory" | "symlink";
  mode: number;
  size: number;
  mtime: Date;
  ctime: Date;
  atime: Date;
}

interface WriteResult {
  error?: string;
}

Browser Compatibility

This package is browser-safe and doesn't depend on Node.js APIs. It can be used in any JavaScript environment.

Related Packages

License

MIT