```ts
/**
 * Encodes every maximal run of one repeated character in the input string,
 * replacing it with that character followed by the run length.
 *
 * @param input - The input 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');
  }

  let result = '';
  let currentChar = input[0];
  let count = 1;

  for (let i = 1; i < input.length; i++) {
    const char = input[i];

    if (char === currentChar) {
      count++;
    } else {
      result += `${currentChar}${count > 1 ? count : ''}`;
      currentChar = char;
      count = 1;
    }
  }

  // Append the last run
  result += `${currentChar}${count > 1 ? count : ''}`;

  return result;
}
```