kpym / windows1252-light

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

Home Page:https://kpym.github.io/windows1252-light/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

windows1252-light

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.

About

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

https://kpym.github.io/windows1252-light/


Languages

Language:HTML 50.7%Language:JavaScript 49.3%