open-index/open-npm huggingface dataset:
npm package: @nativewrappers/fast-text-encoding
Description: Build package for fast-text-encoding, should not be published
Author: Sam Thorogood
Latest version: 1.0.7
Deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.


The only difference between this and the original fast-text-encoding is that
this will always bind onto both `window` and `globalThis`.

[![Test](https://github.com/samthor/fast-text-encoding/actions/workflows/node.js.yml/badge.svg)](https://github.com/samthor/fast-text-encoding/actions/workflows/node.js.yml)

This is a fast polyfill for [`TextEncoder`][1] and [`TextDecoder`][2], 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](https://github.com/samthor/fast-text-encoding/tree/master/bench).

^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.

[1]: https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder
[2]: https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder

# Usage

Install as "@nativewrappers/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.
It will create `TextEncoder` and `TextDecoder` if the symbols are missing on `window` or `global.`

```html
<script type="module">
  import '@nativewrappers/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.