Fast polyfill for TextEncoder and TextDecoder, only supports UTF-8
JavaScript
114
67 commits
updated Feb 10, 2025
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).
See some benchmarks.
^If this polyfill used on Node v5.1 through v11 (when Text... was introduced), then this simply wraps Buffer, which supports many encodings and is native code.
Install as "fast-text-encoding" via your favourite package manager.
You only need this polyfill if you're supporting older browsers like IE, legacy Edge, ancient Chrome and Firefox, or Node before v11.
Include the minified code 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 or global.
<script src="node_modules/fast-text-encoding/text.min.js"></script>
<script type="module">
import './node_modules/fast-text-encoding/text.min.js';
import 'fast-text-encoding'; // or perhaps this
// confidently do something with TextEncoder or TextDecoder \o/
</script>
⚠️ You'll probably want to depend on "text.min.js", as it's compiled to ES5 for older environments.
If your project doesn't need the polyfill, but is included as a transitive dependency, we publish an empty version that you could pin NPM or similar's version algorithm to. Use "fast-text-encoding@empty".
Overall
Maintained
Code review
Latest release
Releases this year
4,260 followers · starred Dec 2025
1,233 followers · starred Sep 2024
228 followers · starred Mar 2020
25 followers · starred Dec 2020
Fast polyfill for TextEncoder and TextDecoder, only supports UTF-8
JavaScript
114
67 commits
updated Feb 10, 2025
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).
See some benchmarks.
^If this polyfill used on Node v5.1 through v11 (when Text... was introduced), then this simply wraps Buffer, which supports many encodings and is native code.
Install as "fast-text-encoding" via your favourite package manager.
You only need this polyfill if you're supporting older browsers like IE, legacy Edge, ancient Chrome and Firefox, or Node before v11.
Include the minified code 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 or global.
<script src="node_modules/fast-text-encoding/text.min.js"></script>
<script type="module">
import './node_modules/fast-text-encoding/text.min.js';
import 'fast-text-encoding'; // or perhaps this
// confidently do something with TextEncoder or TextDecoder \o/
</script>
⚠️ You'll probably want to depend on "text.min.js", as it's compiled to ES5 for older environments.
If your project doesn't need the polyfill, but is included as a transitive dependency, we publish an empty version that you could pin NPM or similar's version algorithm to. Use "fast-text-encoding@empty".
Overall
Maintained
Code review
Latest release
Releases this year
4,260 followers · starred Dec 2025
1,233 followers · starred Sep 2024
228 followers · starred Mar 2020
25 followers · starred Dec 2020