Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Polyfill for TextDecoder

I'm using fetch and have included the whatwg-fetch polyfill in my application.

I also employ TextDecoder as described in Jake Archibald's blog That's so fetch! to decode the response, but I'm not sure what polyfill to use.

(Currently Safari complains about ReferenceError: Can't find variable: TextDecoder)

I'm guessing there's a polyfill for TextDecoder, but I'm not finding it...

like image 583
sfletche Avatar asked Nov 17 '16 18:11

sfletche


2 Answers

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

like image 154
Rosberg Linhares Avatar answered Sep 19 '22 12:09

Rosberg Linhares


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();
like image 30
sfletche Avatar answered Sep 23 '22 12:09

sfletche