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

llm-context-code-stripper

v0.1.0

Published

Strip large base64 data: URIs and raw base64 blobs out of source code before sending it to an LLM — saves context-window tokens and keeps prompts within request size limits. Works with OpenAI, Claude, and any LLM. Zero dependencies.

Readme

llm-context-code-stripper

Strip large base64 data: URIs and raw base64 blobs out of source code before you send it to an LLM.

npm version license: MIT

Why

Source files often inline sprites, audio, fonts, or images as base64 data: URIs or raw base64 string literals. A single asset can balloon a file to hundreds of kilobytes even though the actual logic is tiny.

When you feed that code to an LLM, those blobs are pure waste:

  • The model can't read base64 anyway — it's opaque noise to the tokenizer.
  • It burns context-window tokens — a 770 KB sprite can eat your entire budget and crowd out the real code.
  • It can blow past request size limits — pushing you over provider payload caps for no benefit.

llm-context-code-stripper replaces those blobs with a short placeholder while leaving the real code untouched. It's a pure, synchronous function with zero runtime dependencies, safe for both browser and server bundles.

- const sprite = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...770KB...";
+ const sprite = "data:[STRIPPED]";

Install

npm install llm-context-code-stripper
pnpm add llm-context-code-stripper
yarn add llm-context-code-stripper

Usage

Quick clean

import { stripCode } from "llm-context-code-stripper";

const cleaned = stripCode(sourceCode);
// send `cleaned` to your LLM instead of the raw file

With stats

import { stripBase64Assets } from "llm-context-code-stripper";

const result = stripBase64Assets(sourceCode);

console.log(result);
// {
//   code: "const sprite = \"data:[STRIPPED]\"; ...",
//   beforeBytes: 812345,
//   afterBytes: 33012,
//   dataUrisStripped: 1,
//   rawBase64Stripped: 0,
// }

const saved = result.beforeBytes - result.afterBytes;
console.log(`Trimmed ${(saved / 1024).toFixed(0)} KB before sending to the LLM`);

Custom placeholder and thresholds

import { stripBase64Assets } from "llm-context-code-stripper";

const result = stripBase64Assets(sourceCode, {
  placeholder: "<asset removed>",
  minDataUriLength: 100, // strip smaller data: URIs than the default 200
  minRawBase64Length: 512, // strip smaller raw base64 blobs than the default 1024
});

Measuring payload size

import { byteLength } from "llm-context-code-stripper";

byteLength("hello"); // 5
byteLength("😀"); // 4 — correct utf-8 byte count, not string length

API

stripBase64Assets(code, options?): StripResult

Strips large data: URIs and raw base64 string literals from code, returning the cleaned code plus statistics.

| Option | Type | Default | Description | | -------------------- | -------- | -------------- | ------------------------------------------------------------------- | | placeholder | string | "[STRIPPED]" | Replacement token substituted for each stripped blob. | | minDataUriLength | number | 200 | Minimum length (chars) of a quoted data: URI before it's stripped. | | minRawBase64Length | number | 1024 | Minimum length (chars) of a raw base64 literal before it's stripped. |

Returns StripResult:

| Field | Type | Description | | ------------------- | -------- | -------------------------------------------------- | | code | string | The cleaned source code. | | beforeBytes | number | Byte length (utf-8) of the input, before stripping. | | afterBytes | number | Byte length (utf-8) of the output, after stripping. | | dataUrisStripped | number | Number of data: URIs that were replaced. | | rawBase64Stripped | number | Number of raw base64 literals that were replaced. |

stripCode(code): string

Convenience wrapper that returns only the cleaned code. Use stripBase64Assets directly when you need the stats.

byteLength(code): number

Returns the utf-8 byte length of a string via TextEncoder, falling back to String.length when TextEncoder is unavailable. Useful for measuring real payload size before and after stripping.

How it works

Two conservative regular expressions target only asset-shaped strings:

  • data: URIs — any quoted (", ', or `) data: URI at or above minDataUriLength characters. The floor prevents removing tiny inline icons an LLM might legitimately read.
  • Raw base64 literals — any quoted string of at least minRawBase64Length continuous base64 characters (A–Z a–z 0–9 + / =) that is not a data: URI. The high default keeps normal long constants (URLs, ids, prompts) safe.

Everything else — your actual code — is left byte-for-byte intact.

License

MIT © 2026 oratis