cometkim / unicode-segmenter

A lightweight and fast, pure JavaScript library for Unicode segmentation
MIT License
37 stars 0 forks source link

Porting the `DoubleEndedIterator` of segmenters #26

Open cometkim opened 2 months ago

cometkim commented 2 months ago

The original Rust library implements the DoubleEndedIterator trait, which, unlike JavaScript's standard iterator, allows for reverse traversal (next_back())

The original goal was to be a lightweight alternative to Intl.Segmenter, so I intentionally removed it. But as I can see some issues in the ecosystem like https://github.com/flmnt/graphemer/issues/10, it is one of the most common requirements in scenarios such as implementing an editor. Because, it would be crazy to re-traverse the entire text forward to find just the previous cursor. To avoid that, the user would have to implement their own cursor history, which is inefficient.

However, that significantly inflates the bundle size, which the generator cannot represent.

I will improved the class version implementation and expose it as a separate bundle entry (e.g unicode-segmenter/advanced/double-ended/grapheme)