+15
-16
@@ -9,5 +9,6 @@ (function(global) { | ||
| var csv = require('csv'); | ||
| var Iconv = require('iconv').Iconv; | ||
| var Iconv = require('iconv-lite'); | ||
| var conv = null; | ||
| var _ = require('lodash'); | ||
| var app = { | ||
@@ -32,14 +33,9 @@ debug : false, | ||
| if( _.isString( option.charset ) && option.charset !== '' ) { | ||
| if( /^shift_jis$/i.test(option.charset) || | ||
| /^shift.jis$/i.test( option.charset ) || | ||
| /^cp932$/.test( option.charset ) ) { | ||
| conv = new Iconv(option.charset,'utf-8'); | ||
| } else if( /^utf-8$/i.test(option.charset) ) { | ||
| conv = null; | ||
| } else { | ||
| conv = new Iconv('cp932','utf-8'); | ||
| } | ||
| this.charset = option.charset; | ||
| if( this.debug ) console.log( 'override charset setting.' ); | ||
| } | ||
| } catch(e) { | ||
| console.log("faild.iconv charset setting."); | ||
| if( this.debug ) { | ||
| console.log("default charset setting."); | ||
| } | ||
| } | ||
@@ -150,2 +146,4 @@ | ||
| _dumpCsv: function ( path ) { | ||
| var charset = this.charset; | ||
| var promise = new Promise( function ( resolve, reject ) { | ||
@@ -156,7 +154,8 @@ var json_array = []; | ||
| var buf; | ||
| if( conv !== null ) { | ||
| buf = conv.convert( _buf ); | ||
| } else { | ||
| buf = _buf; | ||
| } | ||
| //console.log( charset ); | ||
| //console.log( _buf ); | ||
| buf = Iconv.decode( _buf, charset ); | ||
| if( app.debug ) console.log( 'CSV Loading:' + path + ' *=-'); | ||
@@ -163,0 +162,0 @@ csv.parse(buf.toString(),{comment:'#'}, function(err, data) { |
+2
-2
| { | ||
| "name": "csv2jsonic", | ||
| "version": "1.0.2", | ||
| "version": "1.0.3", | ||
| "description": "This module returns the CSV file in Json file or object.", | ||
@@ -24,3 +24,3 @@ "author": "Jun Fujimura <sv.junic@gmail.com> (http://sv.junic.jp)", | ||
| "fs": "0.0.2", | ||
| "iconv": "^2.1.6", | ||
| "iconv-lite": "^0.4.10", | ||
| "lodash": "^3.3.0", | ||
@@ -27,0 +27,0 @@ "mocha": "^2.2.5", |
19320
-1.1%371
-1.59%+ Added
+ Added
- Removed
- Removed
- Removed