-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
128 additions
and
25 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,19 @@ | ||
module.exports=function filterRow(row, param) { | ||
if (param.ignoreColumns instanceof Array && param.ignoreColumns.length > 0) { | ||
for (var igRow = 0, igColLen = param.ignoreColumns.length; igRow < igColLen; igRow++) { | ||
if (param.ignoreColumns[igRow] >= 0) { | ||
row.splice(param.ignoreColumns[igRow], 1); | ||
} | ||
} | ||
} | ||
if (param.includeColumns instanceof Array && param.includeColumns.length > 0) { | ||
var cleanRowArr = []; | ||
for (var inRow = 0, inColLen = param.includeColumns.length; inRow < inColLen; inRow++) { | ||
if (param.includeColumns[inRow] >= 0) { | ||
cleanRowArr.push(row[param.includeColumns[inRow]]); | ||
} | ||
} | ||
row = cleanRowArr; | ||
} | ||
return row; | ||
} |
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,32 @@ | ||
var csv = require("../"); | ||
var assert = require("assert"); | ||
var fs = require("fs"); | ||
describe("CSV Converter", function () { | ||
it ("should ignore column only once",function(done){ | ||
csv({ | ||
ignoreColumns:[0,0] | ||
}) | ||
.fromFile(__dirname+"/data/complexJSONCSV") | ||
.on('json',function(json){ | ||
assert(!json.fieldA.title); | ||
assert(json.fieldA.children[0].name); | ||
}) | ||
.on('done',function(){ | ||
done() | ||
}); | ||
}) | ||
it ("should ignore column by header name",function(done){ | ||
csv({ | ||
ignoreColumns:[0,"fieldA.title",2] | ||
}) | ||
.fromFile(__dirname+"/data/complexJSONCSV") | ||
.on('json',function(json){ | ||
assert(!json.fieldA.title); | ||
assert(json.fieldA.children[0].name); | ||
assert(!json.fieldA.children[0].id); | ||
}) | ||
.on('done',function(){ | ||
done() | ||
}); | ||
}) | ||
}); |