chardet
Advanced tools
Character encoding detector
Weekly downloads
Readme
Chardet is a character detection module written in pure Javascript (Typescript). Module uses occurrence analysis to determine the most probable encoding.
npm i chardet
To return the encoding with the highest confidence:
const chardet = require('chardet');
chardet.detect(Buffer.from('hello there!'));
// or
chardet.detectFile('/path/to/file').then(encoding => console.log(encoding));
// or
chardet.detectFileSync('/path/to/file');
To return the full list of possible encodings use analyse
method.
const chardet = require('chardet');
chardet.analyse(Buffer.from('hello there!'));
Returned value is an array of objects sorted by confidence value in decending order
[
{ confidence: 90, name: 'UTF-8' },
{ confidence: 20, name: 'windows-1252', lang: 'fr' }
];
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 })
.then(encoding => console.log(encoding));
Currently only these encodings are supported.
Yes. Type definitions are included.
Character encoding detector
The npm package chardet receives a total of 15,741,968 weekly downloads. As such, chardet popularity was classified as popular.
We found that chardet demonstrated a healthy version release cadence and project activity. It has 1 open source maintainer collaborating on the project.