Skip to content

registerFormatter()

PromptScript API


registerFormatter(name, ctorOrFactory): void

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

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

FormatterClass | FormatterFactory

Formatter class (preferred) or factory function

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');