The first version of every chart tool I've written had this line in it:
const rows = text . split ( '\n' ) . map ( line => line . split ( ',' ) ) ;
Enter fullscreen mode
Exit fullscreen mode
It works on the file you tested. It breaks on the first file a real person uploads: a product name with a comma in it, a Windows CRLF, a UTF-8 BOM, a cell with a newline. Then you discover the harder half of the problem β once you have rows, you still don't have series . Someone gives you three snapshots with different sets of categories and expects a smooth animation between them.
Here's the pipeline I ended up with, in plain JavaScript, no dependencies.
1. Parse CSV as a state machine, not a split
RFC 4180 gives you quoted fields, escaped quotes ( "" ), and newlines inside fields. A two-state loop handles all of it:
function parseCSV ( text ) { if ( text . charCodeAt ( 0 ) === 0xFEFF ) text = text .β¦