CKTIS / JavaScript
Intl.Segmenter — locale-sensitive text segmentation
Intl.Segmenter finds grapheme, word, or sentence boundaries using locale-sensitive rules. Its segment() method returns iterable segment descriptions, and isWordLike lets you select segments classified as word-like.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
new Intl.Segmenter(locales, { granularity: "word" }).segment(text)Intl.Segmenter is a JavaScript internationalization API specified in ECMA-402, already present in the 2022 edition, not a DOM API. Its constructor requires new. The granularity option accepts "grapheme" (the default), "word", or "sentence", selecting graphemes, words, or sentences. A grapheme can contain multiple code points, so it is not the same as one UTF-16 code unit.
Intl.Segmenter.prototype.segment(text) returns an iterable Segments object, not an array. Each description contains segment — the text fragment, index — its starting UTF-16 code-unit index, and input — the complete input text. Use Array.from() when you need an array.
Only with granularity: "word" does a description have the Boolean property isWordLike. It is not a segmenter method. Spaces and punctuation also appear in the results; filtering with part.isWordLike generally removes them. Classification and boundaries depend on the implementation and language data, so do not treat them as a universal grammatical parser.
The example selects words and prints their indexes. Fixing the locale to "en" reduces dependence on the default language but does not guarantee identical segmentation of arbitrary text across engines. Feature-detect in the target browser: availability in Node 24 does not prove browser support. The supplied standards sources do not establish browser-version support.
Examples
if (typeof Intl === "undefined" || typeof Intl.Segmenter !== "function") {
throw new Error("Intl.Segmenter is unavailable");
}
const text = "Hello, world!";
const segmenter = new Intl.Segmenter("en", { granularity: "word" });
const words = Array.from(segmenter.segment(text))
.filter(part => part.isWordLike)
.map(part => `${part.segment}@${part.index}`);
console.log(words.join(" | "));Result
Hello@0 | world@7
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.