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

prompt-compressor

v1.0.0

Published

Rule-based prompt compression — reduce LLM token usage without a model, without an API, without sending data anywhere.

Readme

prompt-compressor

Rule-based prompt compression — reduce LLM token usage without a model, without an API, without sending data anywhere.

npm

Install

npm install prompt-compressor

Quick start

import { compress } from 'prompt-compressor';

const { output, stats } = compress(systemPrompt, 'low');

console.log(stats);
// { tokensBefore: 1200, tokensAfter: 820, saved: 380, reductionPct: 31 }

Risk levels

Pick a level — every algorithm at or below that risk runs automatically.

| Level | What runs | Typical saving | |---|---|---| | 'none' | Whitespace, unicode normalization, indentation | 5–15% | | 'very-low' | + Filler removal, phrase shortening, JSON/SQL minify | 15–30% | | 'low' | + Hedging removal, code comments, deduplication, stack trace truncation | 25–45% | | 'medium' | + Fuzzy dedup, TF-IDF, TextRank (may drop sentences) | 30–70% |

compress(text, 'none')      // safest
compress(text, 'very-low')
compress(text, 'low')       // recommended default
compress(text, 'medium')    // most aggressive

Custom options

Override specific algorithms or parameters:

const { output, stats } = compress(text, {
  level: 'low',         // base level

  // enable something above your level
  tfidf: true,
  tfidfRatio: 0.7,      // keep 70% of sentences

  // disable something in your level
  codeComments: false,  // keep code comments intact
});

In a MCP server

import { compress } from 'prompt-compressor';

// Before every Bedrock call:
const { output } = compress(systemPrompt, 'low');

const response = await bedrock.invokeModel({
  body: JSON.stringify({ system: output, messages }),
  ...
});

Individual functions

All algorithms are exported individually:

import {
  removeFiller,
  tfidfCompress,
  deduplicateLines,
  fuzzyDeduplicate,
  estimateTokens,
} from 'prompt-compressor';

const cleaned = removeFiller(text);
const compressed = tfidfCompress(cleaned, 0.7);
console.log(estimateTokens(compressed));

Variable protection

Prompt variables are automatically detected and preserved — compression never breaks your templates.

Supported: {{var}}, {var}, ${var}, <tag>, [[var]], %VAR%

// This is safe:
compress("Please {{user_name}}, utilize this in order to process {context}", 'low');
// → "Please {{user_name}}, use this to process {context}"
// Variables untouched, filler compressed.

Result shape

{
  output: string,
  stats: {
    tokensBefore: number,
    tokensAfter: number,
    saved: number,
    reductionPct: number,   // 0–100
  }
}

Algorithms reference

| Algorithm | Risk | What it does | |---|---|---| | compressWhitespace | none | Collapse spaces, tabs, excess blank lines | | normalizeUnicode | none | Smart quotes, em-dash, zero-width chars | | cleanPunctuation | none | !!!!, ???? | | stripLicenseHeaders | none | Remove copyright blocks from code | | normalizeIndentation | none | 4-space → 2-space in code blocks | | removeFiller | very-low | Remove "please note that", "e.g.", "i.e." clauses | | shortenPhrases | very-low | "in order to" → "to", "utilize" → "use" (50+ rules) | | numberWordsToNumerals | very-low | "twenty" → "20" | | normalizeDates | very-low | "Monday, Dec 25th 2023" → "2023-12-25" | | minifyJSON | very-low | Minify JSON code blocks | | minifySQL | very-low | Remove SQL comments, collapse whitespace | | removeHedging | low | Remove "perhaps", "it seems", "one might say" | | removeMetaCommentary | low | Remove "Here is...", "I hope this helps" | | removeParentheticals | low | Remove "(as mentioned above)", "(see below)" | | stripCodeComments | low | Remove //, /* */, # comments | | stripDocstrings | low | Remove Python/JSDoc documentation blocks | | removeNullJsonFields | low | Strip null/empty fields from JSON | | stripBase64AndHex | low | Replace long hashes with placeholders | | truncateStackTraces | low | Keep 4 frames, replace rest with count | | deduplicateLines | low | Remove duplicate lines | | deduplicateSentences | low | Remove duplicate sentences | | fuzzyDeduplicate | medium | Jaccard-based near-duplicate removal | | ngramDeduplicate | medium | Bigram/trigram near-duplicate removal | | levenshteinDeduplicate | medium | Edit-distance near-duplicate removal | | tfidfCompress | medium | Keep top sentences by TF-IDF score | | textRankCompress | medium | Keep top sentences by PageRank centrality | | extractiveCompress | medium | Keep top sentences by Term Frequency |

License

MIT