# fast-text-encoding

> Fast polyfill for TextEncoder and TextDecoder, only supports utf-8

Latest version **1.0.6** (published 2022-08-30) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install fast-text-encoding
pnpm add fast-text-encoding
yarn add fast-text-encoding
bun add fast-text-encoding
```

## Health

**Score 18/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2022-08-30 |
| First published | 2017-09-01 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | separate (@types/fast-text-encoding) |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 31.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 114 |
| Author | Sam Thorogood |
| Maintainers | samthor |

## Links

- npm: https://www.npmjs.com/package/fast-text-encoding
- Repository: https://github.com/samthor/fast-text-encoding
- Homepage: https://github.com/samthor/fast-text-encoding#readme
- Issues: https://github.com/samthor/fast-text-encoding/issues
- npm.io page: https://npm.io/package/fast-text-encoding

## Recent versions

- 1.0.6 (latest) — 2022-08-30
- 0.0.0-empty (empty) — 2022-08-30
- 1.0.4 — 2022-06-20
- 1.0.3 — 2020-06-16
- 1.0.2 — 2020-04-22
- 1.0.1 — 2020-03-06
- 1.0.0 — 2017-09-01

## README

[![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 "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 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.

## Not Including Polyfill

If your project doesn't need the polyfill, but is included as a transitive dependency, we publish [an empty version](https://www.npmjs.com/package/fast-text-encoding/v/0.0.0-empty) that you could pin NPM or similar's version algorithm to.
Use "fast-text-encoding@empty".

---
_Source: https://npm.io/package/fast-text-encoding · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
