d4_dsv library
A parser and formatter for delimiter-separated values, such as CSV and TSV.
These tabular formats are popular with spreadsheet programs such as Microsoft Excel, and are often more space-efficient than JSON. This implementation is based on RFC 4180.
Comma (CSV) and tab (TSV) delimiters are built-in. For example, to parse:
csvParse("foo,bar\n1,2"); // ([{foo: 1, bar: 2}], columns: [foo, bar])
tsvParse("foo\tbar\n1\t2"); // ([{foo: 1, bar: 2}], columns: [foo, bar])
Or to format:
csvFormat([{"foo": "1", "bar": "2"}]); // "foo,bar\n1,2"
tsvFormat([{"foo": "1", "bar": "2"}]); // "foo\tbar\n1\t2"
To use a different delimiter, such as “|” for pipe-separated values, use DsvFormat:
final psv = DsvFormat("|");
print(psv.parse("foo|bar\n1|2")); // ([{foo: 1, bar: 2}], columns: [foo, bar])
Classes
- DsvFormat
- A class for parsing and formatting Delimiter-Separated Values (DSV) data.
Functions
-
autoType(
Map< String, String> row) → Map<String, Object?> - Given an map representing a parsed row, infers the types of values on the map and coerces them accordingly, returning the mutated map.
-
csvFormat(
Iterable< Map< rows, [Iterable<String, Object?> >String> ? columns]) → String - Equivalent to DsvFormat.format with a delimiter of ",".
-
csvFormatBody(
Iterable< Map< rows, [Iterable<String, Object?> >String> ? columns]) → String - Equivalent to DsvFormat.formatBody with a delimiter of ",".
-
csvFormatRow(
Iterable< Object?> row) → String - Equivalent to DsvFormat.formatRow with a delimiter of ",".
-
csvFormatRows(
Iterable< Iterable< rows) → StringObject?> > - Equivalent to DsvFormat.formatRows with a delimiter of ",".
-
csvFormatValue(
Object? value) → String - Equivalent to DsvFormat.formatValue with a delimiter of ",".
-
csvParse(
String data) → (List< Map< , {List<String, String> >String> columns}) - Equivalent to DsvFormat.parse using "," as delimiter.
-
csvParseRows(
String data) → List< List< String> > - Equivalent to DsvFormat.parseRows with a delimiter of ",".
-
csvParseRowsWith<
R> (String data, R? conversion(List< String> , int)) → List<R> - Equivalent to DsvFormat.parseRowsWith with a delimiter of ",".
-
csvParseWith<
R> (String data, R? conversion(Map< String, String> , int, List<String> )) → (List<R> , {List<String> columns}) - Equivalent to DsvFormat.parseWith with a delimiter of ",".
-
tsvFormat(
Iterable< Map< rows, [Iterable<String, Object?> >String> ? columns]) → String - Equivalent to DsvFormat.format with a delimiter of "\t".
-
tsvFormatBody(
Iterable< Map< rows, [Iterable<String, Object?> >String> ? columns]) → String - Equivalent to DsvFormat.formatBody with a delimiter of "\t".
-
tsvFormatRow(
Iterable< Object?> row) → String - Equivalent to DsvFormat.formatRow with a delimiter of "\t".
-
tsvFormatRows(
Iterable< Iterable< rows) → StringObject?> > - Equivalent to DsvFormat.formatRows with a delimiter of "\t".
-
tsvFormatValue(
Object? value) → String - Equivalent to DsvFormat.formatValue with a delimiter of "\t".
-
tsvParse(
String data) → (List< Map< , {List<String, String> >String> columns}) - Equivalent to DsvFormat.parse using "\t" as delimiter.
-
tsvParseRows(
String data) → List< List< String> > - Equivalent to DsvFormat.parseRows with a delimiter of "\t".
-
tsvParseRowsWith<
R> (String data, R? conversion(List< String> , int)) → List<R> - Equivalent to DsvFormat.parseRowsWith with a delimiter of "\t".
-
tsvParseWith<
R> (String data, R? conversion(Map< String, String> , int, List<String> )) → (List<R> , {List<String> columns}) - Equivalent to DsvFormat.parseWith with a delimiter of "\t".