All Projects → ashtuchkin → Iconv Lite

ashtuchkin / Iconv Lite

Licence: mit
Convert character encodings in pure javascript.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Iconv Lite

iconv
Fast encoding conversion library for Erlang / Elixir
Stars: ✭ 45 (-98.33%)
Mutual labels:  encoding, iconv
Elixir Json
Native JSON library for Elixir
Stars: ✭ 216 (-91.99%)
Mutual labels:  encoding
Cyberchef
The Cyber Swiss Army Knife - a web app for encryption, encoding, compression and data analysis
Stars: ✭ 13,674 (+407.01%)
Mutual labels:  encoding
Libchef
🍀 c++ standalone header-only basic library. || c++头文件实现无第三方依赖基础库
Stars: ✭ 178 (-93.4%)
Mutual labels:  encoding
Mini Svg Data Uri
Small, efficient encoding of SVG data URIs for CSS, HTML, etc.
Stars: ✭ 158 (-94.14%)
Mutual labels:  encoding
Base X
Encode/decode any base
Stars: ✭ 191 (-92.92%)
Mutual labels:  encoding
Ffmpeg Video Player
An FFmpeg and SDL Tutorial.
Stars: ✭ 149 (-94.48%)
Mutual labels:  encoding
Qs
Quick serialization of R objects
Stars: ✭ 225 (-91.66%)
Mutual labels:  encoding
Jsonlab
JSONLab: a native JSON/UBJSON/MassagePack encoder/decoder for MATLAB/Octave
Stars: ✭ 202 (-92.51%)
Mutual labels:  encoding
Encoding
Encoding Standard
Stars: ✭ 176 (-93.47%)
Mutual labels:  encoding
Packetserial
An Arduino Library that facilitates packet-based serial communication using COBS or SLIP encoding.
Stars: ✭ 177 (-93.44%)
Mutual labels:  encoding
Xssor2
XSS'OR - Hack with JavaScript.
Stars: ✭ 1,969 (-26.99%)
Mutual labels:  encoding
Rust Lexical
Lexical, to- and from-string conversion routines.
Stars: ✭ 192 (-92.88%)
Mutual labels:  encoding
Img Encode
Encode an image to sound and view it as a spectrogram - turn your images into music
Stars: ✭ 157 (-94.18%)
Mutual labels:  encoding
Go
decode/encode thrift message without IDL
Stars: ✭ 219 (-91.88%)
Mutual labels:  encoding
Datagene
DataGene - Identify How Similar TS Datasets Are to One Another (by @firmai)
Stars: ✭ 156 (-94.22%)
Mutual labels:  encoding
Go.geojson
Encoding and decoding GeoJSON <-> Go
Stars: ✭ 172 (-93.62%)
Mutual labels:  encoding
Convertzz
繼承自convertz,但更好用的簡繁轉換工具
Stars: ✭ 181 (-93.29%)
Mutual labels:  encoding
Armor
Armor is a simple Bash script designed to create encrypted macOS payloads capable of evading antivirus scanners.
Stars: ✭ 228 (-91.55%)
Mutual labels:  encoding
Stego
🦕 stego is a steganographic swiss army knife.
Stars: ✭ 220 (-91.84%)
Mutual labels:  encoding

iconv-lite: Pure JS character encoding conversion

  • No need for native code compilation. Quick to install, works on Windows, Web, and in sandboxed environments.
  • Used in popular projects like Express.js (body_parser), Grunt, Nodemailer, Yeoman and others.
  • Faster than node-iconv (see below for performance comparison).
  • Intuitive encode/decode API, including Streaming support.
  • In-browser usage via browserify or webpack (~180kb gzip compressed with Buffer shim included).
  • Typescript type definition file included.
  • React Native is supported (need to install stream module to enable Streaming API).
  • License: MIT.

NPM Stats
Build Status npm npm downloads npm bundle size

Usage

Basic API

var iconv = require('iconv-lite');

// Convert from an encoded buffer to a js string.
str = iconv.decode(Buffer.from([0x68, 0x65, 0x6c, 0x6c, 0x6f]), 'win1251');

// Convert from a js string to an encoded buffer.
buf = iconv.encode("Sample input string", 'win1251');

// Check if encoding is supported
iconv.encodingExists("us-ascii")

