Buffer
buffer.isUtf8()
Tests whether bytes form valid UTF-8 before decoding. It does not validate the meaning or safety of the decoded text. Tested on Node.js 22.16.0. Example output (one line per entry): ["true false"].
Formal Syntax & Structure
nodejs syntaxnodejs
isUtf8(input)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| input | Buffer | TypedArray | ArrayBuffer | Input bytes. |
Return Value
boolean
UTF-8 validity.
Working Example
Example Snippetnodejs
import { isUtf8 } from 'node:buffer';console.log(isUtf8(Buffer.from('é')), isUtf8(Buffer.from([0xc3, 0x28])));