Very small (1.29 KB) javascript library to encode string to Windows-1252
.
This library can be downloaded or use jsdelivr like this :
<script src="https://cdn.jsdelivr.net/gh/kpym/windows1252-light@v1.1.0/windows1252.js" defer></script>
This library contains a single function UnicodeToWindows1252
that ca be used like this
const encoded = UnicodeToWindows1252('Crème brûlée 🙂'); // default replacement character is '?'
const decoded = new TextDecoder("windows-1252").decode(encoded); // 'Crème brûlée ?'
const encoded = UnicodeToWindows1252('Crème brûlée 🙂', '*'); // set replacement character to '*'
const decoded = new TextDecoder("windows-1252").decode(encoded); // 'Crème brûlée *'
const encoded = UnicodeToWindows1252('Crème brûlée 🙂', ''); // ignore non encodable characters
const decoded = new TextDecoder("windows-1252").decode(encoded); // 'Crème brûlée '
You can see in example.html how to use this library to build a csv file for Excel under Windows.
This example is based on b4stien/js-csv-encoding.