TextDecoder
ClassDecodes binary data from a Uint8Array into a string using a specified character encoding.
Index
Properties
Methods
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
| Parameter | Type |
|---|---|
encoding? | string |
Returns
TextDecoder
Overrides
ScriptObject.constructor
Properties
encoding
readonlyencoding: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
| Parameter | Type |
|---|---|
data | Uint8Array |
Returns
string
getTypeName()
staticgetTypeName():string
Returns the type name of this class.
Returns
string
Overrides
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object is of the specified type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
isSame()
isSame(
other):boolean
Returns true if this object refers to the same instance as the given object.
Parameters
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean