Skip to content

A small javascript library for encoding to windows-1252 (in the browser).

Notifications You must be signed in to change notification settings

kpym/windows1252-light

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Very small (1.29 KB) javascript library to encode string to Windows-1252.

Usage

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 '

Example

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.