From 0dd34990a067aa6f3c5d9c84e53cbfc1a865f306 Mon Sep 17 00:00:00 2001 From: Pradeep Mishra Date: Tue, 17 Jan 2017 23:51:56 +0530 Subject: [PATCH] bugfix --- index.js | 6 +++--- package.json | 2 +- test/test.json | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 test/test.json diff --git a/index.js b/index.js index 1e994af..595d404 100644 --- a/index.js +++ b/index.js @@ -218,6 +218,7 @@ function toCSV(data, opts){ replaceNewLinePattern = new RegExp('\n|\r|' + opts.delimiter, 'g'); } + for(var i = 0; i < bigArrayLen; i++){ row = [ ]; for(var j = 0; j < keys.length; j++){ @@ -236,7 +237,6 @@ function toCSV(data, opts){ return csvData; } - function _toCsv(data, table, parent, row, opt){ if(_dataType(data) === 'undefined'){ return _putData('', table, parent, row, opt); @@ -317,8 +317,8 @@ function _getHeaders(headerType, table, opt){ function _getBigArrayLength(table){ var len = 0; Object.keys(table).forEach(function(item){ - if(Array.isArray(table[item]) && item.length > len){ - len = item.length; + if(Array.isArray(table[item]) && table[item].length > len){ + len = table[item].length; } }); return len; diff --git a/package.json b/package.json index b90c80c..b4dc716 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "csvjson", "description": "convert csv to json and json to csv", - "version": "4.0.0", + "version": "4.0.1", "main": "./index.js", "author": { "name": "Pradeep Mishra" diff --git a/test/test.json b/test/test.json new file mode 100644 index 0000000..dc85cf8 --- /dev/null +++ b/test/test.json @@ -0,0 +1,22 @@ +{ + "glossary": { + "title": "example glossary", + "GlossDiv": { + "title": "S", + "GlossList": { + "GlossEntry": { + "ID": "SGML", + "SortAs": "SGML", + "GlossTerm": "Standard Generalized Markup Language", + "Acronym": "SGML", + "Abbrev": "ISO 8879:1986", + "GlossDef": { + "para": "A meta-markup language, used to create markup languages such as DocBook.", + "GlossSeeAlso": ["GML", "XML"] + }, + "GlossSee": "markup" + } + } + } + } +} \ No newline at end of file