Spec-Zone.ru › Deno 2

Encoding

Handle character encoding, decoding, and binary data conversion.

Eg TextDecoder, TextEncoder


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 TextDecodeOptions

Properties

stream: boolean
optional

interface TextDecoder

extends TextDecoderCommon

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
readonly

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 TextDecoderOptions

Properties

fatal: boolean
optional
ignoreBOM: boolean
optional

interface TextDecoderStream

extends GenericTransformStreamTextDecoderCommon

Properties

readable: ReadableStream<string>
readonly
writable: WritableStream<AllowSharedBufferSource>
readonly

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
readonly

interface TextEncoder

extends TextEncoderCommon

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
readonly

interface TextEncoderCommon

Properties

encoding: string
readonly

Returns "utf-8".


interface TextEncoderEncodeIntoResult

Properties

read: number
written: number

interface TextEncoderStream

extends GenericTransformStreamTextEncoderCommon

Properties

readable: ReadableStream<Uint8Array<ArrayBuffer>>
readonly
writable: WritableStream<string>
readonly

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
readonly

© 2018–2025 the Deno authors
Licensed under the MIT License.
https://docs.deno.com/api/web/encoding

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API