Skip to main content

Encoding

Handle character encoding, decoding, and binary data conversion.

Eg TextDecoder, TextEncoder

Functions

f
atob

Decodes a string of data which has been encoded using base-64 encoding.

    f
    btoa

    Creates a base-64 ASCII encoded string from the input string.

      Interfaces

      I
      TextDecodeOptions
      No documentation available
      I
      v
      TextDecoder

      Represents a decoder for a specific text encoding, allowing you to convert binary data into a string given the encoding.

      I
      TextDecoderCommon
      No documentation available
      I
      TextDecoderOptions
      No documentation available
      I
      v
      I
      v
      TextEncoder

      Allows you to convert a string into binary data (in the form of a Uint8Array) given the encoding.

      I
      TextEncoderCommon
      No documentation available
      I
      TextEncoderEncodeIntoResult
      No documentation available
      I
      v

      function atob

      #atob(s: string): string

      Decodes a string of data which has been encoded using base-64 encoding.

      console.log(atob("aGVsbG8gd29ybGQ=")); // outputs 'hello world'
      

      Parameters #

      #s: string

      Return Type #

      string

      function btoa

      #btoa(s: string): string

      Creates a base-64 ASCII encoded string from the input string.

      console.log(btoa("hello world"));  // outputs "aGVsbG8gd29ybGQ="
      

      Parameters #

      #s: string

      Return Type #

      string


      interface TextDecoder

      Represents a decoder for a specific text encoding, allowing you to convert binary data into a string given the encoding.

      Examples #

      #
      const decoder = new TextDecoder('utf-8');
      const buffer = new Uint8Array([72, 101, 108, 108, 111]);
      const decodedString = decoder.decode(buffer);
      console.log(decodedString); // Outputs: "Hello"
      

      Methods #

      Turns binary data, often in the form of a Uint8Array, into a string given the encoding.

      variable TextDecoder

      The constructor object for TextDecoder, used to create a decoder for a given text encoding (UTF-8 by default) that turns byte streams into strings.

      Properties #


      interface TextDecoderCommon

      Properties #

      #encoding: string
      readonly

      Returns encoding's name, lowercased.

      #fatal: boolean
      readonly

      Returns true if error mode is "fatal", otherwise false.

      #ignoreBOM: boolean
      readonly

      Returns the value of ignore BOM.




      interface TextEncoder

      Allows you to convert a string into binary data (in the form of a Uint8Array) given the encoding.

      Examples #

      #
      const encoder = new TextEncoder();
      const str = "Hello";
      const encodedData = encoder.encode(str);
      console.log(encodedData); // Outputs: Uint8Array(5) [72, 101, 108, 108, 111]
      

      Methods #

      #encode(input?: string): Uint8Array<ArrayBuffer>

      Turns a string into binary data (in the form of a Uint8Array) using UTF-8 encoding.

      #encodeInto(
      input: string,
      dest: Uint8Array<ArrayBufferLike>,
      ): TextEncoderEncodeIntoResult

      Encodes a string into the destination Uint8Array and returns the result of the encoding.

      variable TextEncoder

      The constructor object for TextEncoder, used to create an encoder that turns strings into UTF-8 encoded bytes.

      Properties #





      Did you find what you needed?

      Privacy policy