Skip to content

Commit

Permalink
fix: fixes #99. mapHeaders error when using binary
Browse files Browse the repository at this point in the history
  • Loading branch information
shellscape committed Oct 22, 2018
1 parent 2c95c35 commit a22f006
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 53 deletions.
26 changes: 15 additions & 11 deletions bin/csv-parser
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const argv = minimist(process.argv, {
boolean: ['version', 'help']
})

const headers = argv.headers && argv.headers.toString().split(argv.separator)
const [,, filename] = argv._

if (argv.version) {
Expand All @@ -50,10 +49,21 @@ if (argv.help || (process.stdin.isTTY && !filename)) {

let input
const output = (argv.output && argv.output !== '-') ? fs.createWriteStream(argv.output) : process.stdout
const removedHeaders = argv.remove && argv.remove.split(',')
const options = {
separator: argv.separator,
strict: argv.strict,
skipLines: argv.skipLines
}

if (argv.headers) {
options.headers = argv.headers.toString().split(argv.separator)
}

function mapHeaders (name, i) {
return removedHeaders.indexOf(name) === -1 ? name : null
if (argv.remove) {
const removeHeaders = argv.remove.split(',')
options.mapHeaders = (name, i) => {
return removeHeaders.indexOf(name) === -1 ? name : null
}
}

if (filename === '-' || !filename) {
Expand All @@ -66,12 +76,6 @@ if (filename === '-' || !filename) {
}

input
.pipe(csv({
headers,
separator: argv.separator,
strict: argv.strict,
mapHeaders: argv.remove ? mapHeaders : null,
skipLines: argv.skipLines
}))
.pipe(csv(options))
.pipe(ndjson.serialize())
.pipe(output)
162 changes: 122 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"dependencies": {
"buffer-alloc": "^1.1.0",
"buffer-from": "^1.0.0",
"execa": "^1.0.0",
"generate-function": "^1.0.1",
"generate-object-property": "^1.0.0",
"minimist": "^1.2.0",
Expand Down
8 changes: 7 additions & 1 deletion test/snapshots/test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,4 +458,10 @@ Generated by [AVA](https://ava.li).
0,
1,
2,
]


## binary stanity

> Snapshot 1
'{"a":"1"}'
Binary file modified test/snapshots/test.js.snap
Binary file not shown.
Loading

0 comments on commit a22f006

Please sign in to comment.