csv-string
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -126,3 +126,3 @@ 'use strict'; | ||
endingLine = input.indexOf('\n', startingIndex); | ||
//console.log('buffer', input.slice(startingIndex)); | ||
//console.log('buffer', '('+input.slice(startingIndex)+')'); | ||
//console.log('startingIndex:', startingIndex); | ||
@@ -155,17 +155,45 @@ //console.log('endingIndex:', endingIndex); | ||
if (searchIndex === -1) { | ||
searchIndex = input.slice(startingIndex).search(/[^\"]\"\"\"(?!\")/) + 2; | ||
var index = 1 | ||
while (1) { | ||
var searchIndex = input.slice(startingIndex + index).search(/\"\"/); | ||
if (searchIndex === -1) { | ||
break; | ||
} | ||
index += searchIndex + 2; | ||
} | ||
searchIndex = input.slice(startingIndex + index).indexOf('"') | ||
if (searchIndex === -1) { | ||
} | ||
else { | ||
searchIndex = index + searchIndex; | ||
} | ||
} | ||
fields.push(input.slice(startingIndex, startingIndex + searchIndex + 1).replace(/\"\"/g, '"')); | ||
else { | ||
searchIndex += 1 | ||
} | ||
//console.log('FOUND', '['+input.slice(startingIndex, startingIndex + searchIndex)+']'); | ||
fields.push(input.slice(startingIndex, startingIndex + searchIndex).replace(/\"\"/g, '"')); | ||
startingIndex += searchIndex + 1; | ||
searchIndex = input.slice(startingIndex).indexOf(sep); | ||
//console.log('REST', '['+input.slice(startingIndex)+']'); | ||
searchIndex = input.slice(startingIndex).search(/\S/); // ignore the "résidus" | ||
if (searchIndex !== -1) { | ||
startingIndex += searchIndex + sep.length; | ||
//console.log('résidus', '['+input.slice(startingIndex,startingIndex + searchIndex + 1)+']') | ||
var searchIndex1 = input.slice(startingIndex,startingIndex + searchIndex).search(/\n/) | ||
if (searchIndex1 !== -1) { | ||
//console.log('fin') | ||
reminderIndex = startingIndex + searchIndex1 + 1; | ||
callback(fields); | ||
return reminderIndex; | ||
} | ||
var searchIndex2 = input.slice(startingIndex,startingIndex + searchIndex + 1).indexOf(sep) | ||
if (searchIndex2 !== -1) { | ||
//console.log('blank') | ||
startingIndex += searchIndex2 + 1; | ||
} | ||
} | ||
searchIndex = input.slice(startingIndex).search(/\S/); | ||
if (searchIndex !== -1) { | ||
startingIndex += searchIndex; | ||
} | ||
} | ||
} | ||
else if (endingLine >= 0 && endingLine < endingIndex) { | ||
//console.log('E : token" =>', token); | ||
if (input.charAt(endingLine - 1) === '\r') { | ||
@@ -189,3 +217,3 @@ fields.push(input.slice(startingIndex, endingLine - 1)); | ||
//console.log('B : token =>', token); | ||
// console.log(endingLine, '<', endingIndex); | ||
//console.log(endingLine, '<', endingIndex); | ||
fields.push(input.slice(startingIndex, endingIndex)); | ||
@@ -192,0 +220,0 @@ startingIndex = endingIndex + 1; |
{ | ||
"name": "csv-string", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"author": "Nicolas Thouvenin <nthouvenin@gmail.com>", | ||
@@ -5,0 +5,0 @@ "contributors": [ |
12
t.js
@@ -6,6 +6,14 @@ var CSV = require('./lib/csv.js'), input; | ||
//input = 'a ,\tb , c\n' | ||
//input = "a,\"b,b\"\"b,b\"\"b\",c\r\nd,e,f" | ||
input = 'a,b,"c\n' | ||
input = "a,\"b,b\"\"b,b\"\"b\",c\r\nd,e,f" | ||
//input = 'a,b,"c\n' | ||
//input = 'a,"b1,""b2""b3,b4""""",0.9040,/,string,2' | ||
input = "a,\"b1,\"\"b2\"\"b3,b4\"\"\"\"b5\nb6\"\r\nc,d" | ||
input = "a,\"b1,\"\"b2\"\"b3,b4\"\"\"\"b5\nb6\" \t\r\nc,d" | ||
input = "a,\"b1,\"\"b2\"\"b3,b4\"\"\"\"b5\nb6\" ,c\r\n,d" | ||
var obj = CSV.fetch(input); | ||
console.log(input, obj) | ||
//a,"b1,""b2""b3,b4""""b5\b6"\r\nc,d | ||
@@ -218,2 +218,36 @@ 'use strict'; | ||
); | ||
describe('#9 fetch()', function () { | ||
it('should', function () { | ||
var obj = CSV.fetch('a,"b1,""b2""b3,b4""""",c\r\nd,e,f'); | ||
obj.should.eql(['a', 'b1,"b2"b3,b4""', 'c']); | ||
} | ||
); | ||
} | ||
); | ||
describe('#10 fetch()', function () { | ||
it('should', function () { | ||
var obj = CSV.fetch("a,\"b1,\"\"b2\"\"b3,b4\"\"\"\"b5\r\nb6\"\r\nc,d"); | ||
obj.should.eql(['a', "b1,\"b2\"b3,b4\"\"b5\r\nb6"]); | ||
} | ||
); | ||
} | ||
); | ||
describe('#10bis fetch()', function () { | ||
it('should', function () { | ||
var obj = CSV.fetch("a,\"b1,\"\"b2\"\"b3,b4\"\"\"\"b5\nb6\" \t\r\nc,d"); | ||
obj.should.eql(['a', "b1,\"b2\"b3,b4\"\"b5\nb6"]); | ||
} | ||
); | ||
} | ||
); | ||
describe('#10ter fetch()', function () { | ||
it('should', function () { | ||
var obj = CSV.fetch("a,\"b1,\"\"b2\"\"b3,b4\"\"\"\"b5\nb6\" ,c\r\n,d"); | ||
obj.should.eql(['a', "b1,\"b2\"b3,b4\"\"b5\nb6", 'c']); | ||
} | ||
); | ||
} | ||
); | ||
describe('#1 forEach()', function () { | ||
@@ -220,0 +254,0 @@ it('should', function() { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22582
575