Dev Helpers

Node.js / Text encoding

Detect ASCII-only bytes

Dev Helpers · August 12, 2026

An ASCII check operates on bytes. A string that looks simple after display normalization may still require multibyte encoding.

Worked example

import { Buffer, isUtf8, isAscii } from "node:buffer";
console.log(isAscii(Buffer.from("café")));

Result

false

Implementation notes

ASCII validity does not imply safe or printable text. Control characters still fall within the ASCII range.

Try it yourself

Compare a plain hyphen with an en dash encoded as UTF-8.

Open the Node.js example →

Editorial date August 12, 2026 · Published December 6, 2026

Related articles

Safely parse malformed input

Parsing user-provided JSON needs a failure path. Successful parsing alone does not establish that the result has the expected shape.

Checksum bytes with CRC32

CRC32 is useful for detecting accidental changes to a byte sequence. Record the input encoding so different producers compute the same checksum.

Attach details to a mark

Performance marks can carry details about the operation they describe. Small stable identifiers are easier to aggregate than large payloads.