Installation#
Install format-prompt using your preferred package manager:
Basic Usage#
Importing#
Simple Example#
With Variables#
Complex Example#
How It Works#
The prompt function:
- Takes a template literal string with optional interpolated values
- Removes leading/trailing whitespace from each line
- Collapses multiple spaces into single spaces
- Preserves intentional line breaks
- Trims the final result
- Returns a clean, token-efficient string
TypeScript Support#
format-prompt is written in TypeScript and includes type definitions:
Best Practices#
- Use template literals: Leverage JavaScript's template literal syntax for clean code
- Indent for readability: Format your prompts for readability in code - the library will clean it up
- Use interpolation: Insert variables directly into your prompts
- Keep structure: The library preserves intentional line breaks and structure