Simple lightweight polyfill for the Text Encoding API, supporting UTF-8 only
text-encoding-shim to your package.json or run:shell
npm install text-encoding-shim
`$3
Get it via Bower by adding it to your bower.json or run:
`shell
bower install --save text-encoding-shim
`$3
Altenatively you can simply download this project folder from Gitlab
and add it to your html script tags like so:
`shell
`$3
If you are using TypeScript you do not need to create a definition file. This project already includes one.
If you are still using typings you may need to run this command to copy the file:
`shell
typings install --save --global npm:text-encoding-shim
`Importing the polyfill
This polyfill utilizes the Universal Module Definition (UMD) and be used with either a module loader or standalone.
If you import it by adding a script tag you do not have to do anything else. It will automatically be bound to the global scope.
$3
`js
var TextEncodingShim = require('text-encoding-shim');
var TextEncoder = TextEncodingShim.TextEncoder;
var TextDecoder = TextEncodingShim.TextDecoder;
`$3
`js
define([TextEncodingShim], function() {
//...
});
`$3
`js
import { TextEncoder, TextDecoder } from 'text-encoding-shim';
`Basic Usage
`js
var uint8array = new TextEncoder('utf-8').encode(string);
var string = new TextDecoder('utf-8').decode(uint8array);
``