Here is a "simple" solution
csv.split(/\r\n|\r|\n/g)
It processes:
Unfortunately, it splits values ββcontaining newlines between delimiters.
For example, the following row entry ...
"this is some","valid CSV data","with a \r\nnewline char"
Break it because '\ r \ n' will be mistakenly interpreted as the end of the record.
For a complete solution, it is best to create an ND-FSM lexer / parser (non-deterministic state machine). If you've ever heard of the Chomsky hierarchy , CSV can be analyzed as type III grammar. This means char -by-char or stateful token-token processing.
I have a fully RFC 4180 compatible with the client library, but somehow I got the attention of a successful mod for external linking. Where you are interested, there is a link in my profile; otherwise, good luck.
I will give you a fair warning from experience, CSV looks deceptively light on the surface. Having studied dozens / hundreds of implementations, I saw only 3 javascript parsers that did a reasonable job of fulfilling the specification, and not one of them was fully compatible with RFC. I managed to write one thing, but only with the help of the community and a lot of pain.
source share