> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/js/lib/grapheme-splitter.md).

# grapheme-splitter

[libraries](/web/js/lib.md) ⟩ grapheme-splitter

{% hint style="success" %}

* install

```shell
npm install grapheme-splitter
```

* import

```javascript
import GraphemeSplitter from 'grapheme-splitter';       // ES module
const GraphemeSplitter = require('grapheme-splitter');  // CommonJS
```

* test

```javascript
const splitter = new GraphemeSplitter();
const string = "🌷🎁💩😜👍🏳️‍🌈";

// string -> iterable iterator of grapheme clusters
const graphemesIt = splitter.iterateGraphemes(string);
[...graphemesIt],    // [ '🌷', '🎁', '💩', '😜', '👍', '🏳️‍🌈' ]
[...graphemesIt],    // []     (exhausted iterator)

splitter.splitGraphemes(string),        // array of grapheme clusters
// [ '🌷', '🎁', '💩', '😜', '👍', '🏳️‍🌈' ]

splitter.countGraphemes(string),        // 6    (count grapheme clusters)
```

{% endhint %}

{% tabs %}
{% tab title="👥 相關" %}

* [grapheme cluster](/web/js/val/prim/str/unicode/grapheme-cluster.md)
  {% endtab %}

{% tab title="📗 參考" %}

* [ ] GitHub ⟩ [grapheme-splitter](https://github.com/orling/grapheme-splitter)
  {% endtab %}
  {% endtabs %}
