Package Exports
- text-encoding-shim
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (text-encoding-shim) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Text Encoding Shim
When I was looking for a simple lightweight polyfill that works great with TypeScript I was not happe with the results. While a couple polyfills exist, they either broke in my special setup and lead to unexpected results or they implemented a bunch of features that I did not even want to have. So I wrote my own shim.
Installation
npm
Get it via npm by adding text-encoding-shim to your package.json or run:
npm install --save text-encoding-shimBower
Get it via Bower by adding it to your bower.json or run:
bower install --save text-encoding-shimHTML script tag
Altenatively you can simply download this project folder and add it to your html script tags like so:
<script type="text/javascript" src="text-encoding-shim/index.js"></script>TypeScript definitions
If you are using TypeScript you can use the definition file in this folder or install it via typings:
typings install --save --global npm:text-encoding-shimImporting 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.
CommonJS
var TextEncodingShim = require('text-encoding-shim');
var TextEncoder = TextEncodingShim.TextEncoder;
var TextDecoder = TextEncodingShim.TextDecoder;Asynchronous Module Definition (AMD)
define([TextEncodingShim], function() {
//...
});ES2015 or TypeScript
import { TextEncoder, TextDecoder } from 'text-encoding-shim';Basic Usage
var uint8array = new TextEncoder('utf-8').encode(string);
var string = new TextDecoder('utf-8').decode(uint8array);Limitations
If a native implementation is available it will always be handled preferred to this polyfill. Just like native implementations of Mozilla Firefox or Google Chrome, this library only supports UTF-8 encoding. This makes it so fast. If you need additional encodings, check out this more advanced polyfill.