mirror of
https://github.com/keven1024/015.git
synced 2026-05-27 07:29:37 +00:00
10 lines
357 B
TypeScript
10 lines
357 B
TypeScript
function countWords(text: string): number {
|
|
const trimmed = text?.trim()
|
|
if (!trimmed) return 0
|
|
const cjk = trimmed.match(/[\u4e00-\u9fff\u3040-\u30ff\uac00-\ud7af]/g)?.length ?? 0
|
|
const latin = trimmed.replace(/[\u4e00-\u9fff\u3040-\u30ff\uac00-\ud7af]/g, ' ').match(/\S+/g)?.length ?? 0
|
|
return cjk + latin
|
|
}
|
|
|
|
export default countWords
|