Skip to content

PromptScript API


Function: registerFormatter()

registerFormatter(name, ctorOrFactory): void

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

Register a custom formatter.

This is a convenience wrapper around FormatterRegistry.register(). Use this to add custom formatters that can be referenced by name.

Parameters

name

string

Unique identifier for the formatter

ctorOrFactory

Formatter class (preferred) or factory function

FormatterClass | FormatterFactory

Returns

void

Throws

Error if a formatter with the same name is already registered

Example

import { registerFormatter, BaseFormatter } from '@promptscript/formatters';

class MyFormatter extends BaseFormatter {
  name = 'my-tool';
  outputPath = '.my-tool/config.md';
  description = 'My custom formatter';
  defaultConvention = 'markdown';
  static getSupportedVersions() { return { simple: { name: 'simple', description: '...', outputPath: '...' } }; }
}

registerFormatter('my-tool', MyFormatter);

// Now it can be used by name
const formatter = getFormatter('my-tool');