Skip to main content
Apply all requested fixers by type, processing them in order and accumulating fixes. Each fixer receives the output of the previous fixer, allowing multiple corrections to be applied in a single pass.

Function Signature

fixAll(text: string, options: FixAllOptions): FixResult

Parameters

text
string
required
The translation text to fix. Typically the raw LLM output containing formatting errors.
options
FixAllOptions
required
Configuration object specifying which fixers to apply.

Return Value

FixResult
object
Object containing the fixed text and metadata about what was applied.

Example

import { fixAll } from 'wobble-bibble';

const malformedText = `P1 - Questioner: What is the ruling? The Shaykh: The ruling is permissible.
P2 - The text continues here. Questioner: Another question?`;

const result = fixAll(malformedText, {
  types: ['collapsed_speakers'],
  config: {
    speakerLabels: ['Questioner', 'The Shaykh']
  }
});

console.log(result.text);
// P1 - Questioner: What is the ruling?
// The Shaykh: The ruling is permissible.
// P2 - The text continues here.
// Questioner: Another question?

console.log(result.applied);
// ['collapsed_speakers']

console.log(result.counts);
// { fixCollapsedSpeakerLines: 2 }

Behavior

Sequential Processing

Fixers are applied in the order specified in options.types. Each fixer receives the output of the previous fixer:
const result = fixAll(text, {
  types: ['collapsed_speakers', 'other_future_fixer']
});
// 1. collapsed_speakers fixer runs on original text
// 2. other_future_fixer runs on output from step 1
// 3. Final result contains accumulated fixes

Skipped Fixers

If a requested error type has no corresponding fixer, it will be added to the skipped array:
const result = fixAll(text, {
  types: ['collapsed_speakers', 'nonexistent_type']
});

console.log(result.skipped);
// ['nonexistent_type']

Count Accumulation

The counts object tracks how many fixes each fixer applied, using the function name as the key:
const result = fixAll(text, { types: ['collapsed_speakers'] });

// If fixCollapsedSpeakerLines found and fixed 5 instances:
console.log(result.counts);
// { fixCollapsedSpeakerLines: 5 }

Build docs developers (and LLMs) love