### Segment iteration Source: https://github.com/tc39/proposal-intl-segmenter/blob/master/README.md Demonstrates how to create a locale-specific word segmenter and use it to iterate over segments of a string, logging each segment's details. ```javascript let segmenter = new Intl.Segmenter("fr", {granularity: "word"}); let input = "Moi? N'est-ce pas."; let segments = segmenter.segment(input); for (let {segment, index, isWordLike} of segments) { console.log("segment at code units [%d, %d): «%s»%s", index, index + segment.length, segment, isWordLike ? " (word-like)" : "" ); } // console.log output: // segment at code units [0, 3): «Moi» (word-like) // segment at code units [3, 4): «?» // segment at code units [4, 6): « » // segment at code units [6, 11): «N'est» (word-like) // segment at code units [11, 12): «-» // segment at code units [12, 14): «ce» (word-like) // segment at code units [14, 15): « » // segment at code units [15, 18): «pas» (word-like) // segment at code units [18, 19): «.» ``` -------------------------------- ### Direct random access to segments Source: https://github.com/tc39/proposal-intl-segmenter/blob/master/README.md Illustrates direct random access to segments within a string using the `containing` method of the %Segments% instance. ```javascript // ┃0 1 2 3 4 5┃6┃7┃8┃9 // ┃A l l o n s┃-┃y┃!┃ let input = "Allons-y!"; let segmenter = new Intl.Segmenter("fr", {granularity: "word"}); let segments = segmenter.segment(input); let current = undefined; current = segments.containing(0) // → { index: 0, segment: "Allons", isWordLike: true } current = segments.containing(5) // → { index: 0, segment: "Allons", isWordLike: true } current = segments.containing(6) // → { index: 6, segment: "-", isWordLike: false } current = segments.containing(current.index + current.segment.length) // → { index: 7, segment: "y", isWordLike: true } current = segments.containing(current.index + current.segment.length) // → { index: 8, segment: "!", isWordLike: false } current = segments.containing(current.index + current.segment.length) // → undefined ``` -------------------------------- ### Intl.Segmenter Constructor Signature Source: https://github.com/tc39/proposal-intl-segmenter/blob/master/spec.html The signature for the Intl.Segmenter constructor, showing optional locales and options arguments. ```javascript Intl.Segmenter ( [ _locales_ [ , _options_ ] ] ) ``` -------------------------------- ### Intl.Segmenter.prototype.segment Method Source: https://github.com/tc39/proposal-intl-segmenter/blob/master/spec.html The signature for the segment method on the Intl.Segmenter prototype. ```javascript Intl.Segmenter.prototype.segment ( _string_ ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.