As a 16 year-old just getting into software development, it'd be amazing to get feedback from hn.
As a 16 year-old just getting into software development, it'd be amazing to get feedback from hn.
- Vanilla JS would be cleaner
- Make it useable with Node. (Check if "window" variable exists, if not, do export CSV as a module. Should be this easy AFAIK)
- You have some typos on the README.md
- Put this on bower and npm
Good work. I was writing software at 16 but I wasn't doing it open source, I wish I did.
Thanks for the feedback!
[0] http://en.wikipedia.org/wiki/Asynchronous_module_definition
Depends on your definition of 'clean' - IMO CoffeeScript is much cleaner than JS. But yes, more difficult to work with.
This is pretty similar to a library I'm actively working on called Papa Parse: http://papaparse.com
My reason for making this was a mix of "hey let's try making this", let me make something even shorter and (hopefully) sweeter, and "no jQuery".
Your parser is off to a good start: you nailed the general idea of good API design. In other words, it's easy to use, which is immediately appealing. For other things, I think there's been great feedback in the rest of these comments.
(By the way, Papa Parse only uses jQuery for convenience in interacting with the DOM for things like file input elements. The core parser, including the file streamer, is vanilla Javascript.)
"x",""x"",,"x
x","x"
"y",,,,123 [
["x","x\"","","x"],
["x","x"],
["y","","","",123]
]
I can't see anything wrong with it. Am I missing something? [
["x","\"x\"","","x\nx","x"],
["y","","","",123]
]
It's valid CSV, inasmuch as it's accepted and generated by a lot of tools and RFC 4180 ABNF: escaped = DQUOTE *(TEXTDATA / COMMA / CR / LF / 2DQUOTE) DQUOTEThat CSV text is malformed. Arguably, the parsing succeeded, but the expected errors were generated and reported.
Don't hesitate to look at how other CSV libraries work. They've likely solved most/all of the issues you're currently having.
Do add the ability to cast scalar values (ex ints, floats).
Do verify RFC compliance using tests.
Do use vanilla Javascript. Niceties like Coffeescript are good for one-off webapps but add unnecessary dependencies/problems if you're targeting a larger audience.
Do have a solid plan for versioning. Only add backwards-incompatible changes to major versions (ie 1.0, 2.0).
Do have your users try the code in different browsers/platforms. Differences in Regex implementations can cause problems and using streams in Node will be completely different than handling them in the browser.
You win the million dollar prize if you can manage to figure out how to write a CSV stream reader that works in the browser.
In all seriousness though, far beyond anything I was doing at 16. Kudos.
But after doing a lot of mostly CoffeeScript, I had to do some 'plain' JS work, and it took me a while to get back into it. And that can be a problem if you just need to get stuff done sometimes.
(PS: kudos for submitting this! I'm more than a decade older than you are, and I get nervous just thinking of sharing my code with this crowd!)
But what impresses me most is that you're only 16 and you care enough about something as "boring", yet bread-and-butter as CSV parsing. CSV-parsing is not particularly sexy, and there are a lot of libs that do it...but tackling it as a problem to solve, nevermind open-sourcing your solution, is really cool...even if you decide you don't want to be a full-time software developer, your experience (and tolerance) for this kind of data-munging is going to make you a valuable person to work with in any field.
The fact that you're taking the time to write readable documentation for this puts you even farther afield.
In terms of criticism/feedback...what was your reasoning for returning an Object with certain domain-specific properties (i.e. `data` and `fields`) rather than just an Array of hashes? I think the CSV constructor call works fine, and that being the case, maybe add an option in the options hash to return a CSV-object-with-metadata...but by default, `csv.parse()` should return a plain array of objects, so that other programs that utilize it don't have to remember that the data is actually in the Object's `data` property.
Also, you've probably seen D3's implementation, which is designed with the mindset that the CSV-to-be-parsed is likely an external file: https://github.com/mbostock/d3/wiki/CSV
However, after reading your comment, remembering how Ruby does it, and some thought, I decided to default to a returned array but provide the option for a more 'detailed' response.