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

ai-prompt-optimizer

v0.2.1

Published

A TypeScript library for optimizing prompts for Large Language Models (LLMs) like GPT, Claude, and Gemini

Readme

AI Prompt Optimizer 🚀

npm version License: MIT TypeScript

A powerful TypeScript library for optimizing prompts for Large Language Models (LLMs) like GPT, Claude, and Gemini. Automatically analyze, enhance, and score your AI prompts for better results.

✨ Features

  • 🔍 Intelligent Analysis: Deep analysis of prompt structure, clarity, and potential issues
  • ⚡ Multi-Mode Optimization: Generate optimized versions focused on conciseness, creativity, or safety
  • 📊 Comprehensive Scoring: Evaluate prompts on readability, token efficiency, ambiguity, and more
  • 🛠️ CLI & API: Use programmatically or via command line interface
  • 🔧 Extensible: Add custom optimization rules for your specific needs
  • 🌐 Multi-Language: Supports English, Turkish, and more languages
  • 🔒 Safety First: Built-in content safety analysis and optimization

📦 Installation

npm install ai-prompt-optimizer

For CLI usage:

npm install -g ai-prompt-optimizer

🚀 Quick Start

Programmatic Usage

import { optimizePrompt } from 'ai-prompt-optimizer';

const result = await optimizePrompt("Write me a story about a doctor and patient.");

console.log('Original:', result.analysis.original);
console.log('Concise:', result.optimizations.concise.text);
console.log('Creative:', result.optimizations.creative.text);
console.log('Safe:', result.optimizations.safe.text);

// View scores
console.log('Scores:', {
  conciseness: result.scores.original.conciseness,
  creativity: result.scores.original.creativity,
  safety: result.scores.original.safety
});

CLI Usage

# Optimize a prompt
ai-prompt-optimizer "Create a comprehensive marketing plan for a new product"

# Optimize with specific mode
apo "Write code for user authentication" --mode concise

# Analyze from file
apo --file prompt.txt --verbose

# Save results
apo "Generate creative content" --output results.txt --json

📖 API Reference

optimizePrompt(prompt, config?)

Optimizes a prompt with comprehensive analysis and multiple optimization strategies.

Parameters:

  • prompt (string): The original prompt text
  • config (OptimizerConfig, optional): Configuration options

Returns: Promise<OptimizePromptResult>

interface OptimizePromptResult {
  analysis: PromptAnalysis;
  optimizations: {
    concise: OptimizationResult;
    creative: OptimizationResult;  
    safe: OptimizationResult;
  };
  scores: {
    original: PromptScores;
    concise: PromptScores;
    creative: PromptScores;
    safe: PromptScores;
  };
  recommendations: string[];
}

AIPromptOptimizer Class

For more control, use the main class:

import { AIPromptOptimizer } from 'ai-prompt-optimizer';

const optimizer = new AIPromptOptimizer({
  maxTokens: 100,
  minSafetyScore: 0.8
});

// Add custom rules
optimizer.addCustomRule({
  name: 'Remove Redundancy',
  description: 'Removes redundant phrases',
  apply: (text) => text.replace(/\b(\w+)\s+\1\b/gi, '$1'),
  modes: ['concise'],
  priority: 5
});

const result = await optimizer.optimizePrompt("Your prompt here");

🎯 Optimization Modes

Concise Mode

Focuses on brevity and clarity:

  • Removes unnecessary filler words
  • Replaces verbose phrases with concise alternatives
  • Eliminates redundancy
  • Maintains core meaning

Creative Mode

Enhances creative potential:

  • Adds imaginative vocabulary
  • Includes open-ended elements
  • Encourages diverse perspectives
  • Maintains engagement

Safe Mode

Prioritizes content safety:

  • Removes sensitive information
  • Adds appropriate disclaimers
  • Uses respectful language
  • Prevents harmful instructions

📊 Scoring Metrics

Each prompt is evaluated on multiple dimensions:

  • Conciseness (0-1): How brief yet complete the prompt is
  • Creativity (0-1): Presence of creative and engaging elements
  • Safety (0-1): Absence of harmful or sensitive content
  • Readability (0-1): How easy the prompt is to understand
  • Token Efficiency (0-1): Optimal use of tokens for the content
  • Ambiguity (0-1): Lower scores mean less ambiguous prompts

🛠️ CLI Commands

Basic Usage

# Optimize any prompt
apo "Your prompt here"

# Use specific optimization mode
apo "Your prompt" --mode creative

# Get verbose analysis
apo "Your prompt" --verbose

File Operations

# Read prompt from file
apo --file input.txt

# Save results to file
apo "Your prompt" --output results.txt

# JSON output for programmatic use
apo "Your prompt" --json --output data.json

Analysis Only

# Analyze without optimization
apo analyze "Your prompt here"

# Analyze file
apo analyze --file prompt.txt

🔧 Custom Rules

Create custom optimization rules for specific needs:

const customRule = {
  name: 'Technical Terms',
  description: 'Adds technical precision to prompts',
  apply: (text: string) => {
    return text.replace(/\bmake\b/gi, 'implement')
               .replace(/\bfix\b/gi, 'resolve');
  },
  modes: ['concise', 'safe'],
  priority: 7
};

optimizer.addCustomRule(customRule);

📝 Examples

E-commerce Product Description

const result = await optimizePrompt(
  "Please write a really good description for our new smartphone that has lots of features"
);

// Concise: "Write a compelling description for our feature-rich new smartphone"
// Creative: "Craft an engaging description showcasing our innovative new smartphone's unique features"  
// Safe: "Please create a professional description highlighting our new smartphone's key features"

