Skip to content

Commit

Permalink
Merge pull request #22 from doug-martin/master
Browse files Browse the repository at this point in the history
v0.2.0
  • Loading branch information
doug-martin committed Mar 10, 2014
2 parents 49d772e + 7d230e8 commit dd04b47
Show file tree
Hide file tree
Showing 23 changed files with 507 additions and 218 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function (grunt) {
src: 'test/**/*.test.js',
options: {
timeout: 3000, // not fully supported yet
reporter: 'dotmatrix'
reporter: 'spec'
}
}
},
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
[![build status](https://secure.travis-ci.org/C2FO/fast-csv.png)](http://travis-ci.org/C2FO/fast-csv)
# Fast-csv

This is a library is aimed at providing fast CSV parsing. It accomplishes this by not handling some of the more complex
edge cases such as multi line rows. However it does support escaped values, embedded commas, double and single quotes.
This is a library that provides CSV parsing and formatting.

**NOTE** As of v0.2.0 `fast-csv` supports multi-line values.

## Installation

Expand All @@ -21,6 +22,9 @@ All methods accept the following `options`
* `ignoreEmpty=false`: If you wish to ignore empty rows.
* `delimiter=','`: If your data uses an alternate delimiter such as `;` or `\t`.
* **NOTE** When specifying an alternate `delimiter` you may only pass in a single character delimeter
* `quote='"'`: The character to use to escape values that contain a delimeter.
* `escape='"'`: The character to use when escaping a value that is `quoted` and contains a `quote` character.
* `i.e`: 'First,"Name"' => '"First,""name"""'
* The following are options for parsing only.
* `trim=false`: If you want to trim all values parsed set to true.
* `rtrim=false`: If you want to right trim all values parsed set to true.
Expand Down Expand Up @@ -211,12 +215,8 @@ csv
`fast-csv` also allows to you to create create a `CSV` from data.
In addition to the options for parsing you can specify the following additional options.
* `quote='"'`: The character to use to escape values that contain a delimeter.
* `escape='"'`: The character to use when escaping a value that is `quoted` and constains a `quote` character.
* `i.e`: 'First,"Name"' => '"First,""name"""'
Formatting accepts the same options as parsing.
*
**Writing Data**
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.
Expand Down
2 changes: 1 addition & 1 deletion benchmark/assets/100000.csv
Original file line number Diff line number Diff line change
Expand Up @@ -99998,4 +99998,4 @@ First1,Last1,email1@email.com,
,,,
"First'1",Last1,email1@email.com,"1 Street St, State ST, 88888"
"First""1",Last1,email1@email.com,"1 Street St, State ST, 88888"
"First""1",Last1,email1@email.com,"1 Street St, State ST, 88888"
"First""1",Last1,email1@email.com,"1 Street St, State ST, 88888"
2 changes: 1 addition & 1 deletion benchmark/assets/1000000.csv
Original file line number Diff line number Diff line change
Expand Up @@ -999998,4 +999998,4 @@ First1,Last1,email1@email.com,
First1,Last1,email1@email.com,"1 Street St, State ST, 88888"
First1,Last1,email1@email.com,"1 ""Street"" St, State ST, 88888"
First1,Last1,email1@email.com,
,,,
,,,
2 changes: 1 addition & 1 deletion benchmark/assets/20000.csv
Original file line number Diff line number Diff line change
Expand Up @@ -19998,4 +19998,4 @@ First1,Last1,email1@email.com,
"First'1",Last1,email1@email.com,"1 Street St, State ST, 88888"
"First""1",Last1,email1@email.com,"1 Street St, State ST, 88888"
"First""1",Last1,email1@email.com,"1 Street St, State ST, 88888"
First1,Last1,email1@email.com,"1 Street St, State ST, 88888"
First1,Last1,email1@email.com,"1 Street St, State ST, 88888"
2 changes: 1 addition & 1 deletion benchmark/assets/50000.csv
Original file line number Diff line number Diff line change
Expand Up @@ -49998,4 +49998,4 @@ First1,Last1,email1@email.com,
,,,
"First'1",Last1,email1@email.com,"1 Street St, State ST, 88888"
"First""1",Last1,email1@email.com,"1 Street St, State ST, 88888"
"First""1",Last1,email1@email.com,"1 Street St, State ST, 88888"
"First""1",Last1,email1@email.com,"1 Street St, State ST, 88888"
15 changes: 10 additions & 5 deletions benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var fastCsv = require("../lib"),
csv = require("csv"),
path = require("path"),
COUNT = 20000,
COUNT = 100000,
TEST_FILE = path.resolve(__dirname, "./assets/" + COUNT + ".csv");


Expand All @@ -23,7 +23,7 @@ function benchmarkFastCsv(done) {
ret.address = data.address;
return ret;
})
.on("record", function (record) {
.on("record", function () {
count++;
})
.on("end", function () {
Expand All @@ -48,7 +48,7 @@ function benchmarkCsv(done) {
["first_name", "last_name", "email_address"].forEach(function (prop, i) {
ret[camelize(prop)] = data[i];
});
ret.address = data[4];
ret.address = data[3];
return ret;
})
.on('record', function () {
Expand All @@ -67,20 +67,25 @@ function benchmarkCsv(done) {
}

function benchmark(title, m, done) {
var start = new Date();
var start = new Date(), runStart = start;
m(function (err) {
if (err) {
done(err);
} else {
console.log("%s: RUN 1 %dms", title, (new Date() - runStart));
runStart = new Date();
m(function (err) {
if (err) {
done(err);
} else {
console.log("%s: RUN 2 %dms", title, (new Date() - runStart));
runStart = new Date();
m(function (err) {
if (err) {
done(err);
} else {
console.log("%s: %dms", title, (new Date() - start) / 3);
console.log("%s: RUN 3 %dms", title, (new Date() - runStart));
console.log("%s: 3xAVG %dms", title, (new Date() - start) / 3);
done();
}

Expand Down
21 changes: 10 additions & 11 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@

<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>
<h1>Fast-csv</h1>
<p>This is a library is aimed at providing fast CSV parsing. It accomplishes this by not handling some of the more complex
edge cases such as multi line rows. However it does support escaped values, embedded commas, double and single quotes.</p>
<p>This is a library that provides CSV parsing and formatting.</p>
<p><strong>NOTE</strong> As of v0.2.0 <code>fast-csv</code> supports multi-line values.</p>
<h2>Installation</h2>
<p><code>npm install fast-csv</code></p>
<h2>Usage</h2>
Expand All @@ -185,6 +185,11 @@ <h3>Parsing</h3>
<li><strong>NOTE</strong> When specifying an alternate <code>delimiter</code> you may only pass in a single character delimeter</li>
</ul>
</li>
<li><code>quote=&#39;&quot;&#39;</code>: The character to use to escape values that contain a delimeter.</li>
<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>
<li><code>i.e</code>: &#39;First,&quot;Name&quot;&#39; =&gt; &#39;&quot;First,&quot;&quot;name&quot;&quot;&quot;&#39;</li>
</ul>
</li>
<li>The following are options for parsing only.<ul>
<li><code>trim=false</code>: If you want to trim all values parsed set to true.</li>
<li><code>rtrim=false</code>: If you want to right trim all values parsed set to true.</li>
Expand Down Expand Up @@ -324,15 +329,9 @@ <h3>Transforming</h3>
});</code></pre>
<h3>Formatting</h3>
<p><code>fast-csv</code> also allows to you to create create a <code>CSV</code> from data.</p>
<p>In addition to the options for parsing you can specify the following additional options.</p>
<ul>
<li><code>quote=&#39;&quot;&#39;</code>: The character to use to escape values that contain a delimeter.</li>
<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>
<li><code>i.e</code>: &#39;First,&quot;Name&quot;&#39; =&gt; &#39;&quot;First,&quot;&quot;name&quot;&quot;&quot;&#39;</li>
</ul>
</li>
</ul>
<p><strong>Writing Data</strong></p>
<p>Formatting accepts the same options as parsing.
<em>
<em>*Writing Data</em></em></p>
<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>
<p><strong><code>write(arr[, options])</code></strong></p>
<p>Create a readable stream to read data from.</p>
Expand Down
6 changes: 5 additions & 1 deletion lib/extended.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
module.exports = require("extended")().register(require("is-extended")).register(require("object-extended")).register(require("string-extended"));
module.exports = require("extended")()
.register(require("is-extended"))
.register(require("object-extended"))
.register(require("string-extended"))
.register("LINE_BREAK", (process.platform === 'win32' ? '\r\n' : '\n'));
2 changes: 1 addition & 1 deletion lib/formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var fs = require("fs"),
isUndefinedOrNull = extended.isUndefinedOrNull,
hash = extended.hash,
stream = require("stream"),
LINE_BREAK = (process.platform === 'win32' ? '\r\n' : '\n');
LINE_BREAK = extended.LINE_BREAK;

function createFormatter(options) {
options = options || {};
Expand Down
16 changes: 8 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
* [![build status](https://secure.travis-ci.org/C2FO/fast-csv.png)](http://travis-ci.org/C2FO/fast-csv)
* # Fast-csv
*
* This is a library is aimed at providing fast CSV parsing. It accomplishes this by not handling some of the more complex
* edge cases such as multi line rows. However it does support escaped values, embedded commas, double and single quotes.
* This is a library that provides CSV parsing and formatting.
*
* **NOTE** As of v0.2.0 `fast-csv` supports multi-line values.
*
* ## Installation
*
Expand All @@ -22,6 +23,9 @@
* * `ignoreEmpty=false`: If you wish to ignore empty rows.
* * `delimiter=','`: If your data uses an alternate delimiter such as `;` or `\t`.
* * **NOTE** When specifying an alternate `delimiter` you may only pass in a single character delimeter
* * `quote='"'`: The character to use to escape values that contain a delimeter.
* * `escape='"'`: The character to use when escaping a value that is `quoted` and contains a `quote` character.
* * `i.e`: 'First,"Name"' => '"First,""name"""'
* * The following are options for parsing only.
* * `trim=false`: If you want to trim all values parsed set to true.
* * `rtrim=false`: If you want to right trim all values parsed set to true.
Expand Down Expand Up @@ -212,12 +216,8 @@
*
* `fast-csv` also allows to you to create create a `CSV` from data.
*
* In addition to the options for parsing you can specify the following additional options.
*
* * `quote='"'`: The character to use to escape values that contain a delimeter.
* * `escape='"'`: The character to use when escaping a value that is `quoted` and constains a `quote` character.
* * `i.e`: 'First,"Name"' => '"First,""name"""'
*
* Formatting accepts the same options as parsing.
**
* **Writing Data**
*
* 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.
Expand Down
Loading

0 comments on commit dd04b47

Please sign in to comment.