Registry / ai-ml / prompt-minifier

prompt-minifier

JSON →
library0.1.1jsnpmunverified

Token-aware prompt minifier with explainable diff, version 0.1.1. Shrinks LLM prompts by replacing verbose phrases with shorter equivalents, providing a detailed diff of changes. Supports multiple optimization levels (safe, balanced, aggressive) and custom tokenizers. Zero runtime dependencies, ESM/CJS, TypeScript types included. Released under MIT license.

npm install prompt-minifier
INSTALL
IMPORT
SIG · PROMPT-MINIFIER
P
prompt-minifier
ai-mljavascriptv0.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

minify
import { minify } from 'prompt-minifier'
import minify from 'prompt-minifier'
Named import required; default import not available.
Level
import { Level } from 'prompt-minifier'
import { level } from 'prompt-minifier'
TypeScript type; case-sensitive.
MinifyOptions
import type { MinifyOptions } from 'prompt-minifier'
Type import for configuration object.
MinifyResult
import type { MinifyResult } from 'prompt-minifier'
Type import for return value.

Demonstrates basic minify usage with balanced level, showing token savings and detailed changes.

import { minify } from 'prompt-minifier'; const prompt = 'In order to win, please could you take into consideration the fact that, due to the fact that we are at this point in time absolutely essential, you must respond in a timely manner.'; const result = minify(prompt, { level: 'balanced' }); console.log(`Before: ${result.tokensBefore} tokens`); console.log(`After: ${result.tokensAfter} tokens`); console.log(`Savings: ${result.savings.tokenPercent.toFixed(1)}%`); console.log(`Changes: ${result.changes.length}`); for (const c of result.changes) { console.log(`${c.rule}: "${c.from}" -> "${c.to}"`); }
Debug
Known issues
breakingVersion 0.1.1 is the first release; expect API changes in future versions.
fix
Pin to exact version and watch for breaking releases.
affects: 0.1.1
gotchaToken estimation by default uses character count divided by 4; actual token counts may vary significantly with different tokenizers.
fix
Pass a custom tokenizer function for accurate counts (e.g., from gpt-tokenizer or tiktoken).
affects: >=0.1.0
gotchaThe CLI tool is not documented beyond basic usage; advanced options like --diff and --json may not work as expected in all environments.
fix
Test CLI commands thoroughly or use the library API directly.
affects: >=0.1.0
deprecatedNo deprecated features at this early version.
fix
N/A
affects: 0.1.1
Errors
Common errors & fixes
Cannot find module 'prompt-minifier'
Package not installed or incorrect import path.
fix
npm install prompt-minifier
import { minify } from 'prompt-minifier'; SyntaxError: The requested module 'prompt-minifier' does not provide an export named 'minify'
Using CommonJS require instead of ES import or out-of-date package.
fix
Ensure Node >=18 and use ES module (type: module in package.json or .mjs extension).
TypeError: minify is not a function
Default import used instead of named import.
fix
Use import { minify } from 'prompt-minifier' instead of import minify from 'prompt-minifier'.
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
prompt-minifier — npm install prompt-minifier · libregistry