Skip to content

Instantly share code, notes, and snippets.

@mallendeo
mallendeo / toutf8.ts
Last active February 27, 2023 22:29
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'))
}
@TaoK
TaoK / TextFileEncodingDetector.cs
Last active October 21, 2024 16:41
Simple class to automatically detect text file encoding, with English-biased "best guess" heuristic based on byte patterns in the absence of BOM.
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
namespace KlerksSoft
{
public static class TextFileEncodingDetector
{
/*