tdast-util-from-csv
tdast utility to parse csv into tdast (RFC-4180 compliant).
Install
npm install tdast-util-from-csv
Use
With some RFC-4180 compliant CSV content (example below includes escaped double quotes and linebreaks):
"col1","c""o""""l,2,,","co\nl\n\n3\n"row1col1, row1col2 ," row1col3\n,\n""""\nrow2col1",row2col2,row2col3\n
tdast-util-from-csv
will parse the CSV content into a tdast Table
node tracking row/column/cell offsets and attaching well-defined UnistPosition
.
; const options = header: true ;;
API
fromCsv(csv[, options])
Interface
;
RFC-4180 compliant CSV parser to parse CSV to a tdast Table
node.
Parsed Cell
nodes conveniently escape any double-quote characters while preserving the original UnistPosition
. This enables conversion of the tdast tree into other syntax trees that can make use of the positional information.
Related interfaces
Author's Note
I have little experience writing parsers. Unlike most CSV parsers, this parser does not use regexp and its implementation is specifically written to track and assemble a tdast tree with well-defined UnistPosition
.
The parser should be well-behaved since it is implemented against the RFC-4180 spec with some testing.
If there are any issues or you want to implement this in a more elegant/efficient way, please let me know through GH issues!