Skip to content

Commit 7d230e8

Browse files
committed
v0.2.0
* Added multiline value support * Updated escaping logic * More performance enhancements * More robusts test cases * Removed support for having two quote types instead it just supports a single quote and escape sequence.
1 parent d007203 commit 7d230e8

23 files changed

+507
-218
lines changed

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = function (grunt) {
1616
src: 'test/**/*.test.js',
1717
options: {
1818
timeout: 3000, // not fully supported yet
19-
reporter: 'dotmatrix'
19+
reporter: 'spec'
2020
}
2121
}
2222
},

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
[![build status](https://secure.travis-ci.org/C2FO/fast-csv.png)](http://travis-ci.org/C2FO/fast-csv)
55
# Fast-csv
66

7-
This is a library is aimed at providing fast CSV parsing. It accomplishes this by not handling some of the more complex
8-
edge cases such as multi line rows. However it does support escaped values, embedded commas, double and single quotes.
7+
This is a library that provides CSV parsing and formatting.
8+
9+
**NOTE** As of v0.2.0 `fast-csv` supports multi-line values.
910

1011
## Installation
1112

@@ -21,6 +22,9 @@ All methods accept the following `options`
2122
* `ignoreEmpty=false`: If you wish to ignore empty rows.
2223
* `delimiter=','`: If your data uses an alternate delimiter such as `;` or `\t`.
2324
* **NOTE** When specifying an alternate `delimiter` you may only pass in a single character delimeter
25+
* `quote='"'`: The character to use to escape values that contain a delimeter.
26+
* `escape='"'`: The character to use when escaping a value that is `quoted` and contains a `quote` character.
27+
* `i.e`: 'First,"Name"' => '"First,""name"""'
2428
* The following are options for parsing only.
2529
* `trim=false`: If you want to trim all values parsed set to true.
2630
* `rtrim=false`: If you want to right trim all values parsed set to true.
@@ -211,12 +215,8 @@ csv
211215
212216
`fast-csv` also allows to you to create create a `CSV` from data.
213217
214-
In addition to the options for parsing you can specify the following additional options.
215-
216-
* `quote='"'`: The character to use to escape values that contain a delimeter.
217-
* `escape='"'`: The character to use when escaping a value that is `quoted` and constains a `quote` character.
218-
* `i.e`: 'First,"Name"' => '"First,""name"""'
219-
218+
Formatting accepts the same options as parsing.
219+
*
220220
**Writing Data**
221221
222222
Each of the following methods accept an array of values to be written, however each value must be an `array` of `array`s or `object`s.

benchmark/assets/100000.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99998,4 +99998,4 @@ First1,Last1,[email protected],
9999899998
,,,
9999999999
"First'1",Last1,[email protected],"1 Street St, State ST, 88888"
100000100000
"First""1",Last1,[email protected],"1 Street St, State ST, 88888"
100001-
"First""1",Last1,[email protected],"1 Street St, State ST, 88888"
100001+
"First""1",Last1,[email protected],"1 Street St, State ST, 88888"

benchmark/assets/1000000.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999998,4 +999998,4 @@ First1,Last1,[email protected],
999998999998
First1,Last1,[email protected],"1 Street St, State ST, 88888"
999999999999
First1,Last1,[email protected],"1 ""Street"" St, State ST, 88888"
10000001000000
First1,Last1,[email protected],
1000001-
,,,
1000001+
,,,

benchmark/assets/20000.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19998,4 +19998,4 @@ First1,Last1,[email protected],
1999819998
"First'1",Last1,[email protected],"1 Street St, State ST, 88888"
1999919999
"First""1",Last1,[email protected],"1 Street St, State ST, 88888"
2000020000
"First""1",Last1,[email protected],"1 Street St, State ST, 88888"
20001-
First1,Last1,[email protected],"1 Street St, State ST, 88888"
20001+
First1,Last1,[email protected],"1 Street St, State ST, 88888"

benchmark/assets/50000.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49998,4 +49998,4 @@ First1,Last1,[email protected],
4999849998
,,,
4999949999
"First'1",Last1,[email protected],"1 Street St, State ST, 88888"
5000050000
"First""1",Last1,[email protected],"1 Street St, State ST, 88888"
50001-
"First""1",Last1,[email protected],"1 Street St, State ST, 88888"
50001+
"First""1",Last1,[email protected],"1 Street St, State ST, 88888"

benchmark/benchmark.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var fastCsv = require("../lib"),
22
csv = require("csv"),
33
path = require("path"),
4-
COUNT = 20000,
4+
COUNT = 100000,
55
TEST_FILE = path.resolve(__dirname, "./assets/" + COUNT + ".csv");
66

77

@@ -23,7 +23,7 @@ function benchmarkFastCsv(done) {
2323
ret.address = data.address;
2424
return ret;
2525
})
26-
.on("record", function (record) {
26+
.on("record", function () {
2727
count++;
2828
})
2929
.on("end", function () {
@@ -48,7 +48,7 @@ function benchmarkCsv(done) {
4848
["first_name", "last_name", "email_address"].forEach(function (prop, i) {
4949
ret[camelize(prop)] = data[i];
5050
});
51-
ret.address = data[4];
51+
ret.address = data[3];
5252
return ret;
5353
})
5454
.on('record', function () {
@@ -67,20 +67,25 @@ function benchmarkCsv(done) {
6767
}
6868

6969
function benchmark(title, m, done) {
70-
var start = new Date();
70+
var start = new Date(), runStart = start;
7171
m(function (err) {
7272
if (err) {
7373
done(err);
7474
} else {
75+
console.log("%s: RUN 1 %dms", title, (new Date() - runStart));
76+
runStart = new Date();
7577
m(function (err) {
7678
if (err) {
7779
done(err);
7880
} else {
81+
console.log("%s: RUN 2 %dms", title, (new Date() - runStart));
82+
runStart = new Date();
7983
m(function (err) {
8084
if (err) {
8185
done(err);
8286
} else {
83-
console.log("%s: %dms", title, (new Date() - start) / 3);
87+
console.log("%s: RUN 3 %dms", title, (new Date() - runStart));
88+
console.log("%s: 3xAVG %dms", title, (new Date() - start) / 3);
8489
done();
8590
}
8691

docs/index.html

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@
171171

172172
<p><a href="http://travis-ci.org/C2FO/fast-csv"><img src="https://secure.travis-ci.org/C2FO/fast-csv.png" alt="build status"></a></p>
173173
<h1>Fast-csv</h1>
174-
<p>This is a library is aimed at providing fast CSV parsing. It accomplishes this by not handling some of the more complex
175-
edge cases such as multi line rows. However it does support escaped values, embedded commas, double and single quotes.</p>
174+
<p>This is a library that provides CSV parsing and formatting.</p>
175+
<p><strong>NOTE</strong> As of v0.2.0 <code>fast-csv</code> supports multi-line values.</p>
176176
<h2>Installation</h2>
177177
<p><code>npm install fast-csv</code></p>
178178
<h2>Usage</h2>
@@ -185,6 +185,11 @@ <h3>Parsing</h3>
185185
<li><strong>NOTE</strong> When specifying an alternate <code>delimiter</code> you may only pass in a single character delimeter</li>
186186
</ul>
187187
</li>
188+
<li><code>quote=&#39;&quot;&#39;</code>: The character to use to escape values that contain a delimeter.</li>
189+
<li><code>escape=&#39;&quot;&#39;</code>: The character to use when escaping a value that is <code>quoted</code> and contains a <code>quote</code> character.<ul>
190+
<li><code>i.e</code>: &#39;First,&quot;Name&quot;&#39; =&gt; &#39;&quot;First,&quot;&quot;name&quot;&quot;&quot;&#39;</li>
191+
</ul>
192+
</li>
188193
<li>The following are options for parsing only.<ul>
189194
<li><code>trim=false</code>: If you want to trim all values parsed set to true.</li>
190195
<li><code>rtrim=false</code>: If you want to right trim all values parsed set to true.</li>
@@ -324,15 +329,9 @@ <h3>Transforming</h3>
324329
});</code></pre>
325330
<h3>Formatting</h3>
326331
<p><code>fast-csv</code> also allows to you to create create a <code>CSV</code> from data.</p>
327-
<p>In addition to the options for parsing you can specify the following additional options.</p>
328-
<ul>
329-
<li><code>quote=&#39;&quot;&#39;</code>: The character to use to escape values that contain a delimeter.</li>
330-
<li><code>escape=&#39;&quot;&#39;</code>: The character to use when escaping a value that is <code>quoted</code> and constains a <code>quote</code> character.<ul>
331-
<li><code>i.e</code>: &#39;First,&quot;Name&quot;&#39; =&gt; &#39;&quot;First,&quot;&quot;name&quot;&quot;&quot;&#39;</li>
332-
</ul>
333-
</li>
334-
</ul>
335-
<p><strong>Writing Data</strong></p>
332+
<p>Formatting accepts the same options as parsing.
333+
<em>
334+
<em>*Writing Data</em></em></p>
336335
<p>Each of the following methods accept an array of values to be written, however each value must be an <code>array</code> of <code>array</code>s or <code>object</code>s.</p>
337336
<p><strong><code>write(arr[, options])</code></strong></p>
338337
<p>Create a readable stream to read data from.</p>

lib/extended.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
module.exports = require("extended")().register(require("is-extended")).register(require("object-extended")).register(require("string-extended"));
1+
module.exports = require("extended")()
2+
.register(require("is-extended"))
3+
.register(require("object-extended"))
4+
.register(require("string-extended"))
5+
.register("LINE_BREAK", (process.platform === 'win32' ? '\r\n' : '\n'));

lib/formatter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var fs = require("fs"),
33
isUndefinedOrNull = extended.isUndefinedOrNull,
44
hash = extended.hash,
55
stream = require("stream"),
6-
LINE_BREAK = (process.platform === 'win32' ? '\r\n' : '\n');
6+
LINE_BREAK = extended.LINE_BREAK;
77

88
function createFormatter(options) {
99
options = options || {};

0 commit comments

Comments
 (0)