Giter Club home page Giter Club logo

iconv-lite's Introduction

Pure JS character encoding conversion

  • Doesn't need native code compilation. Works on Windows and in sandboxed environments like Cloud9.
  • Intuitive encode/decode API.
  • Encoding is faster than node-iconv (see below for performance comparison).
  • Used in popular projects like Grunt, Nodemailer, Yeoman and others.
  • License: MIT.

NPM Stats

Usage

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

// Convert from an encoded buffer to js string.
str = iconv.decode(buf, 'win1251');

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

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

Supported encodings

  • All node.js native encodings: 'utf8', 'ucs2', 'ascii', 'binary', 'base64'
  • All widespread single byte encodings: Windows 125x family, ISO-8859 family, IBM/DOS codepages, Macintosh family, KOI8 family. Aliases like 'latin1', 'us-ascii' also supported.
  • Multibyte encodings: 'gbk', 'gb2313', 'Big5', 'cp950'.

Others are easy to add, see the source. Please, participate. Most encodings are generated automatically from node-iconv. Thank you Ben Noordhuis and iconv authors!

Not supported yet: EUC family, Shift_JIS.

Encoding/decoding speed

Comparison with node-iconv module (1000x256kb, on Ubuntu 12.04, Core i5/2.5 GHz, Node v0.8.7). Note: your results may vary, so please always check on your hardware.

operation             [email protected]   [email protected] 
----------------------------------------------------------
encode('win1251')     ~115 Mb/s     ~230 Mb/s
decode('win1251')     ~95 Mb/s      ~130 Mb/s

Notes

When decoding, a 'binary'-encoded string can be used as a source buffer.
Untranslatable characters are set to � or ?. No transliteration is currently supported, pull requests are welcome.

Testing

git clone [email protected]:ashtuchkin/iconv-lite.git
cd iconv-lite
npm install
npm test

# To view performance:
node test/performance.js

TODO

  • Support streaming character conversion, something like util.pipe(req, iconv.fromEncodingStream('latin1')).
  • Add more encodings.
  • Add transliteration (best fit char).
  • Add tests and correct support of variable-byte encodings (currently work is delegated to node).

Adoption

NPM

iconv-lite's People

Contributors

adamansky avatar ashtuchkin avatar atinux avatar david50407 avatar fengmk2 avatar jenkinv avatar lastonesky avatar leetreveil avatar mscdex avatar pekim avatar redchair123 avatar stagas avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.