[Pkg-javascript-commits] [node-iconv-lite] 68/83: allow checking support for specific encoding

matthew pideil mpideil-guest at moszumanska.debian.org
Tue Apr 1 19:56:52 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 548ea7e2d9cc2535bffa8f694157b2207aee8340
Author: mscdex <mscdex at mscdex.net>
Date:   Fri Jul 12 08:10:18 2013 -0400

    allow checking support for specific encoding
---
 index.js | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/index.js b/index.js
index f8f904d..a55691b 100644
--- a/index.js
+++ b/index.js
@@ -1,3 +1,4 @@
+var RE_SPACEDASH = /[- ]/g;
 // Module exports
 var iconv = module.exports = {
     toEncoding: function(str, encoding) {
@@ -6,6 +7,11 @@ var iconv = module.exports = {
     fromEncoding: function(buf, encoding) {
         return iconv.getCodec(encoding).fromEncoding(buf);
     },
+    encodingExists: function(enc) {
+        loadEncodings();
+        enc = enc.replace(RE_SPACEDASH, "").toLowerCase();
+        return (iconv.encodings[enc] !== undefined);
+    },
     
     defaultCharUnicode: '�',
     defaultCharSingleByte: '?',
@@ -14,17 +20,12 @@ var iconv = module.exports = {
     
     // Get correct codec for given encoding.
     getCodec: function(encoding) {
-        if (!iconv.encodingsLoaded) {
-            applyEncodings(require('./encodings/singlebyte'));
-            applyEncodings(require('./encodings/gbk'));
-            applyEncodings(require('./encodings/big5'));
-            iconv.encodingsLoaded = true;
-        }
+        loadEncodings();
         var enc = encoding || "utf8";
         var codecOptions = undefined;
         while (1) {
             if (getType(enc) === "String")
-                enc = enc.replace(/[- ]/g, "").toLowerCase();
+                enc = enc.replace(RE_SPACEDASH, "").toLowerCase();
             var codec = iconv.encodings[enc];
             var type = getType(codec);
             if (type === "String") {
@@ -195,9 +196,17 @@ iconv.encode = iconv.toEncoding;
 iconv.decode = iconv.fromEncoding;
 
 // Load other encodings manually from files in /encodings dir.
-function applyEncodings(encodings) {
-    for (var key in encodings)
-        iconv.encodings[key] = encodings[key]
+function loadEncodings() {
+    if (!iconv.encodingsLoaded) {
+        [ require('./encodings/singlebyte'),
+          require('./encodings/gbk'),
+          require('./encodings/big5')
+        ].forEach(function(encodings) {
+            for (var key in encodings)
+                iconv.encodings[key] = encodings[key]
+        });
+        iconv.encodingsLoaded = true;
+    }
 }
 
 

-- 
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