Skip to content

utf8Decode ​

Decodes an ArrayBuffer or Uint8Array to a UTF-8 string.

Syntax ​

typescript
utf8Decode(data: ArrayBuffer | Uint8Array): string

## Parameters ​

NameTypeDescription
dataArrayBuffer | Uint8ArrayThe data to be decoded

Returns ​

TypeDescription
stringThe decoded UTF-8 string

Example ​

typescript
utf8Decode(new Uint8Array([72, 101, 108, 108, 111])); // "Hello"

Notes ​

  • Supports environments with TextDecoder (modern browsers) and Buffer (Node.js).
  • Throws an error if no UTF-8 decoder is available.

References ​

Released under the MIT License.