Skip to content

Commit

Permalink
Merge pull request #123 from C2FO/node-5
Browse files Browse the repository at this point in the history
updating for node 4 and streams3 changes
  • Loading branch information
dustinsmith1024 committed Jan 5, 2016
2 parents 98951c1 + 10f083d commit a2444a0
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 110 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
node_js:
- "0.10"
- "0.11"
- "0.12"
- "4"
- "5"
- "stable"
before_script:
- npm install -g grunt-cli
- npm install -g grunt-cli
6 changes: 5 additions & 1 deletion History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# v1.0.0

* Node 4 and 5 support.
* Deprecating the `record` event.

# v0.6.0

* Removed try catch from emit to allow bubbling up of errors to process, if one is thrown [#93](https://github.com/C2FO/fast-csv/issues/93)
Expand Down Expand Up @@ -133,4 +138,3 @@
* Added trim, ltrim, and rtrim to parsing options

# v0.1.0

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ All methods accept the following `options`
**events**

* `data`: Emitted when a record is parsed.
* `record`: Emitted when a record is parsed. **DEPRECATED**
* `data-invalid`: Emitted if there was invalid row encounted, **only emitted if the `validate` function is used or `strictColumnHandling=true`**.
* `data`: Emitted with the object or `stringified` version if the `objectMode` is set to `false`.

Expand Down
50 changes: 25 additions & 25 deletions docs/History.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,19 @@



<h1>v0.6.0</h1>
<h1 id="v0-6-0">v0.6.0</h1>
<ul>
<li>Removed try catch from emit to allow bubbling up of errors to process, if one is thrown <a href="https://github.com/C2FO/fast-csv/issues/93">#93</a><ul>
<li>This also fixed issue <a href="https://github.com/C2FO/fast-csv/issues/92">#92</a> where a loop was entered when <code>this.emit(&quot;error&quot;)</code> was called.</li>
</ul>
</li>
<li>Added new tests</li>
</ul>
<h1>v0.5.7</h1>
<h1 id="v0-5-7">v0.5.7</h1>
<ul>
<li>Strict record handling <a href="https://github.com/C2FO/fast-csv/pull/53">#53</a> - <a href="https://github.com/derjust">@derjust</a></li>
</ul>
<h1>v0.5.6</h1>
<h1 id="v0-5-6">v0.5.6</h1>
<ul>
<li>Fixed issue where parser_stream was emitting end early <a href="https://github.com/C2FO/fast-csv/issues/87">#87</a><ul>
<li>Changed to not emit end during flush</li>
Expand All @@ -197,33 +197,33 @@ <h1>v0.5.6</h1>
</li>
<li>Added support for node <code>v0.12</code></li>
</ul>
<h1>v0.5.5</h1>
<h1 id="v0-5-5">v0.5.5</h1>
<ul>
<li>Fixed issues with ordering of headers when specifying headers in a write stream <a href="https://github.com/C2FO/fast-csv/pull/77">#77</a></li>
<li>Fixed issue where headers were not being written if no data was supplied to write stream.</li>
</ul>
<h1>v0.5.4</h1>
<h1 id="v0-5-4">v0.5.4</h1>
<ul>
<li>Fixed issues with error handling and not registering an error handler on stream <a href="https://github.com/C2FO/fast-csv/issues/68">#68</a></li>
<li>Added support for ignoring quoting while parsing <a href="https://github.com/C2FO/fast-csv/issues/75">#75</a></li>
</ul>
<h1>v0.5.3</h1>
<h1 id="v0-5-3">v0.5.3</h1>
<ul>
<li>Fixed issues with <code>v0.11</code> stream implementation <a href="https://github.com/C2FO/fast-csv/issues/73">#73</a></li>
<li>Fixed issues with <code>pause/resume</code> and data events in <code>v0.10</code> <a href="https://github.com/C2FO/fast-csv/issues/69">#69</a></li>
<li>Fixed the double invoking of done callback when parsing files <a href="https://github.com/C2FO/fast-csv/issues/68">#68</a></li>
<li>Refactored tests</li>
</ul>
<h1>v0.5.2</h1>
<h1 id="v0-5-2">v0.5.2</h1>
<ul>
<li>Fixed issue with <code>writeToString</code> and <code>writeToPath</code> examples <a href="https://github.com/C2FO/fast-csv/issues/64">#64</a></li>
<li>Fixed issue with creating a csv without headers <a href="https://github.com/C2FO/fast-csv/issues/63">#63</a></li>
</ul>
<h1>v0.5.1</h1>
<h1 id="v0-5-1">v0.5.1</h1>
<ul>
<li>Fixed issue where line data was not being passed between transforms in the parser_stream</li>
</ul>
<h1>v0.5.0</h1>
<h1 id="v0-5-0">v0.5.0</h1>
<ul>
<li>Added support for async transforms <a href="https://github.com/C2FO/fast-csv/issues/24">#24</a></li>
<li>Added support for async validation</li>
Expand All @@ -240,67 +240,67 @@ <h1>v0.5.0</h1>
<li>More tests</li>
<li>Code refactor and clean up</li>
</ul>
<h1>v0.4.4</h1>
<h1 id="v0-4-4">v0.4.4</h1>
<ul>
<li>Added support for comments. <a href="https://github.com/C2FO/fast-csv/issues/56">#56</a></li>
</ul>
<h1>v0.4.3</h1>
<h1 id="v0-4-3">v0.4.3</h1>
<ul>
<li>Added ability to include a <code>rowDelimiter</code> at the end of a csv with the <code>includeEndRowDelimiter</code> option <a href="https://github.com/C2FO/fast-csv/issues/54">#54</a></li>
<li>Added escaping for values that include a row delimiter</li>
<li>Added more tests for new feature and escaping row delimiter values.</li>
</ul>
<h1>v0.4.2</h1>
<h1 id="v0-4-2">v0.4.2</h1>
<ul>
<li>Added ability to specify a rowDelimiter when creating a csv.</li>
<li>Added discardUnmappedColumns option to allow the ignoring of extra data <a href="https://github.com/C2FO/fast-csv/pull/45">#45</a></li>
</ul>
<h1>v0.4.1</h1>
<h1 id="v0-4-1">v0.4.1</h1>
<ul>
<li>Fixed race condition that occurred if you called pause during a flush.</li>
</ul>
<h1>v0.4.0</h1>
<h1 id="v0-4-0">v0.4.0</h1>
<ul>
<li>Fixed misspelling of <code>delimiter</code> <a href="https://github.com/C2FO/fast-csv/issues/40">#40</a></li>
</ul>
<h1>v0.3.1</h1>
<h1 id="v0-3-1">v0.3.1</h1>
<ul>
<li>Added transform support to formatters<ul>
<li>When using <code>createWriteStream</code> you can now you the <code>transform</code> method to specify a row transformer.</li>
<li>When using other transform methods you can specify a <code>transform</code> option.</li>
</ul>
</li>
</ul>
<h1>v0.3.0</h1>
<h1 id="v0-3-0">v0.3.0</h1>
<ul>
<li>You can now specify <code>objectMode</code> when parsing a csv which will cause <code>data</code> events to have an object emitted.</li>
<li>You can now pipe directly to the stream returned from <code>createWriteStream</code></li>
<li>You can now transform csvs by piping output from parsing into a formatter.</li>
</ul>
<h1>v0.2.5</h1>
<h1 id="v0-2-5">v0.2.5</h1>
<ul>
<li>Fixed issue where not all rows are emitted when using <code>pause</code> and <code>resume</code></li>
</ul>
<h1>v0.2.4</h1>
<h1 id="v0-2-4">v0.2.4</h1>
<ul>
<li>Added more fine grained control to <code>.pause</code> and <code>.resume</code><ul>
<li>You can now pause resume between chunks</li>
</ul>
</li>
</ul>
<h1>v0.2.3</h1>
<h1 id="v0-2-3">v0.2.3</h1>
<ul>
<li>Add new <code>createWriteStream</code> for creating a streaming csv writer</li>
</ul>
<h1>v0.2.2</h1>
<h1 id="v0-2-2">v0.2.2</h1>
<ul>
<li>Fixed issue with having line breaks containing <code>\r\n</code></li>
</ul>
<h1>v0.2.1</h1>
<h1 id="v0-2-1">v0.2.1</h1>
<ul>
<li>Fixed issue with <code>\r</code> line break in parser</li>
</ul>
<h1>v0.2.0</h1>
<h1 id="v0-2-0">v0.2.0</h1>
<ul>
<li>Added multiline value support</li>
<li>Updated escaping logic</li>
Expand All @@ -309,17 +309,17 @@ <h1>v0.2.0</h1>
<li>Removed support for having two quote types instead it just supports a single quote and escape sequence.
Source code (zip)</li>
</ul>
<h1>v0.1.2</h1>
<h1 id="v0-1-2">v0.1.2</h1>
<ul>
<li>Fixed issue with formatter handling undefined or null values.</li>
<li>Changed formatter not not include a new line at the end of a CSV.</li>
<li>Added pause and resume functionality to ParserStream</li>
</ul>
<h1>v0.1.1</h1>
<h1 id="v0-1-1">v0.1.1</h1>
<ul>
<li>Added trim, ltrim, and rtrim to parsing options</li>
</ul>
<h1>v0.1.0</h1>
<h1 id="v0-1-0">v0.1.0</h1>

<hr>

Expand Down
35 changes: 17 additions & 18 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@


<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>
<h1 id="fast-csv">Fast-csv</h1>
<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>
<h2 id="installation">Installation</h2>
<p><code>npm install fast-csv</code></p>
<h2>Usage</h2>
<h3>Parsing</h3>
<h2 id="usage">Usage</h2>
<h3 id="parsing">Parsing</h3>
<p>All methods accept the following <code>options</code></p>
<ul>
<li><code>objectMode=true</code>: Ensure that <code>data</code> events have an object emitted rather than the stringified version set to false to have a stringified buffer.</li>
Expand Down Expand Up @@ -212,7 +212,6 @@ <h3>Parsing</h3>
<p><strong>events</strong></p>
<ul>
<li><code>data</code>: Emitted when a record is parsed.</li>
<li><code>record</code>: Emitted when a record is parsed. <strong>DEPRECATED</strong></li>
<li><code>data-invalid</code>: Emitted if there was invalid row encounted, <strong>only emitted if the <code>validate</code> function is used or <code>strictColumnHandling=true</code></strong>.</li>
<li><code>data</code>: Emitted with the object or <code>stringified</code> version if the <code>objectMode</code> is set to <code>false</code>.</li>
</ul>
Expand Down Expand Up @@ -351,7 +350,7 @@ <h3>Parsing</h3>
.on(&quot;end&quot;, function(){
console.log(&quot;done&quot;);
});</code></pre>
<h3>Validating</h3>
<h3 id="validating">Validating</h3>
<p>You can validate each row in the csv by providing a validate handler. If a row is invalid then a <code>data-invalid</code> event
will be emitted with the row and the index.</p>
<pre class='prettyprint linenums lang-js'><code class="lang-javascript">var stream = fs.createReadStream(&quot;my.csv&quot;);
Expand Down Expand Up @@ -390,7 +389,7 @@ <h3>Validating</h3>
.on(&quot;end&quot;, function(){
console.log(&quot;done&quot;);
});</code></pre>
<h3>Transforming</h3>
<h3 id="transforming">Transforming</h3>
<p>You can transform data by providing a transform function. What is returned from the transform function will
be provided to validate and emitted as a row.</p>
<pre class='prettyprint linenums lang-js'><code class="lang-javascript">var stream = fs.createReadStream(&quot;my.csv&quot;);
Expand Down Expand Up @@ -420,7 +419,7 @@ <h3>Transforming</h3>
.on(&quot;end&quot;, function(){
console.log(&quot;done&quot;);
});</code></pre>
<h3>Formatting</h3>
<h3 id="formatting">Formatting</h3>
<p><code>fast-csv</code> also allows to you to create create a <code>CSV</code> from data.</p>
<p>Formatting accepts the same options as parsing with an additional <code>transform</code> option.</p>
<ul>
Expand All @@ -440,7 +439,7 @@ <h3>Formatting</h3>
</ul>
</li>
</ul>
<h3>Data Types</h3>
<h3 id="data-types">Data Types</h3>
<p>When creating a CSV <code>fast-csv</code> supports a few data formats.</p>
<p><strong><code>Objects</code></strong></p>
<p>You can pass in object to any formatter function if your csv requires headers the keys of the first object will be used as the header names.</p>
Expand Down Expand Up @@ -480,7 +479,7 @@ <h3>Data Types</h3>
//Generated CSV
//a,a,b,b,c,c
//a1,a2,b1,b2,c1,c2</code></pre>
<h3>Formatting Functions</h3>
<h3 id="formatting-functions">Formatting Functions</h3>
<p><strong><code>createWriteStream(options)</code> or <code>.format(options)</code></strong></p>
<p>This is the lowest level of the write methods, it creates a stream that can be used to create a csv of unknown size and pipe to an output csv.</p>
<pre class='prettyprint linenums lang-js'><code class="lang-javascript">var csvStream = csv.createWriteStream({headers: true}),
Expand Down Expand Up @@ -677,15 +676,15 @@ <h3>Formatting Functions</h3>
console.log(&quot;done!&quot;);
});</code></pre>
<pre class='prettyprint linenums lang-js'><code class="lang-javascript">csv
.writeToStream(&quot;my.csv&quot;, [
.writeToPath(&quot;my.csv&quot;, [
{a: &quot;a1&quot;, b: &quot;b1&quot;},
{a: &quot;a2&quot;, b: &quot;b2&quot;}
], {headers: true})
.on(&quot;finish&quot;, function(){
console.log(&quot;done!&quot;);
});</code></pre>
<pre class='prettyprint linenums lang-js'><code class="lang-javascript">csv
.writeToStream(&quot;my.csv&quot;, [
.writeToPath(&quot;my.csv&quot;, [
{a: &quot;a1&quot;, b: &quot;b1&quot;},
{a: &quot;a2&quot;, b: &quot;b2&quot;}
], {
Expand Down Expand Up @@ -740,7 +739,7 @@ <h3>Formatting Functions</h3>
console.log(data); //&quot;A,B\na1,b1\na2,b2\n&quot;
}
);</code></pre>
<h2>Piping from Parser to Writer</h2>
<h2 id="piping-from-parser-to-writer">Piping from Parser to Writer</h2>
<p>You can use <code>fast-csv</code> to pipe the output from a parsed CSV to a transformed CSV by setting the parser to <code>objectMode</code> and using <code>createWriteStream</code>.</p>
<pre class='prettyprint linenums lang-js'><code class="lang-javascript">csv
.fromPath(&quot;in.csv&quot;, {headers: true})
Expand Down Expand Up @@ -775,10 +774,10 @@ <h2>Piping from Parser to Writer</h2>
.fromPath(&quot;in.csv&quot;, {headers: true})
.pipe(formatStream)
.pipe(fs.createWriteStream(&quot;out.csv&quot;, {encoding: &quot;utf8&quot;}));</code></pre>
<h2>Quoting Columns</h2>
<h2 id="quoting-columns">Quoting Columns</h2>
<p>Sometimes you may need to quote columns is certain ways in order meet certain requirements. <code>fast-csv</code> can quote columns and headers almost anyway you may need.</p>
<p><strong>Note</strong> in the following example we use <code>writeToString</code> but the options option are valid for any of the formatting methods.</p>
<h3><code>quoteColumns</code></h3>
<h3 id="-quotecolumns-"><code>quoteColumns</code></h3>
<pre class='prettyprint linenums lang-js'><code>//quote all columns including headers
var objectData = [{a: &quot;a1&quot;, b: &quot;b1&quot;}, {a: &quot;a2&quot;, b: &quot;b2&quot;}],
arrayData = [[&quot;a&quot;, &quot;b&quot;], [&quot;a1&quot;, &quot;b1&quot;], [&quot;a2&quot;, &quot;b2&quot;]];
Expand All @@ -801,7 +800,7 @@ <h3><code>quoteColumns</code></h3>
//a1,&quot;b1&quot;
//a2,&quot;b2&quot;
});</code></pre>
<h3><code>quoteHeaders</code></h3>
<h3 id="-quoteheaders-"><code>quoteHeaders</code></h3>
<pre class='prettyprint linenums lang-js'><code>//quote all columns including headers
var objectData = [{a: &quot;a1&quot;, b: &quot;b1&quot;}, {a: &quot;a2&quot;, b: &quot;b2&quot;}],
arrayData = [[&quot;a&quot;, &quot;b&quot;], [&quot;a1&quot;, &quot;b1&quot;], [&quot;a2&quot;, &quot;b2&quot;]];
Expand Down Expand Up @@ -833,9 +832,9 @@ <h3><code>quoteHeaders</code></h3>
//&quot;a1&quot;,&quot;b1&quot;
//&quot;a2&quot;,&quot;b2&quot;
});</code></pre>
<h2>License</h2>
<h2 id="license">License</h2>
<p>MIT <a href="https://github.com/C2FO/fast-csv/raw/master/LICENSE">https://github.com/C2FO/fast-csv/raw/master/LICENSE</a></p>
<h2>Meta</h2>
<h2 id="meta">Meta</h2>
<ul>
<li>Code: <code>git clone git://github.com/C2FO/fast-csv.git</code></li>
<li>Website: <a href="http://c2fo.com">http://c2fo.com</a></li>
Expand Down
11 changes: 9 additions & 2 deletions lib/formatter/formatter_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ var fs = require("fs"),
function CsvTransformStream(options) {
options = options || {};
options.objectMode = true;

if (has(options, "transform")) {
// remove so its not set to _transform in Transform constructor
options.consumerTransform = options.transform;
delete options.transform;
}

Transform.call(this, options);
this.formatter = createFormatter(options, this);
this.rowDelimiter = options.rowDelimiter || "\n";
Expand All @@ -33,7 +40,7 @@ function CsvTransformStream(options) {
}
this.hasWrittenHeaders = hasHeaders ? false : true;
this.includeEndRowDelimiter = !!options.includeEndRowDelimiter,
has(options, "transform") && this.transform(options.transform);
has(options, "consumerTransform") && this.transform(options.consumerTransform);
}
util.inherits(CsvTransformStream, Transform);

Expand Down Expand Up @@ -83,4 +90,4 @@ extended(CsvTransformStream).extend({
}
});

module.exports = CsvTransformStream;
module.exports = CsvTransformStream;
2 changes: 1 addition & 1 deletion lib/formatter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ createWriteStream.createWriteStream = createWriteStream;
createWriteStream.writeToString = writeToString;
createWriteStream.writeToPath = writeToPath;
createWriteStream.writeToStream = writeToStream;
module.exports = createWriteStream;
module.exports = createWriteStream;
3 changes: 1 addition & 2 deletions lib/parser/parser_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ extended(ParserStream).extend({
},

__emitRecord: function (dataRow, count) {
this.emit("record", dataRow, count);
if (this._emitData) {
this.push(this.__objectMode ? dataRow : JSON.stringify(dataRow));
}
Expand Down Expand Up @@ -340,4 +339,4 @@ extended(ParserStream).extend({

});

module.exports = ParserStream;
module.exports = ParserStream;
Loading

0 comments on commit a2444a0

Please sign in to comment.