Comparing version 0.1.1 to 0.1.2
37
index.js
@@ -10,3 +10,12 @@ var Iconv, iconvLite = require("iconv-lite");; | ||
function convert(str, to, from){ | ||
/** | ||
* Convert encoding of an UTF-8 string or a buffer | ||
* | ||
* @param {String|Buffer} str String to be converted | ||
* @param {String} to Encoding to be converted to | ||
* @param {String} [from="UTF-8"] Encoding to be converted from | ||
* @param {Boolean} useLite If set to ture, force to use iconvLite | ||
* @return {Buffer} Encoded string | ||
*/ | ||
function convert(str, to, from, useLite){ | ||
from = checkEncoding(from || "UTF-8"); | ||
@@ -25,7 +34,5 @@ to = checkEncoding(to || "UTF-8"); | ||
}else{ | ||
if(Iconv){ | ||
console.log(1); | ||
if(Iconv && !useLite){ | ||
result = convertIconv(str, to, from); | ||
}else{ | ||
console.log(2); | ||
result = convertIconvLite(str, to, from); | ||
@@ -42,2 +49,10 @@ } | ||
/** | ||
* Convert encoding of astring with node-iconv (if available) | ||
* | ||
* @param {String|Buffer} str String to be converted | ||
* @param {String} to Encoding to be converted to | ||
* @param {String} [from="UTF-8"] Encoding to be converted from | ||
* @return {Buffer} Encoded string | ||
*/ | ||
function convertIconv(str, to, from){ | ||
@@ -50,2 +65,10 @@ var response; | ||
/** | ||
* Convert encoding of astring with iconv-lite (if node-iconv is not available) | ||
* | ||
* @param {String|Buffer} str String to be converted | ||
* @param {String} to Encoding to be converted to | ||
* @param {String} [from="UTF-8"] Encoding to be converted from | ||
* @return {Buffer} Encoded string | ||
*/ | ||
function convertIconvLite(str, to, from){ | ||
@@ -61,2 +84,8 @@ if(to == "UTF-8"){ | ||
/** | ||
* Converts charset name if needed | ||
* | ||
* @param {String} name Character set | ||
* @return {String} Character set name | ||
*/ | ||
function checkEncoding(name){ | ||
@@ -63,0 +92,0 @@ name = (name || "").toString().trim(). |
{ | ||
"name": "encoding", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Remove accents from international characters", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "nodeunit test.js" | ||
}, | ||
@@ -17,3 +17,6 @@ "repository": "git://github.com/andris9/encoding.git", | ||
"iconv": "*" | ||
}, | ||
"devDependencies":{ | ||
"nodeunit": "*" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
5201
5
110
2
1