Skip to content

PromptScript API


Function: format()

format(ast, options): FormatterOutput

Defined in: formatters/src/standalone.ts:49

Format a PromptScript AST using a specified or default formatter.

This is a convenience function for one-off formatting without manually creating formatter instances. For repeated formatting operations, consider using the formatter classes directly for better performance.

Parameters

ast

Program

The resolved PromptScript AST to format

options

StandaloneFormatOptions = {}

Format options including which formatter to use

Returns

FormatterOutput

The formatter output (path and content)

Throws

Error if the specified formatter is not found

Example

import { format } from '@promptscript/formatters';

// Use default formatter (GitHub)
const output = format(ast);

// Specify formatter by name
const claudeOutput = format(ast, { formatter: 'claude' });

// Use custom options
const cursorOutput = format(ast, {
  formatter: 'cursor',
  version: 'legacy',
});