Skip to content

PromptScript API


Abstract Class: BaseFormatter

Defined in: formatters/src/base-formatter.ts:9

Abstract base formatter with common helper methods. Extend this class to create new formatter implementations.

Extended by

Implements

Constructors

Constructor

new BaseFormatter(): BaseFormatter

Returns

BaseFormatter

Properties

defaultConvention

abstract readonly defaultConvention: string

Defined in: formatters/src/base-formatter.ts:13

Default convention for this formatter

Implementation of

Formatter.defaultConvention


description

abstract readonly description: string

Defined in: formatters/src/base-formatter.ts:12

Human-readable description

Implementation of

Formatter.description


name

abstract readonly name: string

Defined in: formatters/src/base-formatter.ts:10

Unique formatter identifier

Implementation of

Formatter.name


outputPath

abstract readonly outputPath: string

Defined in: formatters/src/base-formatter.ts:11

Default output file path

Implementation of

Formatter.outputPath

Methods

createRenderer()

protected createRenderer(options?): ConventionRenderer

Defined in: formatters/src/base-formatter.ts:20

Create a convention renderer for this formatter. Uses the provided convention from options or falls back to the default.

Parameters

options?

FormatOptions

Returns

ConventionRenderer


extractSectionWithCodeBlock()

protected extractSectionWithCodeBlock(text, header): string | null

Defined in: formatters/src/base-formatter.ts:140

Safe extraction of a section that contains a header + content + code block + content Avoids ReDoS by using string search instead of backtracking regex. Matches pattern: Header ... ...

Parameters

text

string

string

Returns

string | null


extractText()

protected extractText(content): string

Defined in: formatters/src/base-formatter.ts:42

Extract text from block content.

Parameters

content

BlockContent

Returns

string


findBlock()

protected findBlock(ast, name): Block | undefined

Defined in: formatters/src/base-formatter.ts:35

Find a block by name, ignoring internal blocks (starting with __).

Parameters

ast

Program

name

string

Returns

Block | undefined


format()

abstract format(ast, options?): FormatterOutput

Defined in: formatters/src/base-formatter.ts:14

Transform AST to tool-specific format

Parameters

ast

Program

options?

FormatOptions

Returns

FormatterOutput

Implementation of

Formatter.format


formatArray()

protected formatArray(arr): string

Defined in: formatters/src/base-formatter.ts:84

Format an array as comma-separated string.

Parameters

arr

unknown[]

Returns

string


getArrayElements()

protected getArrayElements(content): Value[]

Defined in: formatters/src/base-formatter.ts:108

Extract array elements from block content.

Parameters

content

BlockContent

Returns

Value[]


getMetaField()

protected getMetaField(ast, key): string | undefined

Defined in: formatters/src/base-formatter.ts:98

Get meta field value as string.

Parameters

ast

Program

key

string

Returns

string | undefined


getOutputPath()

protected getOutputPath(options?): string

Defined in: formatters/src/base-formatter.ts:28

Get the output path, respecting options override.

Parameters

options?

FormatOptions

Returns

string


getProp()

protected getProp(content, key): Value | undefined

Defined in: formatters/src/base-formatter.ts:56

Get a specific property from block content.

Parameters

content

BlockContent

key

string

Returns

Value | undefined


getProps()

protected getProps(content): Record\<string, Value>

Defined in: formatters/src/base-formatter.ts:70

Get all properties from block content.

Parameters

content

BlockContent

Returns

Record\<string, Value>


truncate()

protected truncate(str, max): string

Defined in: formatters/src/base-formatter.ts:91

Truncate string to max length with ellipsis.

Parameters

str

string

max

number

Returns

string


valueToString()

protected valueToString(value): string

Defined in: formatters/src/base-formatter.ts:118

Convert value to string representation.

Parameters

value

Value

Returns

string