fix: add support for multibyte characters#2
Conversation
if the length of a character is more than one (here tested with 2 and 7), it should be counted as that length, but definitely shouldn't cut in the middle of that character. This does not work as expected yet, so the test is skipped
|
Nice @Haroenv , feel free to also submit the solution so that we don't skip the test ;) |
|
Couldn't simply find a rule for how to get the actual characters to not split them. Thought to add this test so we know that it should work |
|
The difference now is that the character count is used, and not the string length. This means that 💩 counts as one character, while before it would count as two. |
This is not a big issue. |
|
I think this can be merged as-is, it will no longer break 💩 or 🧀 , but will still break (possibly) 🙌🏿 or 🏃🏿♀️ |
|
(by the way, ZWJ is also relevant for Arabic, and multibyte strings for some Chinese letters) |
| const chunks = []; | ||
| while (text.length > chunkSize) { | ||
| const splitAt = text.lastIndexOf(' ', chunkSize); | ||
| let characters = [...text]; |
There was a problem hiding this comment.
I just realised that it matters where this is supported: node 6+
If it would be Array.from() it would be node 4+
|
We are using conventional commit format to generate changelog. |
|
I usually squash on merge, but if you prefer to do it this way, it's also fine for me |
|
Runes is amazing, it works exactly how I want it! |
rayrutjes
left a comment
There was a problem hiding this comment.
Impressive man! Go for it 🎉
Make sure you give it a "conventional" commit name.
|
There are some more advanced bugs, but I issued them to runes itself, will see what I can do to fix it. For now it's already going well |
if the length of a character is more than one (here tested with 2 and 7), it should be counted as that length, but definitely shouldn't cut in the middle of that character.
This does not work as expected yet, so the test is skipped