You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
astria 899f8e0b77 ebsocket 4 months ago
..
deps/is_utf8 ebsocket 4 months ago
prebuilds ebsocket 4 months ago
src ebsocket 4 months ago
LICENSE ebsocket 4 months ago
README.md ebsocket 4 months ago
binding.gyp ebsocket 4 months ago
fallback.js ebsocket 4 months ago
index.js ebsocket 4 months ago
package.json ebsocket 4 months ago

README.md

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