Polyfill for TextDecoder

I was able to solve this problem by using the text-encoding library

npm install text-encoding --save

along with

import encoding from 'text-encoding';
const decoder = new encoding.TextDecoder();

For quick client-side testing (without NPM):

<script src="https://unpkg.com/[email protected]/lib/encoding-indexes.js"></script>
<script src="https://unpkg.com/[email protected]/lib/encoding.js"></script>

..and then use TextDecoder like normal. MDN's example:

var win1251decoder = new TextDecoder('windows-1251');
var bytes = new Uint8Array([207, 240, 232, 226, 229, 242, 44, 32, 236, 232, 240, 33]);
console.log(win1251decoder.decode(bytes)); // Привет, мир!
<script src="https://unpkg.com/[email protected]/lib/encoding-indexes.js"></script>
<script src="https://unpkg.com/[email protected]/lib/encoding.js"></script>

Nowadays you can use the FastestSmallestTextEncoderDecoder polyfill (1.5 KB), as recommended by the MDN website.