[Pkg-javascript-commits] [node-iconv-lite] 06/83: Updated information after adding gbk encoding, added aliases 'encode' and 'decode'

matthew pideil mpideil-guest at moszumanska.debian.org
Tue Apr 1 19:56:45 UTC 2014


This is an automated email from the git hooks/post-receive script.

mpideil-guest pushed a commit to branch master
in repository node-iconv-lite.

commit 25e036a5d1bc2659123cdb4c94877d8bf1133c0d
Author: Alexander Shtuchkin <ashtuchkin at gmail.com>
Date:   Wed Nov 23 16:54:21 2011 +0400

    Updated information after adding gbk encoding, added aliases 'encode' and 'decode'
---
 README.md         | 10 +++++++---
 index.js          |  4 ++++
 package.json      |  7 +++++--
 test/gbk-test.js  |  2 +-
 test/main-test.js |  4 ++++
 5 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/README.md b/README.md
index fd48cbd..df92e23 100644
--- a/README.md
+++ b/README.md
@@ -6,19 +6,23 @@ iconv-lite - native javascript conversion between character encodings.
     var iconv = require('iconv-lite');
     
     // Convert from an encoded buffer to string.
-    str = icon.fromEncoding(buf, 'win-1251');
+    str = iconv.fromEncoding(buf, 'win-1251');
+    // Or
+    str = iconv.decode(buf, 'win-1251');
     
     // Convert from string to an encoded buffer.
     buf = iconv.toEncoding("Sample input string", 'win-1251');
-
+    // Or
+    buf = iconv.encode("Sample input string", 'win-1251');
 
 ## Supported encodings
 
 Currently only a small part of encodings supported:
 
 *   All node.js native encodings: 'utf8', 'ucs2', 'ascii', 'binary', 'base64'.
-*   'latin1'
+*   Base encodings: 'latin1'
 *   Cyrillic encodings: 'windows-1251', 'koi8-r', 'iso 8859-5'.
+*   Simplified chinese: 'gbk', 'gb2313'.
 
 Other encodings are easy to add, see the source. Please, participate.
 
diff --git a/index.js b/index.js
index 5f03f5a..352104e 100644
--- a/index.js
+++ b/index.js
@@ -176,6 +176,10 @@ module.exports = iconv = {
     },
 }
 
+// Add aliases to convert functions
+iconv.encode = iconv.toEncoding;
+iconv.decode = iconv.fromEncoding;
+
 // Load other encodings from files in /encodings dir.
 var encodingsDir = __dirname+"/encodings/",
     fs = require('fs');
diff --git a/package.json b/package.json
index 4222638..32b3c69 100644
--- a/package.json
+++ b/package.json
@@ -1,10 +1,13 @@
 {
     "name": "iconv-lite",
     "description": "Convert character encodings in pure javascript.",
-    "version": "0.1.0",
+    "version": "0.1.1",
     
     "keywords": ["iconv", "convert", "charset"],
     "author": "Alexander Shtuchkin <ashtuchkin at gmail.com>",
+    "contributors": [
+        "jenkinv (https://github.com/jenkinv)"
+    ],
     
     "homepage": "http://github.com/ashtuchkin/node-iconv/",
     "repository": {
@@ -16,6 +19,6 @@
     },
     "devDependencies": {
         "vows": "",
-        "iconv": "",
+        "iconv": ""
     }
 }
diff --git a/test/gbk-test.js b/test/gbk-test.js
index a40b4cc..6a4933c 100644
--- a/test/gbk-test.js
+++ b/test/gbk-test.js
@@ -22,7 +22,7 @@ vows.describe("GBK tests").addBatch({
         assert.strictEqual(iconv.fromEncoding(testStringGBKBuffer, "GB2312"), testString);
     },
     "GBK file read decoded,compare with iconv result": function() {
-        var contentBuffer = fs.readFileSync("gbkFile.txt");
+        var contentBuffer = fs.readFileSync(__dirname+"/gbkFile.txt");
         var str = iconv.fromEncoding(contentBuffer, "GBK");
         var iconvc = new (require('iconv').Iconv)('GBK','utf8');
         assert.strictEqual(iconvc.convert(contentBuffer).toString(), str);
diff --git a/test/main-test.js b/test/main-test.js
index 994b7bb..072c599 100644
--- a/test/main-test.js
+++ b/test/main-test.js
@@ -48,4 +48,8 @@ vows.describe("Generic UTF8-UCS2 tests").addBatch({
         assert.strictEqual(iconv.fromEncoding(10, "utf8"), "10");
         assert.strictEqual(iconv.fromEncoding(undefined, "utf8"), "");
     },
+    "Aliases encode and decode work the same as toEncoding and fromEncoding": function() {
+        assert.strictEqual(iconv.toEncoding(testString, "latin1").toString("binary"), iconv.encode(testString, "latin1").toString("binary"));
+        assert.strictEqual(iconv.fromEncoding(testStringLatin1, "latin1"), iconv.decode(testStringLatin1, "latin1"));
+    },
 }).export(module)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-iconv-lite.git



More information about the Pkg-javascript-commits mailing list