@@ -46,6 +46,18 @@ And extra utilities for combined use cases.
4646
4747Utilities for text segmentation by extended grapheme cluster rules.
4848
49+ #### Example: Get grapheme segments
50+
51+ ``` js
52+ import { graphemeSegments } from ' unicode-segmenter/grapheme' ;
53+
54+ [... graphemeSegments (' a̐éö̲\r\n ' )];
55+ // 0: { segment: 'a̐', index: 0, input: 'a̐éö̲\r\n' }
56+ // 1: { segment: 'é', index: 2, input: 'a̐éö̲\r\n' }
57+ // 2: { segment: 'ö̲', index: 4, input: 'a̐éö̲\r\n' }
58+ // 3: { segment: '\r\n', index: 7, input: 'a̐éö̲\r\n' }
59+ ```
60+
4961#### Example: Count graphemes
5062
5163``` js
@@ -62,17 +74,8 @@ countGrapheme('a̐éö̲');
6274// => 3
6375```
6476
65- #### Example: Get grapheme segments
66-
67- ``` js
68- import { graphemeSegments } from ' unicode-segmenter/grapheme' ;
69-
70- [... graphemeSegments (' a̐éö̲\r\n ' )];
71- // 0: { segment: 'a̐', index: 0, input: 'a̐éö̲\r\n' }
72- // 1: { segment: 'é', index: 2, input: 'a̐éö̲\r\n' }
73- // 2: { segment: 'ö̲', index: 4, input: 'a̐éö̲\r\n' }
74- // 3: { segment: '\r\n', index: 7, input: 'a̐éö̲\r\n' }
75- ```
77+ > [ !INFO]
78+ > ` countGrapheme() ` is a small wrapper around ` graphemeSegments() ` . If you call it frequently, consider memoization or iterate once ahead.
7679
7780#### Example: Build an advanced grapheme matcher
7881
0 commit comments