Because of the way Javascript deals with unicode characters, astral code points like some Chinese characters or emojis are marked as surrogate pairs, and are therefore counted as 2 separate characters:
> '👾'.length
2
This means that when using these characters, the limits in Length might not always be accurate.
This PR fixes that by identifying those astral symbols and replacing them with a simple unicode character (_). This solution was based on https://mathiasbynens.be/notes/javascript-unicode. Other solutions would require adding external dependencies.
Because of the way Javascript deals with unicode characters, astral code points like some Chinese characters or emojis are marked as surrogate pairs, and are therefore counted as 2 separate characters:
This means that when using these characters, the limits in
Length
might not always be accurate.This PR fixes that by identifying those astral symbols and replacing them with a simple unicode character (
_
). This solution was based on https://mathiasbynens.be/notes/javascript-unicode. Other solutions would require adding external dependencies.