```ts
export function runLengthEncode(input: string): string {
  /**
   * Replaces every maximal run of one repeated character with that character 
   * followed by the run length in order.
   */

  if (typeof input !== 'string') {
    throw new Error('Input must be a string.');
  }

  const result: string[] = [];
  let currentChar = '';
  let count = 0;

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

  result.push(currentChar);
  result.push(count.toString());

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