Similarities to TextEncoder #1027
-
Sorry, I have face an problem. When using a DataView to write a string, in node or web browser I can call TextEncoder, encode method to create an Uint8Array and write it to the DataView. However, in quickjs I don't have similarities to it, is it possible to achieve it with the existing quickjs API? (0.9.0) Edit: I think using charCodeAt and setUint8 will not guarantee for utf8 character, if not please correct me, thanks. |
Beta Was this translation helpful? Give feedback.
Answered by
bnoordhuis
Apr 14, 2025
Replies: 1 comment 1 reply
-
You can use a TextEncoder polyfill, there is no builtin API equivalent to TextEncoder. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We did add some non-ECMA-but-web-spec things in #16. I wouldn't object to TextEncoder, although:
TextEncoderStream is off the table because that means pulling in all of web streams, and
Supporting more than, let's say, UTF-8 and ISO-8559-1 in TextDecoder is unlikely because too much complexity, making it kind of anemic
Indeed it won't; utf-8 is a variable-length encoding. Doing that encoding manually is not super hard but, as Saúl mentions, polyfills exist.