The binary data to decode.
Optionaloptions: TextDecoderOptionsDecoding options (same as TextDecoderOptions).
If true, throw on invalid sequences. If false (default), replace with U+FFFD.
If true, keep BOM in output. If false (default), strip BOM.
Decoded string.
const decoded = decodeUtf8(new Uint8Array([228, 189, 160, 229, 165, 189]));
console.log(decoded); // '你好'
// With invalid bytes (non-fatal, default)
const withReplacement = decodeUtf8(new Uint8Array([0xff, 0xfe]));
console.log(withReplacement); // '��'
// With invalid bytes (fatal)
decodeUtf8(new Uint8Array([0xff, 0xfe]), { fatal: true }); // throws Error
// BOM handling (default: strip BOM)
const withBOM = new Uint8Array([0xef, 0xbb, 0xbf, 0x48, 0x69]); // BOM + 'Hi'
decodeUtf8(withBOM); // 'Hi'
decodeUtf8(withBOM, { ignoreBOM: true }); // '\uFEFFHi'
Decodes binary data to string (UTF-8 decoding).
Uses native
TextDecoderwhen available (faster at all input sizes). Falls back to pure JS whenTextDecoderis not available.