koles / ya-csv Goto Github PK
View Code? Open in Web Editor NEWCSV parser/writer for Node.js
License: MIT License
CSV parser/writer for Node.js
License: MIT License
If the last field in the csv is empty then it will be set as undefined instead of the expected ''
Example file:
id,name,specials
1,John Doe,
2,Jane Doe,Javascript
3,Jake Doe,
Expected output:
{ id: '1', name: 'John Doe', specials: '' }
{ id: '2', name: 'Jane Doe', specials: 'Javascript' }
{ id: '3', name: 'Jake Doe', specials: '' }
Received output:
{ id: '1', name: 'John Doe', specials: '' }
{ id: '2', name: 'Jane Doe', specials: 'Javascript' }
{ id: '3', name: 'Jake Doe', specials: undefined }
I'm trying to pause the readstream after 500 lines but it does not seem to work :/
this is my code (in coffeescript):
reader.addListener 'data', (data) ->
lines++
console.log "passed line #{lines}",data
@Pause()
return
I expect this code to read only 1 line and than pause and it doesn't stop, am I missing smthing?
I think it would be good to only use escaping for fields when it is required.
I have seen some CSV implementations, doing this, and unless this goes against any rule I think it's great to save some space.
Seems while the version in package.json was bumped and 0.9.3 was tagged it was never published to the npm.
Hi,
The CsvWriter object should support two additional options:
a) an option that defines the column names of objects to be written with writeRecord (e.g. { columnNames : ["name", "age"] } ).
b) an option that defines whether the column names should be written to the output as a first line (e.g. {columnsAsHeader : true} ).
This way, CsvWrite could be used to write objects (dictionaries) instead of just arrays.
Hi,
I am new here, just downloaded your project, I would like to run it, can you please show me how ?
thanks
In my application the csv files I needed are residing in a password protected location in the server. So how to access those files using this module?.
If the last character of a chunk is a double quote and the next character at the beginning of the next chunk is also a double quote, both characters will be ignored and the output will not output any characters.
I believe this has to do with using data.charAt(i+1)
and not looking at the previous field if data.charAt(i+1) is null.
Example:
test,123,"quote""d field here"
If the stream chunk ends here:
test,123,"quote""d field here"
^
The output value
test,123,"quoted field here
when it should read
test,123,"quote"d field here
It works properly on windows when I force to set it up at my machines.
You don't need to miss a windows support.
It's a pretty big csv file. Instead of all the columns, a lot of the output ends with "... X more items". How do I output all of them?
var reader = csv.createCsvFileReader('FB-PageFocus-July2017-To-Sept112017.csv', {
'separator': ',',
'quote': '"',
'escape': '"',
'comment': '',
});
var writer = new csv.CsvWriter(process.stdout);
// reader.addListener('data', function(data) {
// console.log([ data ]);
// });
reader.addListener('data', function(data) {
console.log(data);
});
reader.addListener('error', function(e) {
console.error('Oops!');
});
Right now it only parses streams or file but there is no way to parse a string (and there's no easy way to covert string to a stream either).
At the moment the parser does not support anything but the simplest ascii file format (as far as I an tell). E.g. scandinavian åäöÅÄÖ characters all comes out as 0xFFFD.
Error: separator expected after a closing quote; found C
Hi,
the createCsvFileWriter and createCsvStreamWriter methods throw an exception in all lines that set the encoding since the streamWriter object (no longer?) has the .setEncoding method. The encoding should be defined as a part of the .write method - see http://nodejs.org/api.html#writable-stream-33.
I'm running Node 0.2.3.
The following CSV contains two lines, each containing 4 records. However, the ya-csv parser reports only 1 line with 5 columns.
== begin ==
one,"""two"", two-and-half","three","four"
1,2,3,4
== end == (no EOL after the previous line)
Caused by two bugs:
Thanks to zd at gooddata for reporting this.
After creating a CsvFileWriter and writing data to file there is no documented way to close the writer, resulting in a file descriptor leak. I've managed to close it by using writer.writeStream.end()
.
Example:
writer = csv.createCsvFileWriter('file.csv', {'flags': 'a'});
var csvData = new Array();
csvData.push(id);
csvData.push(name);
writer.writeRecord(csvData);
writer.writeStream.end(); // this is how to close the file descriptor
This is more of a question than an issue. This method (createCsvStreamReader) sets the readStream to undefined if no options are passed through:
csv.createCsvStreamReader = function(readStream, options) {
if (options === undefined && typeof readStream === 'object') {
options = readStream;
readStream = undefined;
}
options = options || {};
if (readStream) readStream.setEncoding(options.encoding || 'utf8');
return new CsvReader(readStream, options);
};
It seem like really strange behaviour, and my reader was not receiving any events because of this. Is this actually intended behaviour?
Now it crashes all nodejs app:
node_modules/ya-csv/lib/ya-csv.js:131
throw new Error("separator expected after a closin
Error: separator expected after a closing quote; found
It should handle the error gracefully.
Would be nice if it was possible to group properties into objects, e.g. like this:
reader.setColumnNames([ 'adress.street', 'adress.zip', 'adress.city']);
reader.addListener('data', function(data) {
console.log(data.adress.street);
console.log(data.adress.zip);
console.log(data.adress.city);
});
Hi,
first of all, thanks for this excellent module.
Question : How error are supposed to be handled ?
The api seems to provide an 'error' event.
But even if you add an 'error' listener, there's a lot of throw new Error ("...") in the code base that makes error handling difficult.
When I try and require the parser after installing through npm I get:
Type '.help' for options.
node> require('ya-csv')
Error: Cannot find module 'ya-csv'
at loadModule (node.js:275:15)
at require (node.js:411:14)
at cwdRequire (repl:27:10)
at [object Context]:1:1
at Interface.<anonymous> (repl:78:19)
at Interface.emit (events:26:26)
at Interface._ttyWrite (readline:281:12)
at Interface.write (readline:123:27)
at Stream.<anonymous> (repl:59:9)
at Stream.emit (events:26:26)
perhaps an index.js problem?
NPM verifies that it's installed:
$ npm ls ya-csv
npm it worked if it ends with ok
npm cli [ 'ls', 'ya-csv' ]
npm version 0.1.26
npm config file /Users/jlarson/.npmrc
npm config file /usr/local/etc/npmrc
npm GET /
[email protected] =koles remote
[email protected] =koles remote
[email protected] =koles remote
[email protected] =koles installed latest remote
npm ok
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.