Skip to main content

Introduction

Learn about format-prompt – a utility to format prompts for cleaner presentation and optimal token usage
1 min read

format-prompt#

A utility to format prompts for a cleaner presentation and optimal token usage. Removes unused spaces and line breaks, and supports template literals.

Why format-prompt?#

When working with LLMs and AI prompts, you often want to write readable, well-formatted prompts in your code with proper indentation. However, this adds unnecessary whitespace that wastes tokens and can affect prompt quality.

format-prompt solves this by:

  • Removing leading and trailing whitespace from each line
  • Collapsing multiple spaces into single spaces
  • Trimming unnecessary line breaks
  • Supporting template literal interpolation
  • Maintaining the structure and readability of your code

Quick Example#

Key Features#

  • Template Literal Support: Works seamlessly with JavaScript/TypeScript template literals
  • Smart Formatting: Removes unnecessary whitespace while preserving structure
  • Small Bundle Size: Minimal dependencies for optimal performance
  • TypeScript Support: Full type safety out of the box
  • Zero Configuration: Works out of the box with sensible defaults

Installation#

Basic Usage#