The nuances of base64 encoding strings in JavaScript
last updated: Oct 20, 2023
https://web.dev/articles/base64-encoding
Encoding unicode strings to base64 in javascript is not easy, but it is possible.
I knew that Javascript used UTF-16 internally, but today I learned about:
- String.fromCodePoint() - convert a sequence of code points into a string
- TextEncoder - allows you to convert a sequence of code points into a UTF-8 byte sequence
- TextDecoder - convert a byte sequence to a stream of code points from a variety of text encodings
- String.isWellFormed() - a new-ish function to check whether a string has any lone surrogates (is invalid UTF-16 - see wtf-8)