tabulate

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.

Parameters

data T[][]

An array of array data

tableConfig TableConfig

A table-wide configuration

columnConfigs ColumnConfig[]

Configurations for each columns (The length should match with data)

Return Value

Type: string

The table string

Examples

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>くん     |       プログラミング言語       |"
);

Meta