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

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

    for (const char of input) {
        if (char === currentChar) {
            charCount++;
        } else {
            if (currentChar) {
                result.push(currentChar);
                result.push(charCount.toString());
            }
            currentChar = char;
            charCount = 1;
        }
    }

    if (currentChar) {
        result.push(currentChar);
        result.push(charCount.toString());
    }

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