Skip to main content
TextDecoder - node__util.d.ts - Node documentation
class TextDecoder

Usage in Deno

```typescript import { TextDecoder } from "node:node__util.d.ts"; ```
An implementation of the [WHATWG Encoding Standard](https://encoding.spec.whatwg.org/) `TextDecoder` API. ```js const decoder = new TextDecoder(); const u8arr = new Uint8Array([72, 101, 108, 108, 111]); console.log(decoder.decode(u8arr)); // Hello ```

Constructors

new
TextDecoder(
encoding?: string,
options?: { fatal?: boolean | undefined; ignoreBOM?: boolean | undefined; },
)

Properties

readonly
encoding: string
The encoding supported by the `TextDecoder` instance.
readonly
fatal: boolean
The value will be `true` if decoding errors result in a `TypeError` being thrown.
readonly
ignoreBOM: boolean
The value will be `true` if the decoding result will include the byte order mark.

Methods

decode(
input?:
ArrayBufferView
| ArrayBuffer
| null
,
options?: { stream?: boolean | undefined; },
): string
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.
variable TextDecoder
`TextDecoder` class is a global reference for `import { TextDecoder } from 'node:util'` https://nodejs.org/api/globals.html#textdecoder

Type

globalThis extends { onmessage: any; TextDecoder: infer TextDecoder; } ? TextDecoder : _TextDecoder