```ts
/** Truncates text to a specified limit, adding '...' at the end if truncated.
 * Throws Error unless limit is an integer of at least 3.
 *
 * @param text - The text to be truncated.
 * @param limit - The maximum length of the truncated text including '...'.
 * @returns The truncated text or the original text if it's already short enough or is equal to the limit.
 */
export function truncate(text: string, limit: number): string {
  if (!Number.isInteger(limit) || limit < 3) {
    throw new Error("limit must be an integer of at least 3");
  }
  if (text.length <= limit) {
    return text;
  }
  return text.slice(0, limit - 3) + "...";
}
```