BlackJack 3df7502993 most working, work on front end | 6 лет назад | |
---|---|---|
.. | ||
encoding | 6 лет назад | |
.npmignore | 6 лет назад | |
.travis.yml | 6 лет назад | |
LICENSE | 6 лет назад | |
README.md | 6 лет назад | |
index.js | 6 лет назад | |
match.js | 6 лет назад | |
package.json | 6 лет назад | |
yarn.lock | 6 лет назад |
Chardet is a character detection module for NodeJS written in pure Javascript. Module is based on ICU project http://site.icu-project.org/, which uses character occurency analysis to determine the most probable encoding.
npm i chardet
var chardet = require('chardet');
chardet.detect(new Buffer('hello there!'));
// or
chardet.detectFile('/path/to/file', function(err, encoding) {});
// or
chardet.detectFileSync('/path/to/file');
Sometimes, when data set is huge and you want to optimize performace (in tradeoff of less accuracy), you can sample only first N bytes of the buffer:
chardet.detectFile('/path/to/file', { sampleSize: 32 }, function(err, encoding) {});
Currently only these encodings are supported, more will be added soon.