Convert Distorted Character to ISO-8859-1

I am trying to grab some text from a Portuguese site which is encoded in ISO-8859-1 according to the meta tag. I am using NodeJS and a promise-request package. For example, I'll be back

Algs

I believe that I need to convert it to ISO-8859-1 in NodeJS / Javascript. I tried decodeURIComponent, encodeURIComponent, unescape and escape. None of them worked. Some of them even made things worse for the string. Does anyone know how to solve this?

Thanks in advance.

+4
source share
1 answer

If you request data through fetch, you can try to convert the data to arrayBuffer:

let result = [];
fetch('isoEncodedApi/data.json').then(response => {
  response.arrayBuffer().then(arrayBuffer => {
    const textDecoder = new TextDecoder('iso-8859-1');
    const decodedResult = textDecoder.decode(arrayBuffer);
    result = JSON.parse(decodedResult);
  });
});

0
source

Source: https://habr.com/ru/post/1694397/


All Articles