Last active
February 27, 2023 22:29
-
-
Save mallendeo/44d5127b40ccb659b609 to your computer and use it in GitHub Desktop.
Convert iso-8859-1 to utf-8 in nodejs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import iconv from 'iconv' | |
export const convertToUTF8 = <T extends any>(body: T, fromEncoding = 'iso-8859-1'): T => { | |
const ic = new iconv.Iconv(fromEncoding, 'utf-8') | |
const buf = ic.convert(JSON.stringify(body)) | |
return JSON.parse(buf.toString('utf-8')) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment