```ts
export function runLengthEncode(input: string): string {
  if (typeof input !== 'string') throw new Error('Input must be a string.');

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

  for (let i = 1, len = input.length; i <= len; i++) {
    if (i < len && input[i] === currentChar) {
      charCount++;
    } else {
      result += `${currentChar}${charCount}`;
      if (i < len) {
        currentChar = input[i];
        charCount = 1;
      }
    }
  }

  // Remove '1' from the numbers that occur only once
  return result.replace(/([0-9])+(?=.$)/g, '$1');
}
```