Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

csvtojson

Package Overview
Dependencies
Maintainers
1
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csvtojson - npm Package Compare versions

Comparing version 0.5.5 to 0.5.6

test/data/dataWithWhiteSpace

83

libs/core/utils.js

@@ -45,24 +45,69 @@

var e=rowArr[i];
if (isToogleQuote(e, quote)) { //if current col has odd quotes, switch quote status
if (inquote) { //if currently in open quote status, close it and output data
quoteBuff += delimiter;
quoteBuff += twoDoubleQuote(e.substr(0, e.length - 1), quote);
row.push(trim ? quoteBuff.trim() : quoteBuff);
quoteBuff = '';
} else { // currently not in open quote status, open it
quoteBuff += twoDoubleQuote(e.substring(1), quote);
if (!inquote && trim){
e=e.trim();
}
var len=e.length;
if (!inquote){
if (e[0] === quote){ //possible open
e=e.substr(1);
len-=1;
if (e[0]!==quote){ // open quote
if (e[len-1] === quote){ // possible close
if (e[len-2]!==quote){ // close quote
e=e.substring(0,len-1);
e=twoDoubleQuote(e,quote);
row.push(e);
continue;
}
}
inquote=true;
quoteBuff+=e;
continue;
}else{
row.push(e);
continue;
}
}else{
row.push(e);
continue;
}
inquote = !inquote;
} else if (inquote) { // if current col has even quotes, do not switch quote status
//if current status is in quote, add to buffer wait to close
quoteBuff += delimiter + twoDoubleQuote(e, quote);
} else { // if current status is not in quote, out put data
if (e.indexOf(quote) === 0 && e[e.length - 1] === quote) { //if current col contain full quote segment,remove quote first
e = e.substring(1, e.length - 1);
}else{ //previous quote not closed
if (e[len-1] === quote && e[len-2] !==quote){ //close double quote
inquote=false;
e=e.substr(0,len-1);
quoteBuff+=delimiter+e;
quoteBuf=twoDoubleQuote(quoteBuff,quote);
if (trim){
quoteBuff=quoteBuff.trimRight();
}
row.push(quoteBuff);
quoteBuff="";
}else{
quoteBuff+=delimiter+e;
}
if (trim) {
e = e.trim();
}
row.push(twoDoubleQuote(e, quote));
}
// if (isToogleQuote(e, quote)) { //if current col has odd quotes, switch quote status
// if (inquote) { //if currently in open quote status, close it and output data
// quoteBuff += delimiter;
// quoteBuff += twoDoubleQuote(e.substr(0, e.length - 1), quote);
// row.push(trim ? quoteBuff.trim() : quoteBuff);
// quoteBuff = '';
// } else { // currently not in open quote status, open it
// quoteBuff += twoDoubleQuote(e.substring(1), quote);
// }
// inquote = !inquote;
// } else if (inquote) { // if current col has even quotes, do not switch quote status
// //if current status is in quote, add to buffer wait to close
// quoteBuff += delimiter + twoDoubleQuote(e, quote);
// } else { // if current status is not in quote, out put data
// if (trim) {
// e = e.trim();
// }
// if (e.indexOf(quote) === 0 && e[e.length - 1] === quote) { //if current col contain full quote segment,remove quote first
// e = e.substring(1, e.length - 1);
// }
// row.push(twoDoubleQuote(e, quote));
// }
}

@@ -69,0 +114,0 @@ return row;

@@ -21,3 +21,3 @@ {

],
"version": "0.5.5",
"version": "0.5.6",
"keywords": [

@@ -36,8 +36,3 @@ "csv",

},
"license": [
{
"type": "MIT",
"url": "https://github.com/Keyang/node-csvtojson/blob/master/LICENSE"
}
],
"license": "MIT",
"engines": {

@@ -44,0 +39,0 @@ "node": ">=0.10"

@@ -69,3 +69,3 @@ var Converter = require("../libs/core/Converter.js");

assert(result[0].col1 === "\"Mini. Sectt");
assert(result[3].col2 === "125001,fenvkdsf");
assert.equal(result[3].col2 , "125001,fenvkdsf");
// console.log(result);

@@ -140,4 +140,4 @@ done();

csvConverter.fromString(data, function (err, jsonObj) {
//console.log(jsonObj);
assert(jsonObj[0].TIMESTAMP === '13954264"22', JSON.stringify(jsonObj[0].TIMESTAMP));
assert(jsonObj[1].TIMESTAMP === 'abc, def, ccc', JSON.stringify(jsonObj[1].TIMESTAMP));

@@ -144,0 +144,0 @@ done();

@@ -142,2 +142,15 @@ var Converter = require("../libs/core/Converter.js");

});
it ("should stripe out whitespaces if trim is true",function(done){
var testData = __dirname + "/data/dataWithWhiteSpace";
var rs = fs.createReadStream(testData);
var conv=new Converter({trim:true});
conv.on("end_parsed",function(res){
// console.log(res);
assert.equal(res[0]["Column 1"],"Column1Row1");
assert.equal(res[0]["Column 2"],"Column2Row1");
done();
});
rs.pipe(conv);
})

@@ -144,0 +157,0 @@ // it ("should convert big csv",function(done){

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc