Last active
January 15, 2016 11:25
-
-
Save JonathanMH/27b2e293cec1647f16c7 to your computer and use it in GitHub Desktop.
newline problem with node-csv-parse
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 5 columns, instead of 6 in line 1.
This file contains hidden or 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
Name,Gender,"preferred language",startDate,endDate | |
Barbara McFinley,Female,JavaScript,2015-13-01,, |
This file contains hidden or 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
var fs = require('fs'); | |
var csv = require('csv'); | |
var readableStream = fs.createReadStream('employee.csv'); | |
var parser = csv.parse(); | |
var transformer = csv.transform(function(data){ | |
return data.map(function(value){return value.toUpperCase()}); | |
}); | |
var stringifier = csv.stringify(); | |
readableStream.on('readable', function(){ | |
while(data = readableStream.read()){ | |
parser.write(data); | |
} | |
}); | |
parser.on('readable', function(){ | |
while(data = parser.read()){ | |
transformer.write(data); | |
} | |
}); | |
transformer.on('readable', function(){ | |
while(data = transformer.read()){ | |
stringifier.write(data); | |
} | |
}); | |
stringifier.on('readable', function(){ | |
while(data = stringifier.read()){ | |
process.stdout.write(data); | |
} | |
}); | |
// % node index.js ~/work/fast-csv | |
// NAME,GENDER,PREFERRED LANGUAGE,STARTDATE,ENDDATE |
This file contains hidden or 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
var fs = require('fs'); | |
var csv = require('csv'); | |
var readableStream = fs.createReadStream('employee.csv'); | |
var parser = csv.parse(); | |
var transformer = csv.transform(function(data){ | |
return data.map(function(value){return value.toUpperCase()}); | |
}); | |
var stringifier = csv.stringify(); | |
readableStream.on('readable', function(){ | |
while(data = readableStream.read()){ | |
parser.write(data); | |
} | |
}); | |
readableStream.on('end', function(){ | |
parser.end(); | |
}) | |
parser.on('readable', function(){ | |
while(data = parser.read()){ | |
transformer.write(data); | |
} | |
}); | |
transformer.on('readable', function(){ | |
while(data = transformer.read()){ | |
stringifier.write(data); | |
} | |
}); | |
stringifier.on('readable', function(){ | |
while(data = stringifier.read()){ | |
process.stdout.write(data); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment