Documentation
    Preparing search index...

    Class MUtf8Encoder

    The encoder for Modified UTF-8.

    This class provides encoding functionality to convert JavaScript strings into Modified UTF-8 byte sequences. The API is designed to be compatible with the WHATWG TextEncoder interface while handling the specific requirements of Modified UTF-8.

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

    Constructors

    Accessors

    Methods

    Constructors

    Accessors

    • get encoding(): string

      The encoding name for this encoder.

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

      Returns string

      Always "mutf-8"

    Methods

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

      This method converts the input string into a Modified UTF-8 byte array.

      Parameters

      • input: string = ""

        The string to encode

      Returns Uint8Array

      A new Uint8Array containing the Modified UTF-8 encoded bytes

    • Encodes a string into Modified UTF-8 bytes within an existing buffer.

      This method provides a memory-efficient way to encode strings by writing directly into a pre-allocated buffer instead of creating a new array.

      The encoding process stops when either:

      • The entire source string has been processed
      • The destination buffer is full and cannot accommodate the next character

      Parameters

      • source: string

        The string to encode into Modified UTF-8 bytes

      • destination: Uint8Array

        The Uint8Array buffer to write the encoded bytes into

      Returns TextEncoderEncodeIntoResult

      An object indicating how many characters were read and bytes written