Streaming API

// Decode stream (from binary data stream to js strings)
http.createServer(function(req, res) {
    var converterStream = iconv.decodeStream('win1251');
    req.pipe(converterStream);

    converterStream.on('data', function(str) {
        console.log(str); // Do something with decoded strings, chunk-by-chunk.
    });
});

// Convert encoding streaming example
fs.createReadStream('file-in-win1251.txt')
    .pipe(iconv.decodeStream('win1251'))
    .pipe(iconv.encodeStream('ucs2'))
    .pipe(fs.createWriteStream('file-in-ucs2.txt'));

// Sugar: all encode/decode streams have .collect(cb) method to accumulate data.
http.createServer(function(req, res) {
    req.pipe(iconv.decodeStream('win1251')).collect(function(err, body) {
        assert(typeof body == 'string');
        console.log(body); // full request body string
    });
});

Supported encodings

  • All node.js native encodings: utf8, ucs2 / utf16-le, ascii, binary, base64, hex.
  • Additional unicode encodings: utf16, utf16-be, utf-7, utf-7-imap, utf32, utf32-le, and utf32-be.
  • All widespread singlebyte encodings: Windows 125x family, ISO-8859 family, IBM/DOS codepages, Macintosh family, KOI8 family, all others supported by iconv library. Aliases like 'latin1', 'us-ascii' also supported.
  • All widespread multibyte encodings: CP932, CP936, CP949, CP950, GB2312, GBK, GB18030, Big5, Shift_JIS, EUC-JP.

See all supported encodings on wiki.

Most singlebyte encodings are generated automatically from node-iconv. Thank you Ben Noordhuis and libiconv authors!

Multibyte encodings are generated from Unicode.org mappings and WHATWG Encoding Standard mappings. Thank you, respective authors!

Encoding/decoding speed

Comparison with node-iconv module (1000x256kb, on MacBook Pro, Core i5/2.6 GHz, Node v0.12.0). Note: your results may vary, so please always check on your hardware.

operation             [email protected]   [email protected]
----------------------------------------------------------
encode('win1251')     ~96 Mb/s      ~320 Mb/s
decode('win1251')     ~95 Mb/s      ~246 Mb/s

BOM handling

  • Decoding: BOM is stripped by default, unless overridden by passing stripBOM: false in options (f.ex. iconv.decode(buf, enc, {stripBOM: false})). A callback might also be given as a stripBOM parameter - it'll be called if BOM character was actually found.
  • If you want to detect UTF-8 BOM when decoding other encodings, use node-autodetect-decoder-stream module.
  • Encoding: No BOM added, unless overridden by addBOM: true option.

UTF-16 Encodings

This library supports UTF-16LE, UTF-16BE and UTF-16 encodings. First two are straightforward, but UTF-16 is trying to be smart about endianness in the following ways:

  • Decoding: uses BOM and 'spaces heuristic' to determine input endianness. Default is UTF-16LE, but can be overridden with defaultEncoding: 'utf-16be' option. Strips BOM unless stripBOM: false.
  • Encoding: uses UTF-16LE and writes BOM by default. Use addBOM: false to override.

UTF-32 Encodings

This library supports UTF-32LE, UTF-32BE and UTF-32 encodings. Like the UTF-16 encoding above, UTF-32 defaults to UTF-32LE, but uses BOM and 'spaces heuristics' to determine input endianness.

  • The default of UTF-32LE can be overridden with the defaultEncoding: 'utf-32be' option. Strips BOM unless stripBOM: false.
  • Encoding: uses UTF-32LE and writes BOM by default. Use addBOM: false to override. (defaultEncoding: 'utf-32be' can also be used here to change encoding.)

Other notes

When decoding, be sure to supply a Buffer to decode() method, otherwise bad things usually happen.
Untranslatable characters are set to � or ?. No transliteration is currently supported.
Node versions 0.10.31 and 0.11.13 are buggy, don't use them (see #65, #77).

Testing

$ git clone [email protected]:ashtuchkin/iconv-lite.git
$ cd iconv-lite
$ npm install
$ npm test
    
$ # To view performance:
$ node test/performance.js

$ # To view test coverage:
$ npm run coverage
$ open coverage/lcov-report/index.html
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].