# jschardet

> Character encoding auto-detection in JavaScript (port of python's chardet)

Latest version **3.1.4** (published 2024-09-30) · LGPL-2.1+ license · 0 weekly downloads

## Install

```sh
npm install jschardet
pnpm add jschardet
yarn add jschardet
bun add jschardet
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: has types; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 3.1.4 |
| Published | 2024-09-30 |
| First published | 2012-03-01 |
| Weekly downloads | 0 |
| License | LGPL-2.1+ |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=0.1.90 |
| Dependencies | 0 |
| Unpacked size | 1.3 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 741 |
| Author | António Afonso |
| Maintainers | aadsm |
| Keywords | encoding, charset |

## Links

- npm: https://www.npmjs.com/package/jschardet
- Repository: https://github.com/aadsm/jschardet
- Homepage: https://github.com/aadsm/jschardet#readme
- Issues: https://github.com/aadsm/jschardet/issues
- npm.io page: https://npm.io/package/jschardet

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 3.1.4 (latest) — 2024-09-30
- 4.0.0-rc.3 (rc) — 2026-09-04
- 4.0.0-rc.2 — 2026-08-23
- 4.0.0-rc.1 — 2026-07-27
- 4.0.0-rc.0 — 2026-06-25
- 3.1.3 — 2024-06-18
- 3.1.2 — 2024-03-25
- 3.1.1 — 2024-03-23
- 3.1.0 — 2024-03-19
- 3.0.0 — 2021-04-15
- 2.3.0 — 2021-02-22
- 2.2.1 — 2020-06-30
- 2.2.0 — 2020-06-29
- 2.1.1 — 2019-11-10
- 2.1.0 — 2019-01-22
- … 15 more at https://npm.io/package/jschardet/versions

## README

[![NPM](https://nodei.co/npm/jschardet.png?downloads=true&downloadRank=true)](https://nodei.co/npm/jschardet/)

JsChardet
=========

Port of python's chardet (https://github.com/chardet/chardet).

License
-------

LGPL

How To Use It
-------------

### Node
```
npm install jschardet
```

    var jschardet = require("jschardet")

    // "àíàçã" in UTF-8
    jschardet.detect("\xc3\xa0\xc3\xad\xc3\xa0\xc3\xa7\xc3\xa3")
    // { encoding: "UTF-8", confidence: 0.9690625 }

    // "次常用國字標準字體表" in Big5
    jschardet.detect("\xa6\xb8\xb1\x60\xa5\xce\xb0\xea\xa6\x72\xbc\xd0\xb7\xc7\xa6\x72\xc5\xe9\xaa\xed")
    // { encoding: "Big5", confidence: 0.99 }

    // Martin Kühl
    // jschardet.detectAll("\x3c\x73\x74\x72\x69\x6e\x67\x3e\x4d\x61\x72\x74\x69\x6e\x20\x4b\xfc\x68\x6c\x3c\x2f\x73\x74\x72\x69\x6e\x67\x3e")
    // [
    //   {encoding: "windows-1252", confidence: 0.95},
    //   {encoding: "ISO-8859-2", confidence: 0.8796300205763055},
    //   {encoding: "SHIFT_JIS", confidence: 0.01}
    // ]

### Browser
Copy and include [jschardet.min.js](https://github.com/aadsm/jschardet/tree/master/dist/jschardet.min.js) in your web page.

This library is also available in [cdnjs](https://cdnjs.com) at [https://cdnjs.cloudflare.com/ajax/libs/jschardet/1.4.1/jschardet.min.js](https://cdnjs.cloudflare.com/ajax/libs/jschardet/1.4.1/jschardet.min.js)

Options
-------

```javascript
// See all information related to the confidence levels of each encoding.
// This is useful to see why you're not getting the expected encoding.
jschardet.enableDebug();

// Default minimum accepted confidence level is 0.20 but sometimes this is not
// enough, specially when dealing with files mostly with numbers.
// To change this to 0 to always get something or any other value that can
// work for you.
jschardet.detect(str, { minimumThreshold: 0 });

// Lock down which encodings to detect, can be useful in situations jschardet
// is giving a higher probability to encodings that you never use.
jschardet.detect(str, { detectEncodings: ["UTF-8", "windows-1252"] });
```

Supported Charsets
------------------

* Big5, GB2312/GB18030, EUC-TW, HZ-GB-2312, and ISO-2022-CN (Traditional and Simplified Chinese)
* EUC-JP, SHIFT_JIS, and ISO-2022-JP (Japanese)
* EUC-KR and ISO-2022-KR (Korean)
* KOI8-R, MacCyrillic, IBM855, IBM866, ISO-8859-5, and windows-1251 (Russian)
* ISO-8859-2 and windows-1250 (Hungarian)
* ISO-8859-5 and windows-1251 (Bulgarian)
* windows-1252
* ISO-8859-7 and windows-1253 (Greek)
* ISO-8859-8 and windows-1255 (Visual and Logical Hebrew)
* TIS-620 (Thai)
* UTF-32 BE, LE, 3412-ordered, or 2143-ordered (with a BOM)
* UTF-16 BE or LE (with a BOM)
* UTF-8 (with or without a BOM)
* ASCII

Technical Information
---------------------

I haven't been able to create tests to correctly detect:

* ISO-2022-CN
* windows-1250 in Hungarian
* windows-1251 in Bulgarian
* windows-1253 in Greek
* EUC-CN

Development
-----------
Use `npm run dist` to update the distribution files. They're available at https://github.com/aadsm/jschardet/tree/master/dist.

Authors
-------

Ported from python to JavaScript by António Afonso (https://github.com/aadsm/jschardet)

Transformed into an npm package by Markus Ast (https://github.com/brainafk)

---
_Source: https://npm.io/package/jschardet · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
