# detect-character-encoding

> Detect character encoding using ICU

Latest version **0.9.0** (published 2024-01-06) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install detect-character-encoding
pnpm add detect-character-encoding
yarn add detect-character-encoding
bun add detect-character-encoding
```

## Health

**Score 23/100 (F)** — status: abandoned.

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

Warnings: low downloads; no esm support; large bundle; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.9.0 |
| Published | 2024-01-06 |
| First published | 2015-03-15 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | separate (@types/detect-character-encoding) |
| Module format | CommonJS |
| Node | >=18 |
| Dependencies | 2 |
| Unpacked size | 20.7 MB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 84 |
| Author | Jakob Krigovsky |
| Maintainers | sonicdoe |
| Keywords | detect, character, encoding, charset, icu |

## Links

- npm: https://www.npmjs.com/package/detect-character-encoding
- Repository: https://github.com/sonicdoe/detect-character-encoding
- Homepage: https://github.com/sonicdoe/detect-character-encoding#readme
- Issues: https://github.com/sonicdoe/detect-character-encoding/issues
- npm.io page: https://npm.io/package/detect-character-encoding

## Dependencies (2)

- [nan](https://npm.io/package/nan.md) ^2.18.0
- [bindings](https://npm.io/package/bindings.md) ^1.3.0

## 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

- 0.9.0 (latest) — 2024-01-06
- 0.8.0 — 2019-07-01
- 0.7.0 — 2018-11-06
- 0.6.0 — 2018-06-14
- 0.5.1 — 2017-09-09
- 0.5.0 — 2017-07-23
- 0.4.0 — 2017-07-02
- 0.3.1 — 2017-03-10
- 0.3.0 — 2017-01-28
- 0.2.1 — 2015-12-28
- 0.2.0 — 2015-09-15
- 0.1.0 — 2015-03-15

## README

# detect-character-encoding

> Detect character encoding using [ICU](http://site.icu-project.org)

**Tip:** If you don’t need ICU in particular, consider using [ced](https://github.com/sonicdoe/ced), which is based on Google’s lighter [compact_enc_det](https://github.com/google/compact_enc_det) library.

## Installation

```console
$ npm install detect-character-encoding
```

detect-character-encoding is a C++ addon. Therefore, you may need to install various build tools. Check [node-gyp’s readme](https://github.com/nodejs/node-gyp#installation) for more information.

## Usage

```js
const fs = require('fs');
const detectCharacterEncoding = require('detect-character-encoding');

const fileBuffer = fs.readFileSync('file.txt');
const charsetMatch = detectCharacterEncoding(fileBuffer);

console.log(charsetMatch);
// {
//   encoding: 'UTF-8',
//   confidence: 60
// }
```

detect-character-encoding may return `null` if no charset matches.

## Supported operating systems

- macOS Sonoma
- Ubuntu 22.04 and 20.04
- Debian 12, 11, and 10

detect-character-encoding does not support 32-bit operating systems.

## Supported character sets

As listed in [ICU’s user guide](http://userguide.icu-project.org/conversion/detection#TOC-Detected-Encodings):

- UTF-8
- UTF-16BE
- UTF-16LE
- UTF-32BE
- UTF-32LE
- Shift_JIS
- ISO-2022-JP
- ISO-2022-CN
- ISO-2022-KR
- GB18030
- Big5
- EUC-JP
- EUC-KR
- ISO-8859-1
- ISO-8859-2
- ISO-8859-5
- ISO-8859-6
- ISO-8859-7
- ISO-8859-8
- ISO-8859-9
- windows-1250
- windows-1251
- windows-1252
- windows-1253
- windows-1254
- windows-1255
- windows-1256
- KOI8-R
- IBM420
- IBM424

## License

detect-character-encoding is licensed under the BSD 2-clause license but includes third-party software under different licenses. See [`LICENSE.md`](./LICENSE.md) for the full license text.

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