tabular 0.2.0-alpha copy "tabular: ^0.2.0-alpha" to clipboard
tabular: ^0.2.0-alpha copied to clipboard

outdated

Dart library for easily displaying tabular data in a visually appealing ASCII table format.

Tabular #

Dart library for easily displaying tabular data in a visually appealing ASCII table format.

Tabular is specifically designed to create tables in the Markdown format that GitHub understands.

The library is inspired by python's tabulate and pretty_table.

At the time of writing, pub.dev does not display the program output correctly. See the Tabular readme on GitHub.


import 'package:tabular/tabular.dart';

var data = [
 ['Season', '#', 'Name', 'Days', 'Sun'],
 ['Winter', 1, 'January', 31, 94],
 ['Winter', 2, 'February', 28, 123],
 ['Spring', 3, 'March', 31, 42],
 ['Spring', 4, 'April', 30, 243],
 ['Spring', 5, 'May', 31, 5523],
 ['Summer', 6, 'June', 30, 11251],
 ['Summer', 7, 'July', 31, 17451],
 ['Summer', 8, 'August', 31, 18707],
 ['Autumn', 9, 'September', 30, 7025],
 ['Autumn', 10, 'October', 31, 5041],
 ['Autumn', 11, 'November', 30, 2302],
 ['Winter', 12, 'December', 31, 258],
];

var string = tabular(data);

print(string);
Season | # | Name | Days | Sun
-------|----|-----------|------|------
Winter | 1 | January | 31 | 94
Winter | 2 | February | 28 | 123
Spring | 3 | March | 31 | 42
Spring | 4 | April | 30 | 243
Spring | 5 | May | 31 | 5523
Summer | 6 | June | 30 | 11251
Summer | 7 | July | 31 | 17451
Summer | 8 | August | 31 | 18707
Autumn | 9 | September | 30 | 7025
Autumn | 10 | October | 31 | 5041
Autumn | 11 | November | 30 | 2302
Winter | 12 | December | 31 | 258

Formatting #

Add border #

tabular(data, outerBorder: true);
| Season | # | Name | Days | Sun |
|--------|----|-----------|------|-------|
| Winter | 1 | January | 31 | 94 |
| Winter | 2 | February | 28 | 123 |
| Spring | 3 | March | 31 | 42 |
| Spring | 4 | April | 30 | 243 |
| Spring | 5 | May | 31 | 5523 |
| Summer | 6 | June | 30 | 11251 |
| Summer | 7 | July | 31 | 17451 |
| Summer | 8 | August | 31 | 18707 |
| Autumn | 9 | September | 30 | 7025 |
| Autumn | 10 | October | 31 | 5041 |
| Autumn | 11 | November | 30 | 2302 |
| Winter | 12 | December | 31 | 258 |

Add markdown ':' alignment marks #

tabular(data, markdownAlign: true)
Season | # | Name | Days | Sun
-------|---:|-----------|-----:|-----:
Winter | 1 | January | 31 | 94
Winter | 2 | February | 28 | 123
Spring | 3 | March | 31 | 42
Spring | 4 | April | 30 | 243
Spring | 5 | May | 31 | 5523
Summer | 6 | June | 30 | 11251
Summer | 7 | July | 31 | 17451
Summer | 8 | August | 31 | 18707
Autumn | 9 | September | 30 | 7025
Autumn | 10 | October | 31 | 5041
Autumn | 11 | November | 30 | 2302
Winter | 12 | December | 31 | 258

Modify alignment #

tabular(data, align: {'Name': Side.center, 'Sun': Side.start})
Season | # | Name | Days | Sun 
-------|----|-----------|------|------
Winter | 1 | January | 31 | 94 
Winter | 2 | February | 28 | 123 
Spring | 3 | March | 31 | 42 
Spring | 4 | April | 30 | 243 
Spring | 5 | May | 31 | 5523 
Summer | 6 | June | 30 | 11251
Summer | 7 | July | 31 | 17451
Summer | 8 | August | 31 | 18707
Autumn | 9 | September | 30 | 7025 
Autumn | 10 | October | 31 | 5041 
Autumn | 11 | November | 30 | 2302 
Winter | 12 | December | 31 | 258

Custom column formatting #

tabular(data, 
 format: {
 'Name': (value) => value.toUpperCase(), 
 'Sun': (value) => '+ '+value.toString() })
Season | # | Name | Days | Sun
-------|----|-----------|------|--------
Winter | 1 | JANUARY | 31 | + 94
Winter | 2 | FEBRUARY | 28 | + 123
Spring | 3 | MARCH | 31 | + 42
Spring | 4 | APRIL | 30 | + 243
Spring | 5 | MAY | 31 | + 5523
Summer | 6 | JUNE | 30 | + 11251
Summer | 7 | JULY | 31 | + 17451
Summer | 8 | AUGUST | 31 | + 18707
Autumn | 9 | SEPTEMBER | 30 | + 7025
Autumn | 10 | OCTOBER | 31 | + 5041
Autumn | 11 | NOVEMBER | 30 | + 2302
Winter | 12 | DECEMBER | 31 | + 258

Sorting #

Sort alphabetically by column 0 #

tabular(data, sort: [Sort(0)]) // 0 is 'Season'
Season | # | Name | Days | Sun
-------|----|-----------|------|------
Autumn | 9 | September | 30 | 7025
Autumn | 10 | October | 31 | 5041
Autumn | 11 | November | 30 | 2302
Spring | 3 | March | 31 | 42
Spring | 4 | April | 30 | 243
Spring | 5 | May | 31 | 5523
Summer | 6 | June | 30 | 11251
Summer | 7 | July | 31 | 17451
Summer | 8 | August | 31 | 18707
Winter | 1 | January | 31 | 94
Winter | 2 | February | 28 | 123
Winter | 12 | December | 31 | 258

Sort by 'Days' descending, and then by 'Sun' ascending #

tabular(data, sort: [Sort('Days', ascending: false), Sort('Sun')])
Season | # | Name | Days | Sun
-------|----|-----------|------|------
Spring | 3 | March | 31 | 42
Winter | 1 | January | 31 | 94
Winter | 12 | December | 31 | 258
Autumn | 10 | October | 31 | 5041
Spring | 5 | May | 31 | 5523
Summer | 7 | July | 31 | 17451
Summer | 8 | August | 31 | 18707
Spring | 4 | April | 30 | 243
Autumn | 11 | November | 30 | 2302
Autumn | 9 | September | 30 | 7025
Summer | 6 | June | 30 | 11251
Winter | 2 | February | 28 | 123
15
likes
0
points
45
downloads

Publisher

verified publisherrevercode.com

Weekly Downloads

Dart library for easily displaying tabular data in a visually appealing ASCII table format.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

quiver

More

Packages that depend on tabular