Skip to content

Latest commit

 

History

History
40 lines (26 loc) · 1.17 KB

grapheme.md

File metadata and controls

40 lines (26 loc) · 1.17 KB

Grapheme cluster splitting

grapheme-splitter and 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 is provided by following modern JavaScript runtimes

  • Node.js v16 / Bun / Deno
  • Chrome v87
  • Safari v14.1
  • Firefox v132
const segmenter = new Intl.Segmenter();

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

unicode-segmenter

unicode-segmenter is a lighter and faster alternative that implement Unicode text segmentation standard with zero dependencies.

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.

import { Segmenter } from 'unicode-segmenter/intl-adapter';
// or
import 'unicode-segmenter/intl-polyfill';