Skip to content

Pakeetharan/PromptFold

Repository files navigation

PromptFold

License Next.js TypeScript PRs Welcome

Convert rich text into deterministic, token-compact prompts optimized for LLM usage.

PromptFold is a production-ready web application that transforms rich text input (with formatting, lists, paragraphs) into clean, token-efficient prompts suitable for Large Language Models. It strips visual styling while preserving document structure, ensuring consistent and optimized output.

πŸ”— Live Demo | πŸ“– Documentation


✨ Features

  • πŸ“ Rich Text Input: Paste formatted text with paragraphs, numbered lists, bullet lists, and mixed formatting
  • 🎯 Deterministic Transformation: Same input always produces the same output
  • πŸš€ Token Optimization: Removes redundant whitespace and normalizes formatting
  • πŸ“Š Accurate Token Counter: Real-time token counting using GPT tokenizer
  • πŸ“‹ One-Click Copy: Copy optimized prompt to clipboard instantly
  • πŸ“± Responsive Design: Works seamlessly on desktop, tablet, and mobile devices
  • 🌐 No Backend Required: Runs entirely in the browser
  • ⚑ Lightweight: Minimal dependencies for fast performance

🎯 Why PromptFold?

When working with LLMs, token efficiency matters. PromptFold helps you:

  • Reduce costs by minimizing token usage
  • Improve clarity by removing visual noise
  • Ensure consistency with deterministic transformations
  • Save time with instant copy-paste workflow

πŸ”„ Transformation Rules

The application applies the following rules to optimize your text:

  1. Whitespace Normalization

    • Trim leading and trailing spaces per line
    • Collapse multiple spaces inside a line into one
    • Remove empty lines completely
  2. Structure Preservation

    • Each paragraph becomes one single line
    • Paragraphs separated by exactly one \n
    • Meaningful line breaks preserved using \n
  3. List Handling

    • Numbered lists remain numbered (1. 2. 3. format)
    • Bullet lists converted to "- item" format
    • Nested lists with different types: Main item keeps format, sub-items use dash
    • Nested lists with same type: Converted to - main: sub1, sub2, sub3 format
  4. Visual Formatting Ignored

    • Colors, font sizes, bold, italics, underline removed
    • Only document structure matters

πŸ“¦ Tech Stack

πŸš€ Getting Started

Prerequisites

  • Node.js 18.x or higher
  • npm, yarn, or pnpm

Installation

  1. Clone the repository:
git clone https://github.com/Pakeetharan/PromptFold.git
cd PromptFold
  1. Install dependencies:
npm install
  1. Run the development server:
npm run dev
  1. Open your browser:

Navigate to http://localhost:3000

Build for Production

npm run build
npm start

πŸ’‘ Usage Example

Input (Rich Text):

Welcome to PromptFold

Here are the features:
1. Token optimization
   β€’ Fast processing
   β€’ Low cost
2. Deterministic output
3. Real-time processing

Key benefits:
β€’ Faster processing
β€’ Lower costs
β€’ Better results

Output (Optimized):

Welcome to PromptFold
Here are the features:
1. Token optimization: Fast processing, Low cost
2. Deterministic output
3. Real-time processing
Key benefits:
- Faster processing
- Lower costs
- Better results

πŸ—οΈ Architecture

Project Structure

PromptFold/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ layout.tsx          # Root layout with metadata
β”‚   β”‚   β”œβ”€β”€ page.tsx            # Main application page
β”‚   β”‚   └── globals.css         # Global styles and Tailwind
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ RichTextInput.tsx   # Editable rich text input
β”‚   β”‚   └── PromptOutput.tsx    # Read-only output with copy
β”‚   └── utils/
β”‚       β”œβ”€β”€ transformer.ts      # Core transformation logic
β”‚       └── tokenCounter.ts     # Token estimation algorithm
β”œβ”€β”€ package.json
β”œβ”€β”€ tsconfig.json
β”œβ”€β”€ tailwind.config.ts
└── next.config.js

Key Components

  • transformer.ts: Pure utility functions for text transformation
  • tokenCounter.ts: Accurate GPT token counting using gpt-tokenizer library
  • RichTextInput: ContentEditable div with paste handling
  • PromptOutput: Read-only textarea with copy button and live stats

🚒 Deployment

Deploy to Netlify (Recommended)

  1. Push to GitHub (see instructions below)
  2. Connect to Netlify:
    • Visit netlify.com
    • Click "Add new site" β†’ "Import an existing project"
    • Select your GitHub repository
    • Build settings are auto-detected
    • Click "Deploy"

Deploy to Vercel

npm install -g vercel
vercel

Other Platforms

  • AWS Amplify: Connect GitHub repository
  • Docker: Use the included configuration
  • Static hosting: Run npm run build and deploy the out folder

🀝 Contributing

We welcome contributions! Here's how you can help:

Ways to Contribute

  • πŸ› Report bugs: Open an issue describing the problem
  • ✨ Suggest features: Share your ideas in the discussions
  • πŸ“– Improve documentation: Fix typos or add examples
  • πŸ”§ Submit PRs: Fix bugs or add new features

Development Guidelines

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes
  4. Test thoroughly: Ensure all existing functionality still works
  5. Commit with clear messages: git commit -m 'Add amazing feature'
  6. Push to your fork: git push origin feature/amazing-feature
  7. Open a Pull Request

Code Standards

  • Follow TypeScript strict mode
  • Use Prettier for formatting
  • Write clear, descriptive comments
  • Keep transformation logic deterministic
  • Avoid unnecessary dependencies

πŸ§ͺ Testing

The transformation logic is implemented as pure functions, making testing straightforward:

import { transformToPrompt } from './utils/transformer';

// Test deterministic output
const input = '<p>Hello World</p>';
const output = transformToPrompt(input);
expect(output).toBe('Hello World');

πŸ› Known Issues & Limitations

  • Very deeply nested lists may not format perfectly
  • Browser compatibility requires modern JavaScript features

πŸ“‹ Roadmap

  • Exact token counting using gpt-tokenizer βœ…
  • Dark mode support
  • Export to file functionality
  • Undo/redo functionality
  • Custom transformation rules
  • Batch processing
  • API endpoint option

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘¨β€πŸ’» Author

Your Name

πŸ™ Acknowledgments

⭐ Show Your Support

If this project helps you, please give it a ⭐ on GitHub!


Made with ❀️ for the AI community

About

Convert rich text into token-optimized prompts for LLMs

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors