Skip to content

websockets/utf-8-validate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

1439ad4 · Dec 21, 2024
Aug 7, 2024
Oct 28, 2024
Jan 3, 2023
Jul 5, 2018
Jan 3, 2023
Apr 25, 2020
Jan 3, 2023
Oct 26, 2024
Oct 28, 2024
May 3, 2021
Jul 5, 2018
Dec 21, 2024

Repository files navigation

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