I need to write encoder/decoder functions for UTF-8, UTF-16, and UTF-32 in JavaScript unaided by any libraries, but I can't find a good reference to use. A polyfill for TextEncoder
and TextDecoder
(which only implements UTF-8) is a that I've found, but it does not feature validation checks. iconv-lite, which is supposedly a pure JavaScript codec, is a thicket of interdependent functions and classes with no clear encoding/decoding functions. Source files in CPython, like here appear to be wrappers without traceable wrapees. I can't even find official specifications for these things.
Can I get an easily readable and understandable reference for the string-to-bytes and bytes-to-string procedures that include validation checks, when to throw errors, how to use the replacement character, and the byte-order mark?