An array of array data
A table-wide configuration
Configurations for each columns (The length should match with data)
The table string
const testdata = [ ["D-man", "Programming Language"], ["D言語くん", "プログラミング言語"], ]; const tableConfig = TableConfig(Style.simple, " ", " ", true); const columnConfigs = [ ColumnConfig(20, "マスコットキャラクタ", Align.center), ColumnConfig(10, "about", Align.center) ]; const reference = " マスコットキャラクタ about \n" ~ "---------------------- ------------\n" ~ " D-man ..ming L.. \n" ~ " D言語くん ..ラミン.. "; assert(tabulate(testdata, tableConfig, columnConfigs) == reference);
const testdata = [ ["D-man", "Programming\nLanguage"], ["D言語\nくん", "プログラミング言語"], ]; const columnConfigs = [ ColumnConfig(20, "マスコットキャラクタ", Align.center), ColumnConfig(30, "about", Align.center) ]; assert(tabulate(testdata, TableConfig(Style.simple, " ", " ", true, 0), columnConfigs) == " マスコットキャラクタ about \n" ~ "---------------------- --------------------------------\n" ~ " D-man Programming \n" ~ " Language \n" ~ " D言語 プログラミング言語 \n" ~ " くん " ); assert(tabulate(testdata, TableConfig(Style.simple, " ", " ", true, 1), columnConfigs) == " マスコットキャラクタ about \n" ~ "---------------------- --------------------------------\n" ~ " D-man Programming.. \n" ~ " D言語.. プログラミング言語 " ); assert(tabulate(testdata, TableConfig(Style.markdown, " ", " ", true, 0), columnConfigs) == "| マスコットキャラクタ | about |\n" ~ "|----------------------|--------------------------------|\n" ~ "| D-man | Programming<br>Language |\n" ~ "| D言語<br>くん | プログラミング言語 |" );
Tabulate an array of array data with detailed configurations.
This version uses TableConfig and an array of ColumnConfig instead of Config. TableConfig affects the whole table appearance and ColumnConfigs affect each columns' appearance. This can be used if you want to configure (e.g.) columns one-by-one.