Package Exports
- utf-8-validate
- utf-8-validate/index.js
- utf-8-validate/package.json
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (utf-8-validate) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
utf-8-validate
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