Count characters, words, sentences, and reading times for any text.
The most common mistake junior developers make when building a word counter is writing code like text.split(' ').length. This assumes that all languages use spaces to separate words.
Languages like Japanese, Chinese, and Thai do not use spaces between words. If you paste a 500-word Japanese essay into a naive word counter built with split(' '), it will tell you the document contains exactly 1 word.
To count words accurately across all human languages, modern JavaScript provides the Intl.Segmenter API. This powerful built-in tool uses the browser's deeply embedded linguistic rules to properly slice text into graphemes, words, or sentences.
By calling new Intl.Segmenter('en', { granularity: 'word' }), the browser analyzes the text and correctly identifies word boundaries, completely bypassing the need for fragile Regular Expressions (Regex) and supporting languages without spaces natively.
How many characters is the family emoji (👨👩👧👦)? Visually, it is one. But under the hood in JavaScript, it is 11 characters long.
Emojis are constructed using multiple Unicode points combined with Zero-Width Joiners (ZWJ). A naive text.length check will report 11 characters for a single family emoji. A professional tool must use the Intl.Segmenter with grapheme granularity to correctly count this complex combination as a single visual character.
Why does the naive text.split(' ').length method fail completely for languages like Japanese?