| export function countWords(text: string): number { | |
| if (!text || text.trim().length === 0) { | |
| return 0; | |
| } | |
| // Remove extra whitespace and split by whitespace | |
| const words = text | |
| .trim() | |
| .split(/\s+/) | |
| .filter((word) => word.length > 0); | |
| return words.length; | |
| } | |