wayfind / is-utf8 Goto Github PK
View Code? Open in Web Editor NEWDetect if a buffer is utf8 encoded.
License: MIT License
Detect if a buffer is utf8 encoded.
License: MIT License
用sublimetext3保存为utf8文件,检测失败
var fs = require('fs');
var isUtf8 = require('is-utf8');
var utf8 = fs.readFileSync('test.html');
console.log('test.html is utf8: '+isUtf8(utf8));
Can you mention in the readme the minimum amount of bytes needed to reliably detect utf8?
Hey,
Thanks for the good effort in building this library. We would like to use your node in our project.
Can you let us know what BSD license have been assigned to this library?
Thanks
Kandy
NULL terminated strings (NULL is part of the buffer) should qualify as UTF-8 but don't.
In fact only a few characters below 0x20 qualify as valid.
The check for ASCII should simply be
if(bytes[i]<=0x7F)
And not
if( (// ASCII
bytes[i] == 0x09 ||
bytes[i] == 0x0A ||
bytes[i] == 0x0D ||
(0x20 <= bytes[i] && bytes[i] <= 0x7E)
)
UTF-8 is supposed to be backward compatible with ASCII.
The salient features of this scheme are as follows:
Backward compatibility: One-byte codes are used only for the ASCII values 0 through 127. In this case the UTF-8 code has the same value as the ASCII code. The high-order bit of these codes is always 0. This means that ASCII text is valid UTF-8....
The string is sent by a device and is received by a third party software (node-red) which uses is-UTF8. I can't change either.
We like to take code from github to make debian packages.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.