Comparing version 0.2.3 to 0.2.4
@@ -13,2 +13,14 @@ --- | ||
version 0.2.4 | ||
------------- | ||
* Speed improvement to transformation | ||
version 0.2.3 | ||
------------- | ||
* Fix stdout samples | ||
* Install instruction | ||
* Honor the pipe `end` option | ||
version 0.2.2 | ||
@@ -15,0 +27,0 @@ ------------- |
@@ -5,3 +5,3 @@ --- | ||
title: "Reading data from a source" | ||
date: 2012-11-16T16:44:20.770Z | ||
date: 2012-11-05T20:57:04.723Z | ||
comments: false | ||
@@ -8,0 +8,0 @@ sharing: false |
@@ -5,3 +5,3 @@ --- | ||
title: "Node CSV" | ||
date: 2012-11-16T16:44:20.770Z | ||
date: 2012-11-16T16:02:50.333Z | ||
comments: false | ||
@@ -8,0 +8,0 @@ sharing: false |
@@ -5,3 +5,3 @@ --- | ||
title: "Parsing" | ||
date: 2012-11-16T16:44:20.771Z | ||
date: 2012-10-09T16:24:28.047Z | ||
comments: false | ||
@@ -8,0 +8,0 @@ sharing: false |
@@ -5,3 +5,3 @@ --- | ||
title: "Stringifier" | ||
date: 2012-11-16T16:44:20.771Z | ||
date: 2012-11-19T14:18:05.878Z | ||
comments: false | ||
@@ -16,3 +16,16 @@ sharing: false | ||
Convert an array or an object into a CSV line. | ||
<a name="write"></a> | ||
`write(line, [preserve])` | ||
------------------------- | ||
Write a line to the written stream. Line may be an object, an array or a string | ||
The `preserve` argument is for line which are not considered as CSV data. | ||
The `preserve` argument is for the lines which are not considered as CSV data. | ||
<a name="Stringifier"></a> | ||
`Stringifier(line)` | ||
------------------- | ||
Convert a line to a string. Line may be an object, an array or a string. | ||
@@ -5,3 +5,3 @@ --- | ||
title: "Transforming data" | ||
date: 2012-11-16T16:44:20.771Z | ||
date: 2012-10-18T13:11:44.066Z | ||
comments: false | ||
@@ -8,0 +8,0 @@ sharing: false |
@@ -153,2 +153,4 @@ // Generated by CoffeeScript 1.3.3 | ||
CSV = function() { | ||
var self; | ||
self = this; | ||
this.paused = false; | ||
@@ -162,16 +164,16 @@ this.readable = true; | ||
this.parser = parser(this); | ||
this.parser.on('row', (function(row) { | ||
return this.transformer.transform(row); | ||
}).bind(this)); | ||
this.parser.on('end', (function() { | ||
return this.transformer.end(); | ||
}).bind(this)); | ||
this.parser.on('error', (function(e) { | ||
return this.error(e); | ||
}).bind(this)); | ||
this.parser.on('row', function(row) { | ||
return self.transformer.transform(row); | ||
}); | ||
this.parser.on('end', function() { | ||
return self.transformer.end(); | ||
}); | ||
this.parser.on('error', function(e) { | ||
return self.error(e); | ||
}); | ||
this.stringifier = stringifier(this); | ||
this.transformer = transformer(this); | ||
this.transformer.on('end', (function() { | ||
return this.emit('end', this.state.count); | ||
}).bind(this)); | ||
this.transformer.on('end', function() { | ||
return self.emit('end', self.state.count); | ||
}); | ||
return this; | ||
@@ -178,0 +180,0 @@ }; |
@@ -18,4 +18,8 @@ // Generated by CoffeeScript 1.3.3 | ||
/* | ||
`write(line, [preserve])` | ||
------------------------- | ||
Write a line to the written stream. Line may be an object, an array or a string | ||
The `preserve` argument is for line which are not considered as CSV data. | ||
The `preserve` argument is for the lines which are not considered as CSV data. | ||
*/ | ||
@@ -25,3 +29,3 @@ | ||
Stringifier.prototype.write = function(line, preserve) { | ||
if (typeof line === 'undefined' || line === null) { | ||
if (line == null) { | ||
return; | ||
@@ -44,4 +48,16 @@ } | ||
/* | ||
`Stringifier(line)` | ||
------------------- | ||
Convert a line to a string. Line may be an object, an array or a string. | ||
*/ | ||
Stringifier.prototype.stringify = function(line) { | ||
var column, columns, containsLinebreak, containsQuote, containsdelimiter, delimiter, escape, field, i, newLine, quote, regexp, _i, _j, _line, _ref, _ref1; | ||
if (typeof line !== 'object') { | ||
return line; | ||
} | ||
columns = this.csv.options.to.columns || this.csv.options.from.columns; | ||
@@ -54,54 +70,50 @@ if (typeof columns === 'object' && columns !== null && !Array.isArray(columns)) { | ||
escape = this.csv.options.to.escape || this.csv.options.from.escape; | ||
if (typeof line === 'object') { | ||
if (!Array.isArray(line)) { | ||
_line = []; | ||
if (columns) { | ||
for (i = _i = 0, _ref = columns.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { | ||
column = columns[i]; | ||
_line[i] = typeof line[column] === 'undefined' || line[column] === null ? '' : line[column]; | ||
} | ||
} else { | ||
for (column in line) { | ||
_line.push(line[column]); | ||
} | ||
if (!Array.isArray(line)) { | ||
_line = []; | ||
if (columns) { | ||
for (i = _i = 0, _ref = columns.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { | ||
column = columns[i]; | ||
_line[i] = typeof line[column] === 'undefined' || line[column] === null ? '' : line[column]; | ||
} | ||
line = _line; | ||
_line = null; | ||
} else if (columns) { | ||
line.splice(columns.length); | ||
} else { | ||
for (column in line) { | ||
_line.push(line[column]); | ||
} | ||
} | ||
if (Array.isArray(line)) { | ||
newLine = this.csv.state.countWriten ? this.csv.options.to.lineBreaks || "\n" : ''; | ||
for (i = _j = 0, _ref1 = line.length; 0 <= _ref1 ? _j < _ref1 : _j > _ref1; i = 0 <= _ref1 ? ++_j : --_j) { | ||
field = line[i]; | ||
if (typeof field === 'string') { | ||
line = _line; | ||
_line = null; | ||
} else if (columns) { | ||
line.splice(columns.length); | ||
} | ||
if (Array.isArray(line)) { | ||
newLine = this.csv.state.countWriten ? this.csv.options.to.lineBreaks || "\n" : ''; | ||
for (i = _j = 0, _ref1 = line.length; 0 <= _ref1 ? _j < _ref1 : _j > _ref1; i = 0 <= _ref1 ? ++_j : --_j) { | ||
field = line[i]; | ||
if (typeof field === 'string') { | ||
} else if (typeof field === 'number') { | ||
field = '' + field; | ||
} else if (typeof field === 'boolean') { | ||
field = field ? '1' : ''; | ||
} else if (field instanceof Date) { | ||
field = '' + field.getTime(); | ||
} else if (typeof field === 'number') { | ||
field = '' + field; | ||
} else if (typeof field === 'boolean') { | ||
field = field ? '1' : ''; | ||
} else if (field instanceof Date) { | ||
field = '' + field.getTime(); | ||
} | ||
if (field) { | ||
containsdelimiter = field.indexOf(delimiter) >= 0; | ||
containsQuote = field.indexOf(quote) >= 0; | ||
containsLinebreak = field.indexOf("\r") >= 0 || field.indexOf("\n") >= 0; | ||
if (containsQuote) { | ||
regexp = new RegExp(quote, 'g'); | ||
field = field.replace(regexp, escape + quote); | ||
} | ||
if (field) { | ||
containsdelimiter = field.indexOf(delimiter) >= 0; | ||
containsQuote = field.indexOf(quote) >= 0; | ||
containsLinebreak = field.indexOf("\r") >= 0 || field.indexOf("\n") >= 0; | ||
if (containsQuote) { | ||
regexp = new RegExp(quote, 'g'); | ||
field = field.replace(regexp, escape + quote); | ||
} | ||
if (containsQuote || containsdelimiter || containsLinebreak || this.csv.options.to.quoted) { | ||
field = quote + field + quote; | ||
} | ||
newLine += field; | ||
if (containsQuote || containsdelimiter || containsLinebreak || this.csv.options.to.quoted) { | ||
field = quote + field + quote; | ||
} | ||
if (i !== line.length - 1) { | ||
newLine += delimiter; | ||
} | ||
newLine += field; | ||
} | ||
line = newLine; | ||
if (i !== line.length - 1) { | ||
newLine += delimiter; | ||
} | ||
} | ||
} else if (typeof line === 'number') { | ||
line = '' + line; | ||
line = newLine; | ||
} | ||
@@ -108,0 +120,0 @@ return line; |
@@ -99,3 +99,4 @@ // Generated by CoffeeScript 1.3.3 | ||
Transformer.prototype.transform = function(line) { | ||
var column, columns, csv, done, finish, i, lineAsObject, sync, _i, _j, _len, _len1; | ||
var column, columns, csv, done, finish, i, lineAsObject, self, sync, _i, _j, _len, _len1; | ||
self = this; | ||
csv = this.csv; | ||
@@ -127,3 +128,3 @@ columns = csv.options.from.columns; | ||
} | ||
finish = (function(line) { | ||
finish = function(line) { | ||
var k, v; | ||
@@ -146,6 +147,6 @@ if (csv.state.count === 1 && csv.options.to.header === true) { | ||
csv.stringifier.write(line); | ||
if (csv.state.transforming === 0 && this.closed === true) { | ||
return this.emit('end', csv.state.count); | ||
if (csv.state.transforming === 0 && self.closed === true) { | ||
return self.emit('end', csv.state.count); | ||
} | ||
}).bind(this); | ||
}; | ||
csv.state.count++; | ||
@@ -152,0 +153,0 @@ if (this.callback) { |
{ | ||
"name": "csv", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "CSV parser with simple api, full of options and tested against large datasets.", | ||
@@ -5,0 +5,0 @@ "homepage": "http://www.adaltas.com/projects/node-csv/", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
365710
1434