1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-12-23 06:43:17 +00:00
musix-oss/node_modules/fast-text-encoding
2020-03-03 22:30:50 +02:00
..
.npmignore Modules 2020-03-03 22:30:50 +02:00
LICENSE Modules 2020-03-03 22:30:50 +02:00
package.json Modules 2020-03-03 22:30:50 +02:00
polyfill.js Modules 2020-03-03 22:30:50 +02:00
README.md Modules 2020-03-03 22:30:50 +02:00
test.html Modules 2020-03-03 22:30:50 +02:00
text.js Modules 2020-03-03 22:30:50 +02:00
text.min.js Modules 2020-03-03 22:30:50 +02:00

This is a fast polyfill for TextEncoder and TextDecoder, which let you encode and decode JavaScript strings into UTF-8 bytes.

It is fast partially as it does not support any encodings aside UTF-8 (and note that natively, only TextDecoder supports alternative encodings anyway).

Usage

Include the minified inside a script tag or as an ES6 Module for its side-effects. It will create TextEncoder and TextDecoder if the symbols are missing on window.

<script src="node_modules/fast-text-encoding/text.min.js"></script>
<script type="module">
  import './node_modules/fast-text-encoding/text.min.js';
  // confidently do something with TextEncoder \o/
</script>

Note: Always include text.min.js, as it's compiled to ES5 for older environments.

Node

Install via NPM or Yarn (name "fast-text-encoding"), and then import purely for side effects:

// don't need to save this anywhere, just require before use
require('fast-text-encoding');

const buffer = new TextEncoder().encode('Turn me into UTF-8!');
// buffer is now a Uint8Array of [84, 117, 114, 110, ...]

Supports

Built for IE11, Edge and Node environments. Not required for Chrome, Firefox etc, which have native implementations.

Release

Compile code with Closure Compiler.

// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @output_file_name text.min.js
// ==/ClosureCompiler==

// code here