csv-string
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -123,3 +123,10 @@ 'use strict'; | ||
} | ||
exports.readAll = function (input, sep, callback) { | ||
var csv = new Parser(input, sep); | ||
var rows = csv.File(); | ||
callback(rows); | ||
return csv.pointer; | ||
} | ||
exports.fetch = function (input, sep) { | ||
@@ -126,0 +133,0 @@ var output; |
'use strict'; | ||
/* | ||
file | ||
: row+ EOF | ||
; | ||
row | ||
@@ -38,2 +41,30 @@ : value (Comma value)* (LineBreak | EOF) | ||
Parser.prototype.File = function () { | ||
var files = [], row, eof, linepointer; | ||
while (1) { | ||
var t = this.pointer | ||
row = this.Row(); | ||
if (row.length > 0) { | ||
linepointer = t | ||
files.push(row); | ||
} | ||
else { | ||
if (linepointer && this.pointer !== this.input.length) { | ||
files.pop(); | ||
this.pointer = linepointer; | ||
} | ||
break; | ||
} | ||
eof = this.EOF(); | ||
if (eof) { | ||
if (linepointer && this.pointer !== this.input.length) { | ||
files.pop(); | ||
this.pointer = linepointer; | ||
} | ||
break; | ||
} | ||
} | ||
return files; | ||
} | ||
Parser.prototype.Row = function () { | ||
@@ -115,18 +146,17 @@ var value, comma, linebreak, eof, row = []; | ||
var searchIndex, index = 1; | ||
while (1) { | ||
searchIndex = this.input.slice(this.pointer + index).search('""'); | ||
while (1) { | ||
searchIndex = this.input.slice(this.pointer + index).search('"'); | ||
if (searchIndex === -1) { | ||
break; | ||
return; | ||
} | ||
index += searchIndex + 2; | ||
if (this.input.charAt(this.pointer + index + searchIndex + 1) === '"') { | ||
index += searchIndex + 2; | ||
continue; | ||
} | ||
else { | ||
var value = this.input.slice(this.pointer, this.pointer + index + searchIndex + 1); | ||
this.pointer += value.length; | ||
return value; | ||
} | ||
} | ||
searchIndex = this.input.slice(this.pointer + index).indexOf('"'); | ||
if (searchIndex === -1) { | ||
return | ||
} | ||
else { | ||
var value = this.input.slice(this.pointer, this.pointer + index + searchIndex + 1); | ||
this.pointer += value.length; | ||
return value; | ||
} | ||
} | ||
@@ -133,0 +163,0 @@ } |
{ | ||
"name": "csv-string", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"author": "Nicolas Thouvenin <nthouvenin@gmail.com>", | ||
@@ -5,0 +5,0 @@ "contributors": [ |
33
t.js
@@ -16,9 +16,36 @@ var CSV = require('./lib/csv.js'), input; | ||
input = '"a,a",,"c"' | ||
input = 'a,b,"c\n' | ||
var obj = CSV.fetch(input); | ||
console.log(input, obj) | ||
input = 'T,T,T\n1,2,3\na,"b' | ||
input = 'a,"Mon, 19 Dec 2011 18:56:59 +0000",c,d,e,f\r\na,"RT @dhofstet: ""If something is not documented, it\'s safe to assume it\'s either internal, deprecated or in \'private beta\' mode."" #nodejs",c,d,e,f' | ||
input = 'a,"b",c\r\na,"b""b",c' | ||
input = 'a,"b1,""b2""b3,b4""""",c\r\nd,e,f' | ||
input = 'a,https://si0.twimg.com/profile_i | ||
456}mages/1560906577/avatar_normal.png,c,d,e,f | ||
/* | ||
var r, s = 0, t = 0; | ||
r = CSV.read(input.slice(s), ',', function(x) {console.log(x)}) | ||
console.log('r:'+r, 's+'+s, 't:'+t, input.slice(s), 'X', input.slice(t)) | ||
t = s; | ||
s += r; | ||
r = CSV.read(input.slice(s), ',', function(x) {console.log(x)}) | ||
console.log('r:'+r, 's+'+s, 't:'+t, input.slice(s), 'X', input.slice(t)) | ||
t = s; | ||
s += r; | ||
r = CSV.read(input.slice(s), ',', function(x) {console.log(x)}) | ||
console.log('r:'+r, 's+'+s, 't:'+t, input.slice(s), 'X', input.slice(t)) | ||
t = s | ||
s += r | ||
r = CSV.read(input.slice(s), ',', function(x) {console.log(x)}) | ||
console.log('r:'+r, 's+'+s, 't:'+t, input.slice(s), 'X', input.slice(t)) | ||
*/ | ||
var r = CSV.readAll(input, ',', function (rows) { | ||
console.log(input, rows); | ||
}) | ||
console.log('r:'+r, input.length, input.slice(r)) | ||
//var obj = CSV.fetch(input); | ||
//console.log(input, obj) | ||
//a,"b1,""b2""b3,b4""""b5\b6"\r\nc,d | ||
@@ -258,4 +258,10 @@ 'use strict'; | ||
); | ||
describe('#12 fetch()', function () { | ||
it('should', function () { | ||
var obj = CSV.fetch('a,"b",c\r\na,"b""b",c'); | ||
obj.should.eql(['a', 'b', 'c']); | ||
} | ||
); | ||
} | ||
); | ||
describe('#1 forEach()', function () { | ||
@@ -262,0 +268,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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 3 instances in 1 package
26378510
16
748
0
2