Skip to content

Commit

Permalink
v2.3.0 (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-martin authored Sep 27, 2016
1 parent 85a1b02 commit 507fe51
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 46 deletions.
4 changes: 4 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v2.3.0

* Writing object ends up with function definitions [#158](https://github.com/C2FO/fast-csv/pull/158)

# v2.2.0

* Handle split CRLF [#156](https://github.com/C2FO/fast-csv/pull/156) - [@alexeits](https://github.com/alexeits)
Expand Down
4 changes: 4 additions & 0 deletions docs/History.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@



<h1 id="v2-3-0">v2.3.0</h1>
<ul>
<li>Writing object ends up with function definitions <a href="https://github.com/C2FO/fast-csv/pull/158">#158</a></li>
</ul>
<h1 id="v2-2-0">v2.2.0</h1>
<ul>
<li>Handle split CRLF <a href="https://github.com/C2FO/fast-csv/pull/156">#156</a> - <a href="https://github.com/alexeits">@alexeits</a></li>
Expand Down
7 changes: 4 additions & 3 deletions lib/extended.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var is = require("is-extended");
var is = require("is-extended"),
hasOwn = Object.prototype.hasOwnProperty;
module.exports = require("extended")()
.register(is)
.register(require("object-extended"))
Expand Down Expand Up @@ -51,8 +52,8 @@ module.exports = require("extended")()
})
.register("keys", function (obj) {
var ret = [];
if (is.isObject(obj)) {
for (var i in obj) {
for (var i in obj) {
if (hasOwn.call(obj, i)) {
ret.push(i);
}
}
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": "2.2.0",
"version": "2.3.0",
"description": "CSV parser and writer",
"main": "index.js",
"scripts": {
Expand Down
116 changes: 74 additions & 42 deletions test/issues.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ it.describe("github issues", function (it) {
it.should("handle bubble up parse errors properly", function (next) {
var d = domain.create(), called = false;
d.on("error", function (err) {
if(!called) {
if (!called) {
called = true;
assert.equal(/^Parse Error/.test(err.message), true);
next();
Expand All @@ -40,11 +40,11 @@ it.describe("github issues", function (it) {
it.should("handle bubble up data errors properly", function (next) {
var d = domain.create(), called = false;
d.on("error", function (err) {
if(!called) {
if (!called) {
called = true;
assert.equal(err.message, "Data error");
next();
}else{
} else {
throw err;
}
});
Expand Down Expand Up @@ -148,22 +148,23 @@ it.describe("github issues", function (it) {
it.should("handle bubble up errors thrown in end properly", function (next) {
var d = domain.create(), called = false;
d.on("error", function (err) {
if(!called) {
if (!called) {
called = true;
assert.equal(err.message, "End error");
next();
}else{
} else {
throw err;
}
});
d.run(function () {
var actual = [];
csv
.fromPath(path.resolve(__dirname, "./assets/issue93.csv"), {headers: true, delimiter: "\t"})
.on("error", function(){
.on("error", function () {
next(new Error("Should not get here!"));
})
.on("data", function (data) {})
.on("data", function (data) {
})
.on("end", function () {
throw new Error("End error");
});
Expand All @@ -173,42 +174,42 @@ it.describe("github issues", function (it) {

it.describe("#111", function (it) {

it.should("parse a block of CSV text with a trailing delimiter", function () {
var data = "first_name,last_name,email_address,empty\nFirst1,Last1,[email protected],\n";
var myParser = parser({delimiter: ","});
assert.deepEqual(myParser(data, false), {
"line": "", "rows": [
["first_name", "last_name", "email_address", "empty"],
["First1", "Last1", "[email protected]", ""]
]
});
it.should("parse a block of CSV text with a trailing delimiter", function () {
var data = "first_name,last_name,email_address,empty\nFirst1,Last1,[email protected],\n";
var myParser = parser({delimiter: ","});
assert.deepEqual(myParser(data, false), {
"line": "", "rows": [
["first_name", "last_name", "email_address", "empty"],
["First1", "Last1", "[email protected]", ""]
]
});
});

it.should("parse a block of CSV text with a delimiter at file end", function () {
var data = "first_name,last_name,email_address,empty\nFirst1,Last1,[email protected],";
var myParser = parser({delimiter: ","});
assert.deepEqual(myParser(data, false), {
"line": "", "rows": [
["first_name", "last_name", "email_address", "empty"],
["First1", "Last1", "[email protected]", ""]
]
});
it.should("parse a block of CSV text with a delimiter at file end", function () {
var data = "first_name,last_name,email_address,empty\nFirst1,Last1,[email protected],";
var myParser = parser({delimiter: ","});
assert.deepEqual(myParser(data, false), {
"line": "", "rows": [
["first_name", "last_name", "email_address", "empty"],
["First1", "Last1", "[email protected]", ""]
]
});
});

it.should("parse a block of CSV text with two delimiters at file end", function () {
var data = "first_name,last_name,email_address,empty1,empty2\nFirst1,Last1,[email protected],,";
var myParser = parser({delimiter: ","});
assert.deepEqual(myParser(data, false), {
"line": "", "rows": [
["first_name", "last_name", "email_address", "empty1", "empty2"],
["First1", "Last1", "[email protected]", "", ""]
]
});
it.should("parse a block of CSV text with two delimiters at file end", function () {
var data = "first_name,last_name,email_address,empty1,empty2\nFirst1,Last1,[email protected],,";
var myParser = parser({delimiter: ","});
assert.deepEqual(myParser(data, false), {
"line": "", "rows": [
["first_name", "last_name", "email_address", "empty1", "empty2"],
["First1", "Last1", "[email protected]", "", ""]
]
});
});

it.should("parse a block of CSV text with a trailing delimiter followed by a space", function() {
it.should("parse a block of CSV text with a trailing delimiter followed by a space", function () {
var data = "first_name,last_name,email_address,empty\nFirst1,Last1,[email protected], \n";
var myParser = parser({ delimiter: "," });
var myParser = parser({delimiter: ","});
assert.deepEqual(myParser(data, false), {
"line": "", "rows": [
["first_name", "last_name", "email_address", "empty"],
Expand All @@ -217,20 +218,20 @@ it.describe("github issues", function (it) {
});
});

it.should("parse a block of Space Separated Value text with a trailing delimiter", function() {
it.should("parse a block of Space Separated Value text with a trailing delimiter", function () {
var data = "first_name last_name email_address empty\nFirst1 Last1 [email protected] \n";
var myParser = parser({ delimiter: " " });
var myParser = parser({delimiter: " "});
assert.deepEqual(myParser(data, false), {
"line": "", "rows": [
["first_name", "last_name", "email_address", "empty"],
["First1", "Last1", "[email protected]", ""]
]
});
});
});

it.should("parse a block of Space Separated Values with two delimiters at file end", function() {
it.should("parse a block of Space Separated Values with two delimiters at file end", function () {
var data = "first_name last_name email_address empty empty2\nFirst1 Last1 [email protected] \n";
var myParser = parser({ delimiter: " " });
var myParser = parser({delimiter: " "});
assert.deepEqual(myParser(data, false), {
"line": "", "rows": [
["first_name", "last_name", "email_address", "empty", "empty2"],
Expand All @@ -251,4 +252,35 @@ it.describe("github issues", function (it) {
});
});
});
});

it.describe("#158", function (it) {
function Place(id, name) {
this.id = id;
this.name = name;
this.calculatedValue = 0;
}

Place.prototype.calculateSomething = function () {
this.calculatedValue = this.id * 2;
return this;
};

it.should("not write prototype methods in csv", function (next) {
var ws = new stream.Writable(), written = [];
ws._write = function (data, enc, cb) {
written.push(data + "");
cb();
};
ws.on("finish", function () {
assert.deepEqual(written.join(""), "id,name,calculatedValue\n1,a,2\n2,b,4\n3,c,6");
next();
});
csv.writeToStream(ws, [
new Place(1, "a").calculateSomething(),
new Place(2, "b").calculateSomething(),
new Place(3, "c").calculateSomething()
], {headers: true}).on("error", next);
});

});
});

0 comments on commit 507fe51

Please sign in to comment.