camwiegert / typical

Animated typing in ~400 bytes 🐑 of JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Some Unicode characters aren't iterated correctly

cbbfcd opened this issue Β· comments

thx! i like this repo, but unicode is a trouble, such as:

type(target, 'café', 1000, 'cafe', 1000, loop);

type(target, 'πŸ‘¨β€πŸ‘©β€πŸ‘¦', 1000, 'πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦', 1000, loop);

I know that some Unicode surrogate pairs aren't handled by String.prototype[Symbol.iterator], which is how this library iterates over strings.

Many emoji and other Unicode characters are handled correctly, but some surrogate pairs and diacritics cause an issue. I'd like to handle as many cases as possible without greatly increasing the complexity of the library or introducing a dependency.

One thing I haven't done yet is use String.prototype.normalize on string arguments. I'm going to use this issue to discuss options. Thank you!

An example of using the String normalize method:

[...'café'].length === 5
[...'café'.normalize()].length === 4

@camwiegert thx your replay.
i totally agree with you and String.prototype.normalize is a good idea.