Skip to main content

Type definition

type FixConfig = {
  speakerLabels?: string[];
  leadingPunctuation?: string[];
};

Properties

speakerLabels
string[]
Optional array of speaker labels to recognize when fixing collapsed speaker lines.If omitted, the fixer will attempt to infer labels from the text automatically.Examples:
['Questioner', 'The Shaykh', 'Mu\'adhdhin']
['Student', 'Teacher']
['Q', 'A']
leadingPunctuation
string[]
Optional array of punctuation tokens that may appear before a collapsed speaker label.Used to detect patterns like "... The Shaykh:" where punctuation precedes the label.Default: ['.', '!', '?', '،', '؛']Examples:
['.', '!', '?']  // English punctuation only
['،', '؛', '.']  // Arabic punctuation

Usage

With explicit speaker labels

import { fixCollapsedSpeakerLines } from 'wobble-bibble';

const text = `
Questioner: First question here? The Shaykh: The answer is...
`;

const result = fixCollapsedSpeakerLines(text, {
  speakerLabels: ['Questioner', 'The Shaykh']
});

console.log(result.text);
// Output:
// Questioner: First question here?
// The Shaykh: The answer is...

With automatic label inference

import { fixCollapsedSpeakerLines } from 'wobble-bibble';

const text = `
Student: What is the ruling? Teacher: The ruling is...
`;

// No speakerLabels provided - will infer from text
const result = fixCollapsedSpeakerLines(text);

console.log(result.applied);
// ['fixCollapsedSpeakerLines'] if labels were detected and fixed

Custom punctuation handling

import { fixCollapsedSpeakerLines } from 'wobble-bibble';

const arabicText = `
السائل: ما الحكم؟ الشيخ: الحكم هو...
`;

const result = fixCollapsedSpeakerLines(arabicText, {
  speakerLabels: ['السائل', 'الشيخ'],
  leadingPunctuation: ['؟', '،', '؛', '.']  // Arabic + English
});

Complete configuration

import { fixCollapsedSpeakerLines, type FixConfig } from 'wobble-bibble';

const config: FixConfig = {
  speakerLabels: [
    'Questioner',
    'The Shaykh',
    'Mu\'adhdhin',
    'Imam'
  ],
  leadingPunctuation: [
    '.',   // Period
    '!',   // Exclamation
    '?',   // Question
    '،',   // Arabic comma
    '؛',   // Arabic semicolon
    '؟'    // Arabic question mark
  ]
};

const result = fixCollapsedSpeakerLines(text, config);

Label inference

When speakerLabels is omitted, the fixer uses a pattern to detect labels:
// Pattern from constants.ts
const SPEAKER_LABEL_GUESS_PATTERN = /^([^:\n]{1,28}):/gm;
This finds:
  • Lines starting with text followed by :
  • Label is 1-28 characters
  • Maximum 2 words
Examples that will be detected:
Questioner:      ✓ (detected)
The Shaykh:      ✓ (detected)
Mu'adhdhin:      ✓ (detected)
Q:               ✓ (detected)

This is too long to be a label:  ✗ (ignored, >28 chars)

Punctuation preservation

The fixer preserves trailing punctuation before inserting line breaks:

Before fix

Text continues here. The Shaykh: Answer here.

After fix (punctuation preserved)

Text continues here.
The Shaykh: Answer here.
The period stays with the preceding text, not moved to a new line.

Default punctuation

If leadingPunctuation is omitted, the default includes:
const DEFAULT_LEADING_PUNCTUATION = [
  '.',   // Period
  '!',   // Exclamation
  '?',   // Question mark
  '،',   // Arabic comma (U+060C)
  '؛'    // Arabic semicolon (U+061B)
];

Common patterns

Fatawa Q&A format

const fatawaConfig: FixConfig = {
  speakerLabels: ['Questioner', 'The Shaykh'],
  leadingPunctuation: ['.', '?', '،', '؛', '؟']
};

Academic dialogue

const academicConfig: FixConfig = {
  speakerLabels: ['Student', 'Professor', 'Researcher'],
  leadingPunctuation: ['.', ',', ';', ':']
};

Minimal configuration

const minimalConfig: FixConfig = {
  // Auto-detect labels, use default punctuation
};

// Equivalent to:
const result = fixCollapsedSpeakerLines(text);

Build docs developers (and LLMs) love