Comparing version 0.0.1 to 0.0.2
@@ -11,3 +11,3 @@ module.exports = function(list, options, cb){ | ||
headers = [], | ||
row, key, i, idx; | ||
row, key, i, idx, field; | ||
@@ -26,10 +26,13 @@ | ||
row = []; | ||
debugger; | ||
for (key in obj){ | ||
if (obj.hasOwnProperty(key)){ | ||
idx = headers.indexOf(key); | ||
field = obj[key]; | ||
if (idx===-1){ | ||
idx = headers.push(key) - 1; | ||
} | ||
row[(idx)] = obj[key]; // push and indexOf returns index+1, idx is idx-1 | ||
if (typeof field === "string"){ | ||
field = '"' + field + ''; | ||
} | ||
row[(idx)] = field; // push and indexOf returns index+1, idx is idx-1 | ||
} | ||
@@ -59,2 +62,2 @@ } | ||
return cb(null, csv); | ||
}; | ||
}; |
@@ -5,7 +5,7 @@ { | ||
"description": "Simple node module for converting a json array [ {}, {} ] to CSV", | ||
"version": "0.0.1", | ||
"homepage": "github.com/cianclarke/jcsvsv", | ||
"version": "0.0.2", | ||
"homepage": "github.com/cianclarke/json2csv", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:cianclarke/jcsv.git" | ||
"url": "git@github.com:cianclarke/json2csv.git" | ||
}, | ||
@@ -12,0 +12,0 @@ "main": "./index.js", |
@@ -10,3 +10,11 @@ [ | ||
"c" : 5 | ||
}, | ||
{ | ||
"a" : 6, | ||
"b" : 7, | ||
"c" : 8, | ||
"d" : true, | ||
"e" : "string", | ||
"f" : { "a" : 1, "b" : 2} | ||
} | ||
] | ||
] |
@@ -8,8 +8,6 @@ var jcsv = require ('../index.js'), | ||
assert.ok(typeof res === "string"); | ||
var resStr = "a,b,c;\n1,2,;\n3,4,5;\n"; | ||
assert.ok(res === resStr); | ||
console.log(res); | ||
var resStr = ['a,b,c,d,e,f;', '1,2,,,,;', '3,4,5,,,;', '6,7,8,true,"string,[object Object];']; | ||
assert.ok(res === resStr.join('\n') + '\n'); | ||
console.log("Tests passed ok!"); | ||
}); | ||
}); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
3351
81
1