22 Star 218 Fork 230

记得要让着本宝宝/ckjcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
.idea
_includes
_layouts
_posts
css
fonts
img
js
less
node_modules
.bin
abbrev
align-text
amdefine
ansi-regex
ansi-styles
argparse
asn1
assert-plus
async
aws-sign2
boom
browserify-zlib
buffer-from
camelcase
center-align
chalk
clean-css
cliui
coffee-script
colors
combined-stream
commander
concat-stream
core-util-is
cryptiles
ctype
dateformat
debug
decamelize
deep-equal
defined
delayed-stream
escape-string-regexp
esprima
eventemitter2
exit
faye-websocket
figures
findup-sync
forever-agent
form-data
gaze
getobject
glob
globule
graceful-fs
grunt-contrib-less/node_modules
grunt-contrib-uglify/node_modules
grunt-contrib-watch/node_modules
grunt-legacy-log-utils
grunt-legacy-log
grunt-legacy-util
gzip-size
has-ansi
has-color
hawk
hoek
hooker
http-signature
iconv-lite
encodings
generation
test
.npmignore
.travis.yml
LICENSE
README.md
index.js
package.json
inherits
ip-regex
is-buffer
isarray
js-yaml
json-stringify-safe
jsonify
kind-of
lazy-cache
less
lodash
longest
lru-cache
maxmin
mime-types
mime
minimatch
minimist
mkdirp
natives
node-uuid
nopt
noptify
oauth-sign
object-assign
pako
pretty-bytes
process-nextick-args
psl
punycode
qs
readable-stream
repeat-string
request
right-align
rimraf
safe-buffer
sigmund
sntp
source-map
string_decoder
stringstream
strip-ansi
supports-color
tape
tiny-lr-fork
tough-cookie
tunnel-agent
typedarray
uglify-js
uglify-to-browserify
underscore.string
underscore
util-deprecate
which
window-size
wordwrap
yargs
zlib-browserify
pwa
.gitignore
404.html
ChengKeJ.github.io.iml
Graph Bed.md
Gruntfile.js
LICENSE
README.md
_config.yml
about.html
chengkej.io.iml
codecov.yml
feed.xml
index.html
offline.html
package-lock.json
package.json
sw.js
tags.html
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

iconv-lite - pure javascript character encoding conversion

Build Status

Features

  • Pure javascript. Doesn't need native code compilation.
  • Easy API.
  • Works on Windows and in sandboxed environments like Cloud9.
  • Encoding is much faster than node-iconv (see below for performance comparison).

Usage

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

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

// Convert from 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 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             iconv@1.2.4   iconv-lite@0.2.4 
----------------------------------------------------------
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 git@github.com: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).
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/ckjcode/ckjcode.git
git@gitee.com:ckjcode/ckjcode.git
ckjcode
ckjcode
ckjcode
master

搜索帮助