吕君喜 406d880ac6 first | 3 tahun lalu | |
---|---|---|
.. | ||
prebuilds | 3 tahun lalu | |
src | 3 tahun lalu | |
LICENSE | 3 tahun lalu | |
README.md | 3 tahun lalu | |
binding.gyp | 3 tahun lalu | |
fallback.js | 3 tahun lalu | |
index.js | 3 tahun lalu | |
package.json | 3 tahun lalu |
Check if a buffer contains valid UTF-8 encoded text.
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.
The module exports a single function which takes one argument.
isValidUTF8(buffer)
Checks whether a buffer contains valid UTF-8.
buffer
- The buffer to check.true
if the buffer contains only correct UTF-8, else false
.
'use strict';
const isValidUTF8 = require('utf-8-validate');
const buf = Buffer.from([0xf0, 0x90, 0x80, 0x80]);
console.log(isValidUTF8(buf));
// => true