Skip to content

Implement WHATWG Encoding specification.

Evan Welsh requested to merge ewlsh/text-encoding into master

This MR implements the WHATWG Encoding specification, sans streams.

const encoder = new TextEncoder();

const arr = encoder.encode("Hi!");
const decoder = new TextDecoder();

const str = decoder.decode(new Uint8Array([1, 2, 3]));

This specification is implemented by all major web browsers, Node.js, and Deno. For our implementation we borrow Node.js' code for handling encoding labels and some of Deno's test suite.

The core functionality is located in a core module called _encodingNative. Both imports.byteArray and imports._text utilize this module to implement their respective code.

This significantly reduces the amount of code within _byteArrayNative.

And with these changes we support non-fatal encoding/decoding 🎉

Edited by Evan Welsh

Merge request reports