TextDecoder class
An implementation of the WHATWG Encoding Standard TextDecoder API.
const decoder = new TextDecoder();
const u8arr = new Uint8Array([72, 101, 108, 108, 111]);
console.log(decoder.decode(u8arr)); // Hello
Properties
| encoding | The encoding supported by the |
| fatal | The value will be |
| ignoreBOM | The value will be |
Methods
| decode(null | Array |
Decodes the If |
Constructor Details
TextDecoder(string, { fatal?: boolean, ignoreBOM?: boolean })
new TextDecoder(encoding?: string, options?: { fatal?: boolean, ignoreBOM?: boolean })
Parameters
- encoding
-
string
- options
-
{ fatal?: boolean, ignoreBOM?: boolean }
Property Details
encoding
The encoding supported by the TextDecoder instance.
encoding: string
Property Value
string
fatal
The value will be true if decoding errors result in a TypeError being
thrown.
fatal: boolean
Property Value
boolean
ignoreBOM
The value will be true if the decoding result will include the byte order
mark.
ignoreBOM: boolean
Property Value
boolean
Method Details
decode(null | ArrayBuffer | ArrayBufferView, { stream?: boolean })
Decodes the input and returns a string. If options.stream is true, any
incomplete byte sequences occurring at the end of the input are buffered
internally and emitted after the next call to textDecoder.decode().
If textDecoder.fatal is true, decoding errors that occur will result in a TypeError being thrown.
function decode(input?: null | ArrayBuffer | ArrayBufferView, options?: { stream?: boolean }): string
Parameters
- input
-
null | ArrayBuffer | ArrayBufferView
An ArrayBuffer, DataView, or TypedArray instance containing the encoded data.
- options
-
{ stream?: boolean }
Returns
string