CSV parsing with typescript
A few years ago I needed to troubleshoot some imports based on csv files and I had one big issue, depending on the language the user was using on Windows, Excel would export csv files with different separators. Being located in Italy, this means that the separator was ;
. The same was true when trying to read csv with Excel, the separator is chosed based on the language of the OS.
I prefer to set up everything in English because I think it is easier to troubleshoot issues when the error is not localized to Italian.
So I couldn't read csv just opening them on Excel because of the separator, Excel also formats field depending on the content. It might hide leading zeros if it thinks a column is filled with numbers, dates are problematic and so on. I wanted to be able to see the actual content of the csv in a tabular format without fighting with Excel for the separator or for automatic formatting of columns.
I decided to go ahead and build a simple parser, hostable on a website that would read a csv and just print the values without any custom formatting and with the possibility to choose the separator. Of course today I would go with a vs code extension, I'm sure there are plenty doing something similar better than I did in a few hours but at the time this small parser was enough to support my need.
CSV is not a well defined or well agreed format, however there is a IEFT RFC that documents the format. Following that I implemented a parser in typescript that read a csv and creates an html table with the content manipulating the DOM directly.
The repo is this one: https://github.com/davidelettieri/yacv
Online demo: https://davidelettieri.github.io/yacv/
Just today I revisited the code, adding some basic tests and updating typescript version.