Skip to content

Commit

Permalink
feat: add grapheme-splitter and grapheme alternatives (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
cometkim authored Nov 15, 2024
1 parent be8aadb commit f8e7b19
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/modules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ ESLint plugin.
- [`fs-extra`](./fs-extra.md)
- [`glob`](./glob.md)
- [`globby`](./glob.md)
- [`grapheme`](./grapheme.md)
- [`ìnvariant`](./invariant.md)
- [`is-builtin-module`](./is-builtin-module.md)
- [`jQuery`](./jquery.md)
Expand Down
40 changes: 40 additions & 0 deletions docs/modules/grapheme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Grapheme cluster splitting

[`grapheme-splitter`](https://github.com/orling/grapheme-splitter) and [`graphemer`](https://github.com/flmnt/graphemer) are no longer maintained, and can often be replaced with platform-provided APIs.

Or you can find much lighter, actively maintained alternative.

## Alternatives

### Intl API

[`Intl.Segmenter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter) is provided by following modern JavaScript runtimes

- Node.js v16 / Bun / Deno
- Chrome v87
- Safari v14.1
- Firefox v132

```js
const segmenter = new Intl.Segmenter();

const segments = [...segmenter.segment(text)];
```

### unicode-segmenter

[`unicode-segmenter`](https://github.com/cometkim/unicode-segmenter) is a lighter and faster alternative that implement Unicode text segmentation standard with zero dependencies.

```js
import { graphemeSegments } from 'unicode-segmenter/grapheme';

const segments = [...graphemeSegments(text)];
```

The API is almost same with the `Intl.Segmenter`, so you can also use it as polyfill.

```js
import { Segmenter } from 'unicode-segmenter/intl-adapter';
// or
import 'unicode-segmenter/intl-polyfill';
```
12 changes: 12 additions & 0 deletions manifests/preferred.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@
"docPath": "glob",
"category": "preferred"
},
{
"type": "documented",
"moduleName": "grapheme-splitter",
"docPath": "grapheme",
"category": "preferred"
},
{
"type": "documented",
"moduleName": "graphemer",
"docPath": "grapheme",
"category": "preferred"
},
{
"type": "documented",
"moduleName": "invariant",
Expand Down

0 comments on commit f8e7b19

Please sign in to comment.