```ts
/** The text, cut to limit characters with an ellipsis when it is longer. */
export function truncate(text: string, limit: number): string {
  if (limit <= 0 || !Number.isInteger(limit)) {
    throw new Error("Invalid limit - must be a positive integer of at least 3.");
  }
  const truncatedText = text.length > limit ? text.slice(0, limit - 4) + "..." : text;
  return truncatedText;
}
```