Code Generation

const result = await optimizePrompt(
  "I need some code that does user authentication stuff with login and maybe password reset"
);

// Concise: "Generate user authentication code with login and password reset"
// Creative: "Design a comprehensive user authentication system featuring login and password reset capabilities"
// Safe: "Please create secure user authentication code including login and password reset functionality"

🏗️ Project Structure

src/
├── core/
│   ├── analyzer.ts      # Prompt analysis engine
│   ├── optimizer.ts     # Optimization strategies  
│   └── scorer.ts        # Scoring algorithms
├── types/
│   └── index.ts         # TypeScript definitions
├── cli.ts               # Command line interface
└── index.ts             # Main API exports

🧪 Testing

# Run tests
npm test

# Run with coverage  
npm run test:coverage

# Watch mode for development
npm run test:watch

🚀 Building

# Build the library
npm run build

# Development mode with watch
npm run dev

# Linting and formatting
npm run lint
npm run format

👨‍💻 About the Author

Hey 👋 This is Ahmet KAHRAMAN

💻 I'm a Mobile Developer & Cyber Security Expert
🔗 My home on the net is ahmetxhero.web.app
🎥 I have my own YouTube channel - @ahmetxhero - Haven't you subscribed yet?
🗣️ I enjoy speaking at tech events. Are you interested in having me speak at your event?
📫 You can reach me by email at [email protected]
🐤 You can find me on Twitter as @ahmetxhero
💼 You can visit my LinkedIn for more info about my professional career
🎓 You can check out my Google Scholar or ResearchGate profiles to find my academic publications
📷 You can follow me on Instagram
🤖 I'm passionate about mobile development and cybersecurity solutions
💬 I heavily inspired by the mantra - "Security first, innovation always"
🏠 I'm living in Ankara, Turkey 🇹🇷
🌟 I am a Mobile Developer with 10+ years of experience in Public Sector IT
☕ You can support my open source work on GitHub or buy me a coffee

🛠️ My Tech Stack & Expertise

Mobile Development

  • iOS: Swift, Objective-C, UIKit, SwiftUI
  • Android: Java, Kotlin, Android SDK
  • Cross-Platform: Flutter, React Native
  • Frameworks: Xamarin, Ionic

Cybersecurity & Forensics

  • Digital Forensics: EnCase, FTK, Autopsy, Volatility
  • Penetration Testing: Metasploit, Burp Suite, Nmap
  • Security Tools: Wireshark, OWASP ZAP, Nessus
  • Programming: Python, PowerShell, Bash

System Administration

  • Operating Systems: Windows Server, Linux (Ubuntu, CentOS)
  • Virtualization: VMware, Hyper-V, VirtualBox
  • Cloud Platforms: AWS, Azure, Google Cloud
  • Networking: TCP/IP, DNS, DHCP, VPN

📊 Professional Experience

Current Role
Mobile Developer / Mobile System Operator
Gendarmerie General Command | July 2024 - Present
📍 Ankara, Turkey

Previous Experience

  • IT Expert | Gendarmerie General Command (2015-2024)
  • Founder | Sadık Internet Cafe (2012-2014)

🎓 Education

  • Master's Degree in Forensic Informatics | Gazi University (2021-2023)
  • Bachelor's Degree in Health Management | Anadolu University (2017-2021)
  • Associate's Degree in Computer Programming | Atatürk University (2020-2023)
  • Associate's Degree in Occupational Health & Safety | Atatürk University (2016-2019)

🌐 Connect With Me

| Platform | Link | Description | |----------|------|-------------| | 🌐 Portfolio | ahmetxhero.web.app | My personal website | | 💼 LinkedIn | linkedin.com/in/ahmetxhero | Professional network | | 🎥 YouTube | youtube.com/@ahmetxhero | Tech tutorials & content | | 📝 Medium | ahmetxhero.medium.com | Technical articles | | 🐤 Twitter | x.com/ahmetxhero | Tech thoughts & updates | | 📷 Instagram | instagram.com/ahmetxhero | Behind the scenes | | 🎮 Twitch | twitch.tv/ahmetxhero | Live coding sessions | | 🎨 Dribbble | dribbble.com/ahmetxhero | Design portfolio | | 🎨 Figma | figma.com/@ahmetxhero | UI/UX designs |

🏆 Certifications & Achievements

  • ✅ Microsoft Certified Professional
  • ✅ Certified Ethical Hacker (CEH)
  • ✅ Digital Forensics Expert
  • ✅ iOS & Swift Development
  • ✅ Flutter Development
  • ✅ Android Development

🎯 Current Focus

  • 🔒 Cybersecurity: Developing secure mobile applications
  • 📱 Mobile Development: Creating innovative iOS and Android apps
  • 🔍 Digital Forensics: Advancing forensic investigation techniques
  • 📚 Knowledge Sharing: Contributing to the tech community
  • 🌟 Open Source: Building tools for the developer community

"Building secure, innovative solutions for a better digital future" 🚀


📄 License

MIT License - see LICENSE for details.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

🌟 Roadmap

  • [ ] Integration with OpenAI/Anthropic APIs for dynamic optimization
  • [ ] Support for more languages
  • [ ] Advanced prompt templates
  • [ ] Visual prompt builder
  • [ ] Plugin system for popular IDEs
  • [ ] Web interface for prompt optimization

📞 Support


Made with ❤️ for the AI community by Ahmet KAHRAMAN