Encoding
Handle character encoding, decoding, and binary data conversion.
function atob
atob(s: string): stringDecodes 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): stringCreates a base-64 ASCII encoded string from the input string.
console.log(btoa("hello world")); // outputs "aGVsbG8gd29ybGQ="
Parameters
s: string Return Type
string interface TextDecodeOptions
Properties
stream: boolean 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 TextDecoderCommon
interface TextDecoderOptions
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
Properties
encoding: string Returns "utf-8".
interface TextEncoderEncodeIntoResult
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
© 2018–2025 the Deno authors
Licensed under the MIT License.
https://docs.deno.com/api/web/encoding