```ts
function truncate(text: string, limit: number): string {
  if (!Number.isInteger(limit) || limit < 3) {
    throw new Error("truncate: limit must be a positive integer of at least 3");
  }

  if (text.length <= limit) {
    return text;
  }

  // Ensure the truncated part has enough characters for the ellipsis
  const truncatedPart = text.slice(0, limit - 4);

  return `${truncatedPart}...`;
}
```