I've got an issue with empty values inside quotes, here is an example:
const csv = require('csvtojson');
const string = 'a|^^|^b^';
csv({
delimiter: '|',
quote: '^',
noheader: true,
})
.fromString(string)
.then((jsonObj) => {
console.log(jsonObj);
});
prints
[ { field1: 'a', field2: '^^', field3: 'b' } ]
while my expected result is:
[ { field1: 'a', field2: '', field3: 'b' } ]
took a look at the code, my guess is that isQuoteOpen condition should be fixed to check if everything value consists of are quotes, i.e. smth like:
str[0] === quote && (str[1] === quote || str.length === 2)
therefore smth like:
RowSplit.prototype.isQuoteOpen = function (str) {
var quote = this.quote;
var escape = this.escape;
return str[0] === quote && ((str[1] === quote || str.length === 2) || str[1] !== quote ||
str[1] === escape && (str[2] === quote || str.length === 2));
};
do you agree? any chances to get if fixed any soon? I'd really appreciate it...
btw, if I strip down an original condition in that function, then looks like possible option for isQuoteOpen to be true is str[0] === quote && str[1] === escape && str.length === 2, how possible is that value consists of two chars when first is quote and another once is escape..? tried few inputs:
- for 'a|^$|b^' I get [ { field1: 'a', field2: '$|^b' } ]
- for 'a|^$' I get an unclosed_quote exception
I've got an issue with empty values inside quotes, here is an example:
prints
[ { field1: 'a', field2: '^^', field3: 'b' } ]while my expected result is:
[ { field1: 'a', field2: '', field3: 'b' } ]took a look at the code, my guess is that isQuoteOpen condition should be fixed to check if everything value consists of are quotes, i.e. smth like:
str[0] === quote && (str[1] === quote || str.length === 2)therefore smth like:
do you agree? any chances to get if fixed any soon? I'd really appreciate it...
btw, if I strip down an original condition in that function, then looks like possible option for isQuoteOpen to be true is
str[0] === quote && str[1] === escape && str.length === 2, how possible is that value consists of two chars when first is quote and another once is escape..? tried few inputs: