Documentation
    Preparing search index...

    Class MUtf8Decoder

    The decoder for Modified UTF-8.

    This class provides decoding functionality for the Modified UTF-8 character encoding. The API is designed to be compatible with the WHATWG TextDecoder interface while handling the specific requirements of Modified UTF-8.

    const decoder = new MUtf8Decoder();
    const bytes = new Uint8Array([
    0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0xe4, 0xb8,
    0x96, 0xe7, 0x95, 0x8c, 0x21
    ]);
    const text = decoder.decode(bytes);
    console.log(text); // "Hello 世界!"
    Index

    Constructors

    Accessors

    Methods

    Constructors

    Accessors

    • get encoding(): string

      The encoding name for this decoder.

      This property is provided for compatibility with the WHATWG TextDecoder interface.

      Returns string

      Always "mutf-8"

    • get fatal(): boolean

      Indicates whether the decoder is in fatal error mode.

      When true, the decoder will throw a TypeError when encountering invalid Modified UTF-8 byte sequences. When false, invalid sequences are replaced with the Unicode replacement character (U+FFFD).

      Returns boolean

      true if error mode is fatal, otherwise false

    • get ignoreBOM(): boolean

      Indicates whether the decoder ignores Byte Order Marks.

      When true, BOM bytes (0xEF 0xBB 0xBF) at the beginning of input are silently ignored. When false, they are treated as regular characters.

      Returns boolean

      true if BOM should be ignored, otherwise false

    Methods

    • Decodes Modified UTF-8 bytes into a JavaScript string.

      This method converts Modified UTF-8 encoded bytes back to their original string representation. It supports both single-shot decoding and streaming decoding for processing large amounts of data.

      Decoding Behavior:

      • Invalid sequences: Handled according to the fatal setting
      • Streaming: Incomplete sequences at the end are preserved when stream is true

      Parameters

      Returns string

      The decoded string

      TypeError If fatal is true and the input contains invalid Modified UTF-8 sequences