You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

encoding

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.11 to 0.1.12

.travis.yml

49

lib/encoding.js
'use strict';
var iconvLite = require('iconv-lite');
var Iconv;
// Load Iconv from an external file to be able to disable Iconv for webpack
// Add /\/iconv-loader$/ to webpack.IgnorePlugin to ignore it
var Iconv = require('./iconv-loader');
try {
// this is to fool browserify so it doesn't try (in vain) to install iconv.
var iconv_package = 'iconv';
Iconv = require(iconv_package).Iconv;
} catch (E) {
// node-iconv not present
}
// Expose to the world

@@ -33,3 +27,3 @@ module.exports.convert = convert;

if (from != 'UTF-8' && typeof str == 'string') {
if (from !== 'UTF-8' && typeof str === 'string') {
str = new Buffer(str, 'binary');

@@ -44,17 +38,8 @@ }

}
} else {
if (Iconv && !useLite) {
} else if (Iconv && !useLite) {
try {
result = convertIconv(str, to, from);
} catch (E) {
console.error(E);
try {
result = convertIconv(str, to, from);
} catch (E) {
console.error(E);
try {
result = convertIconvLite(str, to, from);
} catch (E) {
console.error(E);
result = str;
}
}
} else {
try {
result = convertIconvLite(str, to, from);

@@ -66,5 +51,13 @@ } catch (E) {

}
} else {
try {
result = convertIconvLite(str, to, from);
} catch (E) {
console.error(E);
result = str;
}
}
if (typeof result == 'string') {
if (typeof result === 'string') {
result = new Buffer(result, 'utf-8');

@@ -100,5 +93,5 @@ }

function convertIconvLite(str, to, from) {
if (to == 'UTF-8') {
if (to === 'UTF-8') {
return iconvLite.decode(str, from);
} else if (from == 'UTF-8') {
} else if (from === 'UTF-8') {
return iconvLite.encode(str, to);

@@ -124,2 +117,2 @@ } else {

toUpperCase();
}
}
{
"name": "encoding",
"version": "0.1.11",
"version": "0.1.12",
"description": "Convert encodings, uses iconv by default and fallbacks to iconv-lite if needed",

@@ -13,7 +13,8 @@ "main": "lib/encoding.js",

"dependencies": {
"iconv-lite": "~0.4.4"
"iconv-lite": "~0.4.13"
},
"devDependencies": {
"nodeunit": "~0.8.1"
"iconv": "~2.1.11",
"nodeunit": "~0.9.1"
}
}

@@ -6,2 +6,5 @@ # Encoding

[![Build Status](https://secure.travis-ci.org/andris9/encoding.svg)](http://travis-ci.org/andris9/Nodemailer)
[![npm version](https://badge.fury.io/js/encoding.svg)](http://badge.fury.io/js/encoding)
## Install

@@ -50,2 +53,2 @@

**MIT**
**MIT**
'use strict';
var Iconv = require('../lib/iconv-loader');
var encoding = require('../lib/encoding');

@@ -7,3 +8,8 @@

'From UTF-8 to Latin_1': function(test) {
'Iconv is available': function (test) {
test.ok(Iconv);
test.done();
},
'From UTF-8 to Latin_1 with Iconv': function (test) {
var input = 'ÕÄÖÜ',

@@ -15,3 +21,3 @@ expected = new Buffer([0xd5, 0xc4, 0xd6, 0xdc]);

'From Latin_1 to UTF-8': function(test) {
'From Latin_1 to UTF-8 with Iconv': function (test) {
var input = new Buffer([0xd5, 0xc4, 0xd6, 0xdc]),

@@ -23,3 +29,3 @@ expected = 'ÕÄÖÜ';

'From UTF-8 to UTF-8': function(test) {
'From UTF-8 to UTF-8 with Iconv': function (test) {
var input = 'ÕÄÖÜ',

@@ -31,3 +37,3 @@ expected = new Buffer('ÕÄÖÜ');

'From Latin_13 to Latin_15': function(test) {
'From Latin_13 to Latin_15 with Iconv': function (test) {
var input = new Buffer([0xd5, 0xc4, 0xd6, 0xdc, 0xd0]),

@@ -39,3 +45,31 @@ expected = new Buffer([0xd5, 0xc4, 0xd6, 0xdc, 0xA6]);

'From Latin_13 to Latin_15 lite': function(test) {
'From ISO-2022-JP to UTF-8 with Iconv': function (test) {
var input = new Buffer('GyRCM1g5OzU7PVEwdzgmPSQ4IUYkMnFKczlwGyhC', 'base64'),
expected = new Buffer('5a2m5qCh5oqA6KGT5ZOh56CU5L+u5qSc6KiO5Lya5aCx5ZGK', 'base64');
test.deepEqual(encoding.convert(input, 'utf-8', 'ISO-2022-JP'), expected);
test.done();
},
'From UTF-8 to Latin_1 with iconv-lite': function (test) {
var input = 'ÕÄÖÜ',
expected = new Buffer([0xd5, 0xc4, 0xd6, 0xdc]);
test.deepEqual(encoding.convert(input, 'latin1', false, true), expected);
test.done();
},
'From Latin_1 to UTF-8 with iconv-lite': function (test) {
var input = new Buffer([0xd5, 0xc4, 0xd6, 0xdc]),
expected = 'ÕÄÖÜ';
test.deepEqual(encoding.convert(input, 'utf-8', 'latin1', true).toString(), expected);
test.done();
},
'From UTF-8 to UTF-8 with iconv-lite': function (test) {
var input = 'ÕÄÖÜ',
expected = new Buffer('ÕÄÖÜ');
test.deepEqual(encoding.convert(input, 'utf-8', 'utf-8', true), expected);
test.done();
},
'From Latin_13 to Latin_15 with iconv-lite': function (test) {
var input = new Buffer([0xd5, 0xc4, 0xd6, 0xdc, 0xd0]),

@@ -45,10 +79,3 @@ expected = new Buffer([0xd5, 0xc4, 0xd6, 0xdc, 0xA6]);

test.done();
},
'From ISO-2022-JP to UTF-8': function(test) {
var input = new Buffer('GyRCM1g5OzU7PVEwdzgmPSQ4IUYkMnFKczlwGyhC', 'base64'),
expected = new Buffer('5a2m5qCh5oqA6KGT5ZOh56CU5L+u5qSc6KiO5Lya5aCx5ZGK', 'base64');
test.deepEqual(encoding.convert(input, 'utf-8', 'ISO-2022-JP'), expected);
test.done();
}
};
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc