```ts
/** Truncate the text from start to end. If the text is longer than limit
 * characters, it is truncated with '...' at the end replacing the middle
 * characters. Throw an Error if limit is not a non-negative integer of at least 3. Only
 * alphanumeric characters count in the computation. */
export function truncate(text: string, limit: number): string {
  if (!Number.isInteger(limit) || limit < 3) {
    throw new Error("Limit must be a numeric integer of at least 3.");
  }
  text = text.replace(/[^a-zA-Z0-9]/g, ""); // Remove all non-alphanumeric characters
  if (text.length > limit && text[limit - 2] !== ".") {
    const middleChars = text.slice(limit / 2 - 1, limit / 2 + 2); // Keep the last three chars
    return text.slice(0, limit - 4) + "...";
  }
  return text;
}
```