# @cto.af/wtf8

> Encode and decode [WTF-8](https://simonsapin.github.io/wtf-8/) with a similar API to [TextEncoder](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder) and [TextDecoder](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder).

Latest version **0.0.5** (published 2026-03-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install @cto.af/wtf8
pnpm add @cto.af/wtf8
yarn add @cto.af/wtf8
bun add @cto.af/wtf8
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; has provenance.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2026-03-03 |
| First published | 2025-04-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=20 |
| Dependencies | 0 |
| Unpacked size | 16.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Author | Joe Hildebrand |
| Maintainers | hildjj |
| Keywords | utf8, wtf8, unicode, encode, decode, stream |

## Links

- npm: https://www.npmjs.com/package/@cto.af/wtf8
- Repository: https://github.com/cto-af/wtf8
- Homepage: https://github.com/cto-af/wtf8#readme
- Issues: https://github.com/cto-af/wtf8/issues
- npm.io page: https://npm.io/package/@cto.af/wtf8

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 0.0.5 (latest) — 2026-03-03
- 0.0.4 — 2025-08-02
- 0.0.3 — 2025-06-21
- 0.0.2 — 2025-04-29
- 0.0.1 — 2025-04-29

## README

# @cto.af/wtf8

Encode and decode [WTF-8](https://simonsapin.github.io/wtf-8/) with a similar
API to
[TextEncoder](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder)
and
[TextDecoder](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder).

The goal is to be able to parse and generate bytestreams that can store any
JavaScript string, including ones that have unpaired surrogates.

## Installation

```sh
npm install @cto.af/wtf8
```

## API

Full [API documentation](http://cto-af.github.io/wtf8/) is available.

Example:

```js
import {Wtf8Decoder, Wtf8Encoder} from '@cto.af/wtf8';

const bytes = new Wtf8Encoder().encode('\ud800');
const string = new Wtf8Decoder().decode(bytes); // '\ud800'
```

W3C streams are also provided: `Wtf8EncoderStream` and `Wtf8DecoderStream`.

## Notes

Used a few of the tricks from the paper
[Validating UTF-8 In Less Than One Instruction Per Byte](https://arxiv.org/pdf/2010.03090),
but not all of them.  Moving data in and out of WASM to be able to use SIMD
might be slightly faster, but since we're not merely validating but instead
actually decoding (and generating replacement characters when fatal is false),
staying in JS seems good enough for the moment.

---
[![Build Status](https://github.com/cto-af/wtf8/workflows/Tests/badge.svg)](https://github.com/cto-af/wtf8/actions?query=workflow%3ATests)
[![codecov](https://codecov.io/gh/cto-af/wtf8/branch/main/graph/badge.svg?token=N7B7YLIDM4)](https://codecov.io/gh/cto-af/wtf8)

---
_Source: https://npm.io/package/@cto.af/wtf8 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
