utf-8-validate

Check if a buffer contains valid UTF-8

MIT 34 个版本
安装
npm install utf-8-validate
yarn add utf-8-validate
pnpm add utf-8-validate
bun add utf-8-validate
README

utf-8-validate

Version npm Linux/macOS/Windows Build

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 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

'use strict';

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

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

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

License

MIT

版本列表
6.0.6 2025-12-18
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
5.0.3 2020-10-31
5.0.2 2018-12-23
5.0.1 2018-07-05
5.0.0 2018-07-05
4.0.2 2018-05-06
4.0.1 2018-04-06
4.0.0 2017-12-03
4.0.0-napi 2017-12-04
3.0.4 2017-11-03
3.0.3 2017-07-07
3.0.2 2017-05-31
3.0.1 2017-02-06
3.0.0 2017-02-03
2.0.0 2016-12-08
1.2.2 2016-12-07
1.2.1 2015-08-21
1.2.0 2015-08-13
1.1.0 2015-05-05
1.0.1 2015-01-29
1.0.0 2015-01-28