Skip to content

Commit

Permalink
CSV encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Maximillian Murphy committed Mar 20, 2018
1 parent 376f296 commit da16f78
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions bin/csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ var by = process.argv[2];
var parseStream = require('./clean');

function csvRecord(record){
var json = JSON.stringify(record);
return json.substr(1,json.length-2);
return record.map(x =>
(x===undefined)?''
:(x===null)?''
:(x==='')?''
:(typeof(x)==="string")?'"'+x.replace(/"/g,'""').replace(/\r/g,'\\r').replace(/\n/g,'\\n').replace(/\t/g,'\\t')+'"'
:String(x)
).join(",");
}

function getHeaders(stream){
Expand Down Expand Up @@ -49,7 +54,7 @@ if(require.main === module) {
process.exit(2);
}
process.stdout.on('error',process.exit);
console.log.apply(null,['#'].concat(process.argv));
//console.log.apply(null,['#'].concat(process.argv));
var infile = process.argv[2];
if (infile === undefined) {
streamToCsv(process.stdin)
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": "jline",
"version": "0.0.46",
"version": "0.0.47",
"description": "Sort, grep and join files where every line is JSON.",
"main": "index.js",
"bin": {
Expand Down

0 comments on commit da16f78

Please sign in to comment.