```typescript
/**
 * Truncates the given text to the specified limit, replacing any remaining characters with three dots.
 */
export function truncate(text: string, limit: number): string {
  if (typeof limit !== 'number' || limit < 3) {
    throw new Error('limit must be an integer greater than or equal to 3');
  }
  return text.length <= limit
    ? text
    : text.slice(0, limit - 3) + '...';
}
```