```ts
/**
 * The text, cut to limit characters with an ellipsis when it is longer.
 * @param text - The input string to truncate.
 * @param limit - The maximum number of characters including the ellipsis.
 * @returns The truncated string or the original if within limit.
 * @throws {Error} If `limit` is less than 3.
 */
export function truncate(text: string, limit: number): string {
  if (isNaN(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) + "...";
}
```