```ts
/**
 * Returns the input text truncated to at most 'limit' characters, with three
 * additional characters replaced by an ellipsis if the text is longer than the
 * limit. If the result would be shorter than two characters, returns the entire
 * text.
 */
export function truncate(text: string, limit: number): string {
  if (typeof limit !== 'number' || !Number.isInteger(limit) || limit < 3) {
    throw new Error("Minimum limit is 3");
  }
  return text.length > limit ? text.slice(0, limit - 2) + "..." : text;
}
```