Skip to main content

Getting Started

Quick start guide to install and use format-prompt in your JavaScript or TypeScript project
1 min read

Installation#

Install format-prompt using your preferred package manager:

Basic Usage#

Importing#

Simple Example#

With Variables#

Complex Example#

How It Works#

The prompt function:

  1. Takes a template literal string with optional interpolated values
  2. Removes leading/trailing whitespace from each line
  3. Collapses multiple spaces into single spaces
  4. Preserves intentional line breaks
  5. Trims the final result
  6. Returns a clean, token-efficient string

TypeScript Support#

format-prompt is written in TypeScript and includes type definitions:

Best Practices#

  1. Use template literals: Leverage JavaScript's template literal syntax for clean code
  2. Indent for readability: Format your prompts for readability in code - the library will clean it up
  3. Use interpolation: Insert variables directly into your prompts
  4. Keep structure: The library preserves intentional line breaks and structure

Common Patterns#

List Formatting#

Multi-line Instructions#

Dynamic Content#