Encoding
Handle character encoding, decoding, and binary data conversion.
Functions
Interfaces
Represents a decoder for a specific text encoding, allowing you to convert binary data into a string given the encoding.
Allows you to convert a string into binary data (in the form of a Uint8Array) given the encoding.
interface TextDecodeOptions
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 #
#decode(input?: AllowSharedBufferSource,options?: TextDecodeOptions,): string 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 #
#prototype: TextDecoder interface TextDecoderStream
Properties #
#readable: ReadableStream<string> #writable: WritableStream<AllowSharedBufferSource> variable TextDecoderStream
The constructor object for TextDecoderStream, used to create a
transform stream that decodes a stream of bytes into a stream of strings.
Properties #
#prototype: TextDecoderStream 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 #
#prototype: TextEncoder interface TextEncoderCommon
interface TextEncoderStream
Properties #
#readable: ReadableStream<Uint8Array<ArrayBuffer>> #writable: WritableStream<string> variable TextEncoderStream
The constructor object for TextEncoderStream, used to create a
transform stream that encodes a stream of strings into a stream of UTF-8
bytes.
Properties #
#prototype: TextEncoderStream