Spaces:
Running
Running
Download src/utils/countWords.ts from thuongvv/TranslateGemma-WebGPU: direct link, hf CLI and curl.
- Browser
- Download file 283 Bytes
-
https://huggingface.co/spaces/thuongvv/TranslateGemma-WebGPU/resolve/da5e3bbb013c210943c79e139e16ff5f0d60cd5e/src/utils/countWords.ts
- Command line
-
hf download hf://spaces/thuongvv/TranslateGemma-WebGPU@da5e3bbb013c210943c79e139e16ff5f0d60cd5e/src/utils/countWords.ts
-
curl -L -o countWords.ts https://huggingface.co/spaces/thuongvv/TranslateGemma-WebGPU/resolve/da5e3bbb013c210943c79e139e16ff5f0d60cd5e/src/utils/countWords.ts
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; | |
| } | |