-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from mdoelker/master
Added discardUnmappedColumns option that throws away extra columns that ...
- Loading branch information
Showing
4 changed files
with
38 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
first_name,last_name,email_address | ||
First1,Last1,[email protected] | ||
First2,Last2,[email protected],Unmapped1 | ||
First3,Last3,[email protected],Unmapped1,Unmapped2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,8 +141,14 @@ var expected14 = [ | |
|
||
var expected21 = [ | ||
{"first_name": "First\n1", "last_name": "Last\n1", "email_address": "[email protected]", address: "1 Street St,\nState ST, 88888"}, | ||
{"first_name": "First\n2", "last_name": "Last\n2", "email_address": "[email protected]", address: "2 Street St,\nState ST, 88888"}, | ||
] | ||
{"first_name": "First\n2", "last_name": "Last\n2", "email_address": "[email protected]", address: "2 Street St,\nState ST, 88888"} | ||
]; | ||
|
||
var expected23 = [ | ||
{"first_name": "First1", "last_name": "Last1", "email_address": "[email protected]"}, | ||
{"first_name": "First2", "last_name": "Last2", "email_address": "[email protected]"}, | ||
{"first_name": "First3", "last_name": "Last3", "email_address": "[email protected]"} | ||
]; | ||
|
||
it.describe("fast-csv", function (it) { | ||
|
||
|
@@ -461,6 +467,21 @@ it.describe("fast-csv", function (it) { | |
}); | ||
}); | ||
|
||
it.should("discard extra columns that do not map to a header with discardUnmappedColumns option", function (next) { | ||
var actual = []; | ||
csv | ||
.fromPath(path.resolve(__dirname, "./assets/test23.csv"), {headers: true, discardUnmappedColumns: true}) | ||
.on("record", function (data, index) { | ||
actual.push(data); | ||
}) | ||
.on("error", next) | ||
.on("end", function (count) { | ||
assert.deepEqual(actual, expected23); | ||
assert.equal(count, actual.length); | ||
next(); | ||
}); | ||
}); | ||
|
||
it.describe("alternate delimiters", function (it) { | ||
it.should("support tab delimiters", function (next) { | ||
var actual = []; | ||
|
@@ -1000,4 +1021,4 @@ it.describe("fast-csv", function (it) { | |
}); | ||
}); | ||
}); | ||
}); | ||
}); |