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

csv-string

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csv-string - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

bench/fromStream.js

7

lib/csv.js

@@ -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;

56

lib/parser.js
'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": [

@@ -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() {

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