Saw some CSV polyfill stuff posted at CodePen. Did some CSV stuff years ago with VB6. It was quite fast, although the code wasn’t very short. That tends to happen when you have almost full control of memory and want to make things fast. With a language not designed for that kind of stuff.
This CSV element polyfill idea however is quite nice. The original author that did the pen linked above didn’t initially have any support for quotes. I wanted to do something that can take almost anything and still work, even if there are line changes within the quoted values, so I started bothering my brains with JavaScript. I’ve read about it a lot in the past few days (thanks to Secrets of the JavaScript Ninja), but I haven’t really done anything practical for a little while. So here we go:
Check out this Pen!
I have still some work to do. I haven’t read much about regular expressions yet. I know somewhat how they work but I rarely push my brain to understanding them in detail. It’ll probably be one of the more challenging parts of the book for me. RegExps just seem the kind of thing that works so different to my own brain logic that it makes it hard to “get it”. However for the first time in my life I actually have a good reason to learn it so I’ll eventually get my head into it.
The thing that is missing is single quote support. You can have multiple line values if you use double quotes, but that doesn’t work with single quotes. Not just yet. I want to have both supported the same time even though there probably aren’t that many CSV files that are so absurd that they’d use both! However CSV is a very “free” standard and it varies so much between users that it makes your head sore when you want to throw your best shot at supporting everything that people have done with it.