Skip to content

Commit

Permalink
# v0.5.2
Browse files Browse the repository at this point in the history
* Fixed issue with `writeToString` and `writeToPath` examples C2FO#64
* Fixed issue with creating a csv without headers C2FO#63
  • Loading branch information
doug-martin committed Sep 5, 2014
1 parent e697564 commit d958ddd
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 8 deletions.
5 changes: 5 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# v0.5.2

* Fixed issue with `writeToString` and `writeToPath` examples [#64](https://github.com/C2FO/fast-csv/issues/64)
* Fixed issue with creating a csv without headers [#63](https://github.com/C2FO/fast-csv/issues/63)

# v0.5.1

* Fixed issue where line data was not being passed between transforms in the parser_stream
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ csv
.pipe(ws);
```
**`writeToPath(arr[, options])`**
**`writeToPath(path, arr[, options])`**
Write an array of values to the specified path
Expand Down Expand Up @@ -698,7 +698,7 @@ csv.writeToString(
}
},
function (err, data) {
console.log(data); //"a,b\na1,b1\na2,b2\n"
console.log(data); //"A,B\na1,b1\na2,b2\n"
}
);
```
Expand Down
5 changes: 5 additions & 0 deletions docs/History.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@



<h1>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>
<ul>
<li>Fixed issue where line data was not being passed between transforms in the parser_stream</li>
Expand Down
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ <h3>Formatting Functions</h3>
}
})
.pipe(ws);</code></pre>
<p><strong><code>writeToPath(arr[, options])</code></strong></p>
<p><strong><code>writeToPath(path, arr[, options])</code></strong></p>
<p>Write an array of values to the specified path</p>
<pre class='prettyprint linenums lang-js'><code class="lang-javascript">csv
.writeToPath(&quot;my.csv&quot;, [
Expand Down Expand Up @@ -736,7 +736,7 @@ <h3>Formatting Functions</h3>
}
},
function (err, data) {
console.log(data); //&quot;a,b\na1,b1\na2,b2\n&quot;
console.log(data); //&quot;A,B\na1,b1\na2,b2\n&quot;
}
);</code></pre>
<h2>Piping from Parser to Writer</h2>
Expand Down
12 changes: 12 additions & 0 deletions examples/write_to_string_no_headers_example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var csv = require("../");

csv.writeToString(
[
{a: "a1", b: "b1"},
{a: "a2", b: "b2"}
], {
headers: false
}, function (err, data) {
console.log('err:', err, 'data: |' + data + '|');
}
);
19 changes: 19 additions & 0 deletions examples/write_to_string_transform_example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var csv = require("../");
csv.writeToString(
[
{a: "a1", b: "b1"},
{a: "a2", b: "b2"}
],
{
headers: true,
transform: function (row) {
return {
A: row.a,
B: row.b
};
}
},
function (err, data) {
console.log(data); //"A,B\na1,b1\na2,b2\n"
}
);
2 changes: 1 addition & 1 deletion lib/formatter/formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ function gatherHeaders(item) {
function checkHeaders(stream, item) {
var headers, ret = true;
if (!stream.parsedHeaders) {
stream.totalCount++;
stream.parsedHeaders = true;
headers = stream.headers = gatherHeaders(item);
stream.headersLength = headers.length;
}
if (!stream.hasWrittenHeaders) {
stream.totalCount++;
stream.push(new Buffer(stream.formatter(headers, true), "utf8"));
stream.hasWrittenHeaders = true;
ret = isHashArray(item) || !isArray(item);
Expand Down
2 changes: 0 additions & 2 deletions lib/formatter/formatter_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ function CsvTransformStream(options) {
} else {
this.parsedHeaders = false;
}
} else {
this.parsedHeaders = true;
}
this.hasWrittenHeaders = hasHeaders ? false : true;
this.includeEndRowDelimiter = !!options.includeEndRowDelimiter,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fast-csv",
"version": "0.5.1",
"version": "0.5.2",
"description": "CSV parser and writer",
"main": "index.js",
"scripts": {
Expand Down
101 changes: 101 additions & 0 deletions test/fast-csv.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1936,6 +1936,107 @@ it.describe("fast-csv", function (it) {
});
});

it.describe("header option", function (it) {

it.should("write an array of objects without headers", function (next) {
csv.writeToString([
{a: "a1", b: "b1"},
{a: "a2", b: "b2"}
], {
headers: false
}, function (err, csv) {
if (err) {
next(err);
} else {
assert.equal(csv, "a1,b1\na2,b2");
next();
}
});
});

it.should("write an array of objects with headers", function (next) {
csv.writeToString([
{a: "a1", b: "b1"},
{a: "a2", b: "b2"}
], {
headers: true
}, function (err, csv) {
if (err) {
next(err);
} else {
assert.equal(csv, "a,b\na1,b1\na2,b2");
next();
}
});
});

it.should("write an array of arrays without headers", function (next) {
csv.writeToString([
["a1", "b1"],
["a2", "b2"]
], {
headers: false
}, function (err, csv) {
if (err) {
next(err);
} else {
assert.equal(csv, "a1,b1\na2,b2");
next();
}
});
});

it.should("write an array of arrays with headers", function (next) {
csv.writeToString([
["a", "b"],
["a1", "b1"],
["a2", "b2"]
], {
headers: true
}, function (err, csv) {
if (err) {
next(err);
} else {
assert.equal(csv, "a,b\na1,b1\na2,b2");
next();
}
});
});

it.should("write an array of multi-dimensional arrays without headers", function (next) {
csv.writeToString([
[["a", "a1"], ["b", "b1"]],
[["a", "a2"], ["b", "b2"]],
], {
headers: false
}, function (err, csv) {
if (err) {
next(err);
} else {
assert.equal(csv, "a1,b1\na2,b2");
next();
}
});
});

it.should("write an array of multi-dimensional arrays with headers", function (next) {
csv.writeToString([
[["a", "a1"], ["b", "b1"]],
[["a", "a2"], ["b", "b2"]],
], {
headers: true
}, function (err, csv) {
if (err) {
next(err);
} else {
assert.equal(csv, "a,b\na1,b1\na2,b2");
next();
}
});
});
});


it.describe("rowDelimiter option", function (it) {
it.should("support specifying an alternate row delimiter", function (next) {
csv.writeToString([
Expand Down

0 comments on commit d958ddd

Please sign in to comment.