```ts
/**
 * Encodes a string by replacing every maximal run of one repeated character with that character followed by its count.
 *
 * @param input The string to be encoded.
 * @returns The encoded string.
 */
export function runLengthEncode(input: string): string {
    if (typeof input !== 'string') {
        throw new Error('Input must be a string.');
    }

    const result = [];
    let currentChar = '';
    let currentCount = 0;

    for (const char of input) {
        if (char === currentChar) {
            currentCount++;
        } else {
            if (currentChar !== '') {
                result.push(currentChar + currentCount);
            }
            currentChar = char;
            currentCount = 1;
        }
    }

    if (currentChar !== '') {
        result.push(currentChar + currentCount);
    }

    return result.join('');
}
```