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

@leadertechie/r2tohtml

v0.1.0-alpha.12

Published

Generic R2 content loader - fetch and cache content from Cloudflare R2

Readme

@leadertechie/r2tohtml

A generic, configuration-driven R2 content loader for Cloudflare Workers. Fetch, cache, and parse content from R2 without hardcoded paths.

Features

  • Generic R2 operations - No hardcoded content structure
  • In-memory caching - Configurable TTL with cache invalidation
  • Frontmatter parsing - Extract metadata from markdown files
  • TypeScript support - Full type definitions included

Installation

npm install @leadertechie/r2tohtml @leadertechie/md2html

Note: @leadertechie/md2html is a peer dependency and must be installed alongside r2tohtml.

Usage

Basic Usage

import { R2ContentLoader } from '@leadertechie/r2tohtml';

const loader = new R2ContentLoader({
  bucket: env.CONTENT_BUCKET,  // Cloudflare R2 binding
  cacheTTL: 5 * 60 * 1000,    // 5 minutes (default)
  cacheEnabled: true           // Enable caching (default: true)
});

// Fetch a file
const content = await loader.get('about.md');

// Fetch with metadata (parses YAML frontmatter)
const { metadata, content } = await loader.getWithMetadata('blog/post.md');

// List files in a prefix
const result = await loader.list('blogs/');

Configuration

import { R2ContentLoader } from '@leadertechie/r2tohtml';

const loader = new R2ContentLoader({
  // R2 bucket binding (required)
  bucket: env.CONTENT_BUCKET,
  
  // Optional prefix for all operations
  prefix: 'content/',
  
  // Cache TTL in milliseconds (default: 5 minutes)
  cacheTTL: 5 * 60 * 1000,
  
  // Enable/disable caching (default: true)
  cacheEnabled: true
});

API

R2ContentLoader

| Method | Description | |--------|-------------| | get(path: string): Promise<string | null> | Fetch file content as string | | getObject(path: string): Promise<R2Object | null> | Fetch raw R2 object | | getWithMetadata(path: string): Promise<ParsedContent | null> | Fetch and parse frontmatter | | list(prefix: string): Promise<R2ListResult> | List files with prefix | | exists(path: string): Promise<boolean> | Check if file exists | | invalidate(path: string): void | Invalidate cache for specific path | | invalidatePrefix(prefix: string): void | Invalidate cache for prefix | | clearCache(): void | Clear all cached data | | disableCache(): void | Disable caching | | enableCache(): void | Enable caching |

Types

interface R2LoaderConfig {
  bucket: R2Bucket;
  prefix?: string;
  cacheTTL?: number;
  cacheEnabled?: boolean;
}

interface ParsedContent {
  metadata: ContentMetadata;
  content: string;
}

interface ContentMetadata {
  [key: string]: string | string[] | undefined;
  title?: string;
  description?: string;
  date?: string;
  tags?: string[];
  author?: string;
}

Example: Using with md2html

import { R2ContentLoader } from '@leadertechie/r2tohtml';
import { MarkdownPipeline } from '@leadertechie/md2html';

const r2 = new R2ContentLoader({
  bucket: env.CONTENT_BUCKET,
  prefix: 'content/'
});

const pipeline = new MarkdownPipeline({
  imagePathPrefix: 'images/'
});

// Fetch and render markdown content
const content = await r2.get('home.md');
const html = pipeline.renderMarkdown(content);

License

MIT