# isutf8

> Check if a Node.js Buffer or Uint8Array is UTF-8

Latest version **4.0.4** (published 2026-09-11) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install isutf8
pnpm add isutf8
yarn add isutf8
bun add isutf8
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 4.0.4 |
| Published | 2026-09-11 |
| First published | 2014-11-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 12 |
| Dependencies | 0 |
| Unpacked size | 10.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 21 |
| Author | Denis Seleznev |
| Maintainers | hcodes |
| Keywords | charset, utf-8, is utf, is utf-8, is utf8, utf8, unicode, is unicode, text, check, validate, encoding, Buffer, Uint8Array |

## Links

- npm: https://www.npmjs.com/package/isutf8
- Repository: https://github.com/hcodes/isutf8
- Issues: https://github.com/hcodes/isutf8/issues
- npm.io page: https://npm.io/package/isutf8

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 4.0.4 (latest) — 2026-09-11
- 4.0.3 — 2026-09-11
- 4.0.1 — 2024-08-27
- 4.0.0 — 2021-10-31
- 3.1.1 — 2020-09-24
- 3.1.0 — 2020-09-23
- 3.0.0 — 2020-05-09
- 2.1.0 — 2019-08-29
- 2.0.4 — 2019-06-08
- 2.0.3 — 2019-01-16
- 2.0.2 — 2018-01-08
- 2.0.1 — 2017-03-09
- 2.0.0 — 2016-05-28
- 1.0.11 — 2015-02-23
- 1.0.10 — 2014-12-03
- … 8 more at https://npm.io/package/isutf8/versions

## README

[![NPM Version](https://img.shields.io/npm/v/isutf8.svg?style=flat)](https://www.npmjs.org/package/isutf8)
[![NPM Downloads](https://img.shields.io/npm/dm/isutf8.svg?style=flat)](https://www.npmjs.org/package/isutf8)
[![install size](https://packagephobia.com/badge?p=isutf8)](https://packagephobia.com/result?p=isutf8)

isutf8
======

> **Deprecated:** Use [`isUtf8` from `node:buffer`](https://nodejs.org/api/buffer.html#bufferisutf8input)
> in Node.js, or [`TextDecoder`](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/decode)
> with `{ fatal: true }` in browsers. See the migration examples below.

Quick check if a Node.js Buffer or Uint8Array is valid UTF-8.

## Advantages

- Ultra-small package size
- No runtime dependencies
- No native compilation required

## Migration to built-in APIs

For modern Node.js applications, prefer the built-in
[`isUtf8` from `node:buffer`](https://nodejs.org/api/buffer.html#bufferisutf8input),
available since Node.js 18.14.0 and 19.4.0:

```js
import { isUtf8 } from 'node:buffer';

console.log(isUtf8(Buffer.from([0xd0, 0x90]))); // true
```

In modern browsers, use
[`TextDecoder`](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/decode)
with `fatal: true` to reject invalid UTF-8:

```js
function isUtf8(input) {
  if (input === undefined) return false;

  try {
    new TextDecoder('utf-8', { fatal: true }).decode(input);
    return true;
  } catch (error) {
    if (error instanceof TypeError) return false;
    throw error;
  }
}

console.log(isUtf8(new Uint8Array([0xd0, 0x90]))); // true
console.log(isUtf8(new Uint8Array([0xc3]))); // false
```

Unlike a byte-only validator, `TextDecoder` also produces a decoded string.
This package mainly remains useful for older environments without these APIs
(it supports Node.js 12 or later), or for retaining its existing API.
When migrating, note that this package returns `false` for a missing argument,
while Node.js's built-in `isUtf8` throws a `TypeError`.

## Install

```sh
npm install isutf8
```

## Usage

### CommonJS

```js
const isUtf8 = require('isutf8');

const buf = Buffer.from([0xd0, 0x90]);
console.log(isUtf8(buf)); // true

// or

const arr = new Uint8Array([0xd0, 0x90]);
console.log(isUtf8(arr)); // true
```

### ES Modules or TypeScript

```js
import isUtf8 from 'isutf8';

const buf = Buffer.from([0xd0, 0x90]);
console.log(isUtf8(buf)); // true

// or

const arr = new Uint8Array([0xd0, 0x90]);
console.log(isUtf8(arr)); // true
```

## API

`isUtf8(input?: Buffer | Uint8Array): boolean`

Returns `true` for valid UTF-8 byte sequences, including ASCII and empty input.
Returns `false` for invalid or incomplete sequences, or a missing argument.
It validates bytes; it does not detect the original encoding or decode text.

```js
const isUtf8 = require('isutf8');

console.log(isUtf8(new Uint8Array())); // true
console.log(isUtf8(new Uint8Array([0xc3]))); // false: incomplete sequence
console.log(isUtf8()); // false
```

## Development

Use Node.js 22.13.0 or later in the Node.js 22 line, or Node.js 24 or later,
for the development tools.

```sh
npm ci
npm test
npm run build
```

TypeScript is kept on 6.0.x because the current `typescript-eslint` and `ts-jest`
releases do not support TypeScript 7 yet.

## License

[MIT License](./LICENSE)

---
_Source: https://npm.io/package/isutf8 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
