Repository navigation
Version 4.0.0
jschardet 4 is a ground-up TypeScript rewrite, ported from Python's chardet 7. It detects correctly far more often than jschardet 3 and is several times faster, with the same detect() / detectAll() API.
Based on chardet e9603fad69cd (7.6.0 + 32 commits, 2026-08-30)
Highlights
- 99.4% accuracy on 3,138 test files, up from 43.1% in jschardet 3
- ~6× the throughput and ~10× lower peak memory
- Language and MIME type reported with every result
- Licensed 0BSD (previously LGPL)
- Ships ESM, CommonJS, and a browser bundle (
<script>/ AMD), with TypeScript types
The trade-off is size: the bundle grows from 119 to 691 KiB gzipped, and the first detect() call takes about 110 ms while the model decompresses. See the performance comparison.
Upgrading from jschardet 3
Most code keeps working unchanged, but results and confidence values differ, and a few behaviours changed. Most notably, detect() no longer returns null below minimumThreshold, and encoding names follow chardet's spelling (utf-8 rather than UTF-8). Read Upgrading from jschardet 3 before upgrading.
Requires Node.js 20 or later.
Bundle size changes since v3.1.4:
- dist/jschardet.js +786,791 +167.31% (470,248 -> 1,257,039)
- dist/jschardet.min.js +826,408 +241.84% (341,716 -> 1,168,124)
- dist/jschardet.esm.js (new, 1,246,295 bytes)
- dist/jschardet.esm.min.js (new, 1,167,542 bytes)