# utf-8-validate

> Check if a buffer contains valid UTF-8

Latest version **6.0.6** (published 2025-12-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install utf-8-validate
pnpm add utf-8-validate
yarn add utf-8-validate
bun add utf-8-validate
```

## Health

**Score 58/100 (C)** — status: stable.

Positive: has types package; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 6.0.6 |
| Published | 2025-12-18 |
| First published | 2015-01-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/utf-8-validate) |
| Module format | CommonJS |
| Node | >=6.14.2 |
| Dependencies | 1 |
| Unpacked size | 676.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 127 |
| Author | Einar Otto Stangvik |
| Maintainers | einaros, v1, lpinca, 3rdeden |
| Keywords | utf-8-validate |

## Links

- npm: https://www.npmjs.com/package/utf-8-validate
- Repository: https://github.com/websockets/utf-8-validate
- Issues: https://github.com/websockets/utf-8-validate/issues
- npm.io page: https://npm.io/package/utf-8-validate

## Dependencies (1)

- [node-gyp-build](https://npm.io/package/node-gyp-build.md) ^4.3.0

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 6.0.6 (latest) — 2025-12-18
- 4.0.0-napi (n-api) — 2017-12-04
- 6.0.5 — 2024-11-01
- 6.0.4 — 2024-05-10
- 6.0.3 — 2023-02-24
- 6.0.2 — 2023-01-26
- 6.0.1 — 2023-01-21
- 6.0.0 — 2023-01-04
- 5.0.10 — 2022-10-18
- 5.0.9 — 2022-03-08
- 5.0.8 — 2022-01-02
- 5.0.7 — 2021-10-13
- 5.0.6 — 2021-09-26
- 5.0.5 — 2021-05-03
- 5.0.4 — 2021-01-03
- … 19 more at https://npm.io/package/utf-8-validate/versions

## README

# utf-8-validate

[![Version npm](https://img.shields.io/npm/v/utf-8-validate.svg?logo=npm)](https://www.npmjs.com/package/utf-8-validate)
[![Linux/macOS/Windows Build](https://img.shields.io/github/actions/workflow/status/websockets/utf-8-validate/ci.yml?branch=master&label=build&logo=github)](https://github.com/websockets/utf-8-validate/actions?query=workflow%3ACI+branch%3Amaster)

Check if a buffer contains valid UTF-8 encoded text.

## Installation

```
npm install utf-8-validate --save-optional
```

The `--save-optional` flag tells npm to save the package in your package.json
under the
[`optionalDependencies`](https://docs.npmjs.com/files/package.json#optionaldependencies)
key.

## API

The module exports a single function that takes one argument. To maximize
performance, the argument is not validated. It is the caller's responsibility to
ensure that it is correct.

### `isValidUTF8(buffer)`

Checks whether a buffer contains valid UTF-8.

#### Arguments

- `buffer` - The buffer to check.

#### Return value

`true` if the buffer contains only correct UTF-8, else `false`.

#### Example

```js
'use strict';

const isValidUTF8 = require('utf-8-validate');

const buf = Buffer.from([0xf0, 0x90, 0x80, 0x80]);

console.log(isValidUTF8(buf));
// => true
```

## License

[MIT](LICENSE)

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