Have ideas to improve npm?Join in the discussion! »

detect-character-encoding
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/detect-character-encoding package

0.8.0 • Public • Published

detect-character-encoding

npm Build status

Detect character encoding using ICU

Installation

$ npm install detect-character-encoding

Usage

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 Mojave and macOS High Sierra
  • Ubuntu 18.04 and 16.04
  • Debian 9 and 8

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

Supported character sets

As listed in ICU’s user guide:

  • 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 for the full license text.

Install

npm i detect-character-encoding

DownloadsWeekly Downloads

3,337

Version

0.8.0

License

BSD-2-Clause

Unpacked Size

21 MB

Total Files

944

Last publish

Collaborators

  • avatar