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-trim

v0.1.0

Published

Losslessly shorten LLM prompts: whitespace, dedup, format compression. Drop-in middleware + CLI.

Readme

prompt-trim

Losslessly shorten LLM prompts. Drop-in middleware + CLI. Zero dependencies, idempotent, transform-by-transform opt-out.

npx prompt-trim request.json --report > trimmed.json
# prompt-trim: 14820 -> 12430 tokens (-2390, -16%) | 4 dup paragraphs | 7 tools trimmed

What it does

| transform | confidence | description | |-----------|------------|-------------| | collapse-blank-lines | high | runs of 3+ blank lines -> 2 | | trim-trailing-whitespace | high | strip trailing spaces/tabs per line | | trim-leading-trailing-doc | high | strip leading/trailing whitespace from message | | collapse-spaces | high | runs of 3+ spaces inside a line -> 1 (skips code fences) | | normalize-line-endings | high | CRLF/CR -> LF | | compact-list-bullets | high | * and + bullets -> - | | strip-html-comments | high | drop <!-- ... --> | | compress-horizontal-rules | high | normalize ***, ___, etc. -> --- | | reduce-md-headings | medium | #### and deeper -> **bold** | | replace-verbose-fillers | medium | "in order to" -> "to", strip "please make sure to" | | dedup-paragraphs | high | drop verbatim paragraphs after first occurrence across messages | | trim-tools | high | drop additionalProperties: false, empty required: [], $schema, schema examples; collapse description whitespace |

Confidence levels:

  • high runs at every level. Tested across GPT-4o, Claude 3.5 Sonnet/Haiku, Gemini 1.5/2.5.
  • medium runs at the default medium level. Spot-checked but changes the visible markup style.
  • Aggressive level is reserved for future opt-in transforms; it currently behaves the same as medium.

Code blocks (``` fenced and `single-backtick`) are preserved verbatim by every transform that touches text content.

Install

npm i prompt-trim
# or as CLI
npx prompt-trim request.json

CLI

prompt-trim request.json --report > trimmed.json
prompt-trim request.json --in-place
cat req.json | prompt-trim --stdin --json-report
prompt-trim request.json --level safe          # high-confidence only
prompt-trim request.json --aggressive          # all transforms
prompt-trim request.json --disable replace-verbose-fillers
prompt-trim request.json --enable-only collapse-blank-lines,strip-html-comments
prompt-trim request.json --no-dedup

Library

const { trim } = require('prompt-trim');

const result = trim({
  messages: [
    { role: 'system', content: '   You are helpful.\n\n\n\n   Respond in JSON.   ' },
    { role: 'user', content: 'hello' },
  ],
  tools: [],
  level: 'medium',
});

// result.messages          - shortened messages
// result.tools             - shortened tool defs
// result.stats.tokensBefore
// result.stats.tokensAfter
// result.stats.percentSaved
// result.stats.duplicateParagraphsDropped
// result.stats.toolsTrimmed

As OpenAI middleware

const OpenAI = require('openai');
const { trim } = require('prompt-trim');

const client = new OpenAI();

async function call(body) {
  const trimmed = trim(body);
  return client.chat.completions.create({ ...body, ...trimmed });
}

As Anthropic middleware

const Anthropic = require('@anthropic-ai/sdk');
const { trim } = require('prompt-trim');

const client = new Anthropic();

async function call(body) {
  const t = trim({ messages: body.messages, system: body.system, tools: body.tools });
  return client.messages.create({ ...body, messages: t.messages, tools: t.tools });
}

Idempotency

const { trim, isIdempotent } = require('prompt-trim');
isIdempotent({ messages: [...] }); // true - safe to apply more than once

This matters for retries, replays, and caches: trimming the same input twice is guaranteed equivalent to trimming it once.

Companion tools

  • prompt-medic - audit first to see where the waste is.
  • prompt-cache-key - structure prompts so OpenAI / Anthropic prompt caching actually hits.

License

MIT.