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

fetchoraw

v1.2.8

Published

A simple resolver-based URL transformer for Astro and CMS-driven projects.

Readme

Fetchoraw

npm version MIT License type: module

Fetchoraw is a small library to rewrite asset URLs in HTML. You can replace src, href, and other attributes using your own resolver.

Read this page in Japanese →


✨ Features

  • Rewrite asset links in HTML or structured content
  • Fully customizable with your own resolver
  • Supports both full HTML rewriting and individual URL resolution
  • Built-in resolvers for data URLs, file saving, smart handling
  • Gracefully handles environments like Cloudflare Workers where Node.js modules are unavailable.

📦 Install

npm install fetchoraw

🚀 Usage

Rewrite HTML with a custom resolver

import { Fetchoraw } from 'fetchoraw';

const resolver = async (url: string) =>
  url.replace('https://cdn.example.com/', '/assets/');

const fetchoraw = new Fetchoraw(resolver);
const { html, map } = await fetchoraw.html(
  '<img src="https://cdn.example.com/logo.png">'
);

console.log(html); // <img src="/assets/logo.png">
console.log(map);  // [{ url: 'https://cdn.example.com/logo.png', resolvedPath: '/assets/logo.png' }]

Resolve a single URL

const fetchoraw = new Fetchoraw(resolver);
const result = await fetchoraw.url('https://cdn.example.com/logo.png');

console.log(result.path); // /assets/logo.png

🛠 API Overview

Fetchoraw

new Fetchoraw(resolver, options?)
  • resolver: (url: string, options?: RequestInit) => Promise<string | { path: string, data?: unknown }>
  • options.envModeName?: env var name to control rewriting (default: PUBLIC_FETCHORAW_MODE)
  • options.enableFetchEnvValue?: value to enable rewriting (default: FETCH)
  • options.enableCacheEnvValue?: value to read from cache (default: CACHE)
  • options.cacheFilePath?: file to store cache (default: cache/fetchoraw_cache.json)

Methods

html(html: string, config?)
  • config.selectors?: selectors/attributes to rewrite (default presets: img[src], source[srcset], etc.)
  • Returns { html, map }
url(url: string, origin?, fetchOptions?)
  • Resolves a single URL
  • Returns { path, data?, map }

🧙 Built-in Resolvers

You can use any of the included resolvers depending on your use case:

createImageDataUrlResolver()

Fetches and inlines assets as base64 data: URLs.

import { createImageDataUrlResolver } from 'fetchoraw/resolvers';

const resolver = createImageDataUrlResolver();

Options:

  • inlineLimitBytes: max size to inline (default: 2MB)
  • allowMimeTypes: allowed types (default: image/audio/video/pdf)

createImageFileSaveResolver()

Saves remote assets to the local filesystem.

import { createImageFileSaveResolver } from 'fetchoraw/resolvers';

const resolver = createImageFileSaveResolver({
  saveRoot: 'public/assets',
  prependPath: 'assets'
});

Options:

  • saveRoot: root folder to store files (default: dist/assets)
  • prependPath: prefix in rewritten paths (default: assets)
  • keyString: pattern to strip from saved paths (default: URL base)

createImageSmartResolver()

Combines data: and file saving based on file size and URL pattern.

import { createImageSmartResolver } from 'fetchoraw/resolvers';

const resolver = createImageSmartResolver({
  inlineLimitBytes: 500000,
  requireFilePatterns: [/\.svg$/]
});
  • Small files are inlined
  • Larger or matching requireFilePatterns are saved to file

createJsonFileSaveResolver()

Fetches JSON and saves both the file and parsed data.

import { createJsonFileSaveResolver } from 'fetchoraw/resolvers';

const resolver = createJsonFileSaveResolver();

Useful for working with CMS APIs, feeds, config files, etc.


📄 License

MIT