TextEncoder & TextDecoder

You can convert a stream of bytes to a stream of code points, and vice-versa.


RESETRUNFULL
<!DOCTYPE html><html><body><script>
let win1251decoder = new TextDecoder('windows-1251');
let bytes = new Uint8Array([207,240,232,226,229,242,44,32,236,232,240,33]);
document.write(win1251decoder.decode(bytes));
</script></body></html>

RESETRUNFULL
<!DOCTYPE html><html><body><script>
const encoder = new TextEncoder();
const view = encoder.encode('€');
document.write(JSON.stringify(view)); // Uint8Array(3) [226, 130, 172]
</script></body></html>