Skip to content

Instantly share code, notes, and snippets.

@mallendeo
Last active February 27, 2023 22:29
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mallendeo/44d5127b40ccb659b609 to your computer and use it in GitHub Desktop.
Save mallendeo/44d5127b40ccb659b609 to your computer and use it in GitHub Desktop.
Convert iso-8859-1 to utf-8 in nodejs
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