Skip to main content

TextDecoder

Class

Decodes binary data from a Uint8Array into a string using a specified character encoding.

Index

Example

const decoder = new TextDecoder('utf-8');
const bytes = new Uint8Array([72, 101, 108, 108, 111]);
const text = decoder.decode(bytes);
console.log('Decoded text:', text);

const moreBytes = new Uint8Array([87, 111, 114, 108, 100]);
const moreText = decoder.decode(moreBytes);
console.log('Decoded more:', moreText);

Extends

Constructors

Constructor

new TextDecoder(encoding?): TextDecoder

Constructs a TextDecoder with an optional encoding name (defaults to UTF-8).

Parameters

ParameterType
encoding?string

Returns

TextDecoder

Overrides

ScriptObject.constructor

Properties

encoding

readonly encoding: string

The character encoding name used by this decoder, e.g. 'utf-8'.

Methods

decode()

decode(data): string

Decodes a Uint8Array into a string using the instance's encoding.

Parameters

ParameterType
dataUint8Array

Returns

string


getTypeName()

static getTypeName(): string

Returns the type name of this class.

Returns

string

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object is of the specified type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ScriptObject.isOfType


isSame()

isSame(other): boolean

Returns true if this object refers to the same instance as the given object.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

ScriptObject.isSame