Skip to main content

flutter_d3_dsv_port 0.1.0 copy "flutter_d3_dsv_port: ^0.1.0" to clipboard
flutter_d3_dsv_port: ^0.1.0 copied to clipboard

Native Dart CSV, TSV and delimiter-separated value parsing and formatting, with generic row conversion and typed automatic value inference. Ports d3-dsv 3.0.1.

flutter_d3_dsv_port #

A fully typed, pure-Dart port of d3-dsv 3.0.1. Parse and format CSV, TSV and custom delimiters with zero runtime dependencies. Runs on the Dart VM, Flutter native platforms, JavaScript and WebAssembly.

import 'package:flutter_d3_dsv_port/d3_dsv.dart';

final rows = csvParse('name,age\nAda,36');
print(rows.columns); // [name, age]
print(rows.first['name']); // Ada

final people = csvParseAs(
  'name,age\nAda,36',
  (row, index, columns) => (name: row['name']!, age: int.parse(row['age']!)),
);
print(people.first.age); // 36, statically typed as int

final typed = autoType({'active': 'true', 'amount': '4.2'});
print(typed['amount']!.asDouble); // 4.2
print(csvFormat(rows)); // name,age\nAda,36

API #

Operation Result
parse(text) DsvParsedTable<Map<String, String>>
parseAs<T>(text, convert) DsvParsedTable<T>; null skips a row
parseRows(text) List<List<String>>, without a header
parseRowsAs<T>(text, convert) List<T>; null skips a row
format(rows, [columns]) Text with a header
formatBody(rows, [columns]) Text without a header
formatRows(rows), formatRow(row), formatValue(value) Quoted text

Use dsvFormat(';') or dsvFormat('|') for custom separators. Every operation also has a csv* and tsv* shortcut, including csvParseAs and tsvParseRowsAs. Converters receive the row and its input index; header-aware converters also receive columns. Indices count input rows before filtering. Columns retain input order; missing cells are empty strings and duplicate headers use the last value.

autoType returns a new Map<String, DsvValue>. Its sealed variants are DsvNull, DsvBool, DsvNumber, DsvDate and DsvString. Pattern matching is exhaustive; nullable getters asDouble, asBool, asDateTime, and asString return matching payloads. DsvDate(null) represents invalid ISO date text. Date-only values are UTC; date-times without offsets use local time. Unrecognized strings retain whitespace. The original string map is unchanged.

Formatting accepts maps or iterables of heterogeneous Object? cells, including native DateTime and DsvValue cells. Dates use UTC and millisecond precision. Numbers use native Dart text with a whole-number .0 removed. Map keys retain Dart insertion order; __proto__ is a normal key. No JavaScript runtime is used.

Quoting supports embedded separators, quotes and newlines. Input accepts LF, CR and CRLF; output uses LF. Like upstream, a BOM is preserved and an unterminated final quoted field is accepted. Separators must be one UTF-16 code unit other than quote, CR or LF.

Demo and validation #

Interactive playground with editable input, presets, inferred type chips, table and round-trip preview.

The four upstream test files preserve all 136 named cases in native forms. Additional Node.js reference vectors, baseline twins and native API tests cover escaping, metadata, callbacks, automatic inference and special headers. Test fixtures are embedded and require no filesystem access in browsers.

Performance #

Measurements and baseline-versus-optimized summary tables are recorded in doc/performance.md.

Baseline → optimized, µs per 1,000 rows (seven-batch medians):

Native release Plain parse Speedup Record format Speedup
macos 442.4 → 132.6 3.34× 885.6 → 398.5 2.22×
android 448.1 → 147.4 3.04× 975.5 → 469.6 2.08×
ios 207.3 → 69.1 3.00× 404.1 → 218.8 1.85×
Browser Plain parse: JS base → opt Wasm base → opt Upstream JS
desktop-chrome 89.2 → 68.3 418.0 → 117.3 92.5
desktop-firefox 154.8 → 134.6 1,930.4 → 266.1 122.0
desktop-safari 92.6 → 62.5 1,470.3 → 359.6 64.1
mobile-chrome 170.0 → 132.6 547.7 → 200.0 167.0
mobile-firefox 256.7 → 228.6 6,110.0 → 748.5 190.4

The shared development host had background activity during some captures. See the full report for all six workloads, Node comparisons, exact browser versions, raw results and reproduction commands.

License #

ISC, with the original d3-dsv notice (Mike Bostock). Embedded csv-spectrum test data is BSD-2-Clause (Max Ogden). See LICENSE.

0
likes
160
points
--
downloads

Documentation

API reference

Publisher

unverified uploader

Native Dart CSV, TSV and delimiter-separated value parsing and formatting, with generic row conversion and typed automatic value inference. Ports d3-dsv 3.0.1.

Repository (GitHub)
View/report issues
Contributing

Topics

#d3 #csv #tsv #parsing #serialization

License

BSD-2-Clause, ISC (license)

More

Packages that depend on flutter_d3_dsv_port