```ts
function runLengthEncode(input: string): string {
  if (typeof input !== 'string') {
    throw new Error('RunLengthEncoder expected a string');
  }

  let result = '';
  let currentCharcount = 1;
  for (let i = 0; i < input.length; i++) {
    if (i === input.length - 1 || input[i + 1] !== input[i]) {
      result += input[i] + (currentCharcount > 9 ? currentCharcount.toString().charAt(0) : '');
      currentCharcount = 1;
    } else {
      currentCharcount++;
    }
  }

  return result;
}
```