From 7b06502a6c010a1cb2f3dc192c535b1c24ea12b0 Mon Sep 17 00:00:00 2001 From: Sam Thorogood Date: Fri, 6 Mar 2020 16:16:20 +1100 Subject: [PATCH] notes on where this should be used --- README.md | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index c0ab35a..f8e447a 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ It is fast partially as it does not support any encodings aside UTF-8 (and note 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. + ## Browser Include the minified code inside a `script` tag or as an ES6 Module for its side effects. @@ -21,30 +23,24 @@ It will create `TextEncoder` and `TextDecoder` if the symbols are missing on `wi ``` -**Note**: You want `text.min.js`, as it's compiled to ES5 for older environments. +⚠️ You'll probably want to depend on `text.min.js`, as it's compiled to ES5 for older environments. ## Node +You only need this polyfill in Node before v11. +However, you can use `Buffer` to provide the same functionality (but not conforming to any spec) in versions even older than that. + ```js -// don't need to save anywhere, just require before use -require('fast-text-encoding'); +require('fast-text-encoding'); // just require me before use const buffer = new TextEncoder().encode('Turn me into UTF-8!'); // buffer is now a Uint8Array of [84, 117, 114, 110, ...] ``` -However, note that `Buffer.from('Turn me into UTF-8!')` is Node's native version of the text encoding functionality. -You can probably massage [`Buffer`](https://nodejs.org/api/buffer.html) into acting like `TextEncoder` and `TextDecoder`. - -# Supports - -Built for IE11, Edge and Node environments. -Not required for Chrome, Firefox etc, which have native implementations. - # Release Compile code with [Closure Compiler](https://closure-compiler.appspot.com/home).