@welldot/utils
parseDelimitedText
Parses delimited text (CSV, semicolon or tab separated) into rows of fields.
parseDelimitedText(
text):object
Parses delimited text (CSV, semicolon or tab separated) into rows of fields.
The delimiter is detected over the first 20 non-empty lines (a title or
preamble line does not mislead it): for each of , ; \t the lines are
split and the most common field count of 2 or more is found; the delimiter
shared by the most lines wins. Equal scores prefer ;, then \t, then ,,
so a ; file with decimal commas never reads as comma separated. Quotes follow
RFC 4180: a quoted field may contain the delimiter or line breaks, and ""
is an escaped quote. Fields are trimmed and empty lines are dropped.
Parameters
text
string
The raw file content.
Returns
object
The detected delimiter and the parsed rows.
delimiter
delimiter:
Delimiter
rows
rows:
string[]