Gathering detailed insights and metrics for chardet
Gathering detailed insights and metrics for chardet
Gathering detailed insights and metrics for chardet
Gathering detailed insights and metrics for chardet
@types/chardet
Stub TypeScript definitions entry for chardet, which provides its own types definitions
jschardet
Character encoding auto-detection in JavaScript (port of python's chardet)
bemuse-chardet
Fork of chardet for use in bemuse
grunt-chardet-encoding
Check character encoding of files using chardet.
npm install chardet
Typescript
Module System
Node Version
NPM Version
TypeScript (99.69%)
JavaScript (0.31%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
292 Stars
201 Commits
73 Forks
7 Watchers
18 Branches
11 Contributors
Updated on Jul 10, 2025
Latest Version
2.1.0
Package Id
chardet@2.1.0
Unpacked Size
157.99 kB
Size
22.70 kB
File Count
39
NPM Version
10.9.2
Node Version
20.18.2
Published on
Feb 24, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
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:
1import chardet from 'chardet'; 2 3const encoding = chardet.detect(Buffer.from('hello there!')); 4// or 5const encoding = await chardet.detectFile('/path/to/file'); 6// or 7const encoding = chardet.detectFileSync('/path/to/file');
To return the full list of possible encodings use analyse
method.
1import chardet from 'chardet'; 2chardet.analyse(Buffer.from('hello there!'));
Returned value is an array of objects sorted by confidence value in descending order
1[ 2 { confidence: 90, name: 'UTF-8' }, 3 { confidence: 20, name: 'windows-1252', lang: 'fr' }, 4];
In browser, you can use Uint8Array instead of the Buffer
:
1import chardet from 'chardet'; 2chardet.analyse(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f]));
Sometimes, when data set is huge and you want to optimize performance (with a trade off of less accuracy), you can sample only the first N bytes of the buffer:
1const encoding = await chardet.detectFile('/path/to/file', { sampleSize: 32 });
You can also specify where to begin reading from in the buffer:
1const encoding = await chardet.detectFile('/path/to/file', { 2 sampleSize: 32, 3 offset: 128, 4});
In both Node.js and browsers, all strings in memory are represented in UTF-16 encoding. This is a fundamental aspect of the JavaScript language specification. Therefore, you cannot use plain strings directly as input for chardet.analyse()
or chardet.detect()
. Instead, you need the original string data in the form of a Buffer or Uint8Array.
In other words, if you receive a piece of data over the network and want to detect its encoding, use the original data payload, not its string representation. By the time you convert data to a string, it will be in UTF-16 encoding.
Note on TextEncoder: By default, it returns a UTF-8 encoded buffer, which means the buffer will not be in the original encoding of the string.
Currently only these encodings are supported.
Yes. Type definitions are included.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
packaging workflow detected
Details
Reason
1 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 1
Reason
Found 2/26 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More