TranslateGemma-WebGPU / src /utils /countWords.ts
nico-martin's picture
nico-martin HF Staff
Initial commit: TranslateGemma browser translator with Transformers.js
0842d68
raw
history blame
283 Bytes
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;
}