-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support characters >1 byte #5
Conversation
Create a new test for issue #1 , testing if strToBytes() supports characters longer than 1 byte.
Great, thanks Ross! Will you continue working on the fix in this branch/PR? |
Per feedback in #5 (review). Also add spacing for AAA format.
- Properly encode >1 byte characters, closes #1 (adds text-encoding as a dependency) - Add test for bytesToStr() - Fix test for strToBytes(); add 3 byte character test
Latest commit adds a new test for bytesToStr(), tests for 3 byte characters, and adds a fix for #1 |
That's a nice polyfill! It makes me a bit uneasy that it is marked as deprecated, but if it works well I think it's fine. Did you have a look or try other ones as well? |
Move @types/text-encoding dependency to dev-dependencies
@microbit-carlos I looked at using https://github.com/mathiasbynens/utf8.js but the way it worked with strings was a little confusing. |
Yeah, I agree, the |
I've had a look at using https://github.com/solderjs/TextEncoderLite but it looks like it isn't being actively maintained, and didn't seem to work properly (it was also last published 1 year ago whereas the one used here was 5 months ago). TextEncoding has 1.2 million weekly downloads, so it seems pretty popular. I also looked at fast-text-encoding which had similar issues and was lasted updated September 2017. |
@microbit-rosslowe Could we record here the licenses for the new dependencies (the polyfill and the types). |
New dependency: https://www.npmjs.com/package/text-encoding We can choose from unlicensed or Apache: https://github.com/inexorabletash/text-encoding/blob/master/LICENSE.md |
Great, and the It all looks good, if you are happy with the PR you can change the draft state and I can merge. |
cc9a006
to
f1cd7a0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Ross!
@microbit-rosslowe This dependency increased the built file from 80Kbs to 700Kbs. Most of it comes from this file and looks like rollup tree-shaking cannot really remove any of it (since it only uses a small part of the object during runtime, but rollup has no way of knowing that). Could we find a lighter polyfill? Ideally that only does UTF-8? Or that can easily be trimmed by rollup. |
We can use text-encoding-lite, which reduces build size to around 88Kbs. Version 1.0.2 hasn't been published to npm but works nicely. See #6 |
Create a new test for issue #1 , testing if strToBytes() supports characters longer than 1 byte.