DEV Community

Discussion on: Which functions/methods do you...

Collapse
 
brunnerlivio profile image
Livio Brunner • Edited

The base64 functions from @lionel-rowe are compatible with (most) browser. The fs module is only available in Node.js :)

Thread Thread
 
joelbonetr profile image
JoelBonetR 🥇 • Edited

Of course but what I want to check is the details on what's happening on this TextDecoder(), it's decode method and also the reason for it to use an array of 8-bit unsigned integers 😂

Thread Thread
 
lionelrowe profile image
lionel-rowe

TextEncoder and TextDecoder convert strings to and from their equivalent UTF-8 bytes. So for example, new TextEncoder().encode('foo 福 🧧') gives Uint8Array [102, 111, 111, 32, 231, 166, 143, 32, 240, 159, 167, 167], where bytes 0..2 represent the 3 ASCII characters "foo", 4..6 represent the single 3-byte character "福", and 8..11 represent the single 4-byte character "🧧" (3 and 7 are spaces).

Thread Thread
 
joelbonetr profile image
JoelBonetR 🥇

Thanks you for the explanation! 😁