⚡️ Easily generate human-readable ASCII tables from lua
-- require the file
local table_gen = require "table_gen"
local headings = {"Country", "Capital", "Population", "Language"}
local rows = {
{"USA", "Washington, D.C.", "237 million", "English"},
{"Sweden", "Stockholm", "10 million", "Swedish"},
{"Germany", "Berlin", "82 million", "German"}
}
-- generate the table. Last argument are the options, or if a string, the style option
local table_out = table_gen(rows, headings, {
style = "Markdown (Github)"
})
-- Print it to console
print(table_out)
-- output:
-- | Country | Capital | Population | Language |
-- |---------|------------------|-------------|----------|
-- | USA | Washington, D.C. | 237 million | English |
-- | Sweden | Stockholm | 10 million | Swedish |
-- | Germany | Berlin | 82 million | German |
Result:
Country | Capital | Population | Language |
---|---|---|---|
USA | Washington, D.C. | 237 million | English |
Sweden | Stockholm | 10 million | Swedish |
Germany | Berlin | 82 million | German |
table_gen.generate_table(rows, headings, options)
Syntax:
- rows: A table of rows
- (optional) headings: A headings row
- (optional) options: A table of options, or a style string
style
(string): The general style. Check the supported styles belowtop_line
(boolean): Defaults to true for all styles but Github Markdownbottom_line
(boolean): Defaults to true for all styles but Github Markdownheader_seperator_line
: Defaults to true
Instead of table_gen.generate_table(...)
, you can also directly call table_gen(...)
.
ASCII (Default):
+-----------+----------+-----+
| Firstname | Lastname | Age |
+-----------+----------+-----+
| Jill | Smith | 51 |
| Eve | Jackson | 94 |
| John | Doe | 80 |
+-----------+----------+-----+
Unicode:
╔═══════════╦══════════╦═════╗
║ Firstname ║ Lastname ║ Age ║
╠═══════════╬══════════╬═════╣
║ Jill ║ Smith ║ 51 ║
║ Eve ║ Jackson ║ 94 ║
║ John ║ Doe ║ 80 ║
╚═══════════╩══════════╩═════╝
Unicode (Single Line):
┌───────────┬──────────┬─────┐
│ Firstname │ Lastname │ Age │
├───────────┼──────────┼─────┤
│ Jill │ Smith │ 51 │
│ Eve │ Jackson │ 94 │
│ John │ Doe │ 80 │
└───────────┴──────────┴─────┘
Markdown (Github):
| Firstname | Lastname | Age |
|-----------|----------|-----|
| Jill | Smith | 51 |
| Eve | Jackson | 94 |
| John | Doe | 80 |
Compact:
----------- ---------- -----
Firstname Lastname Age
----------- ---------- -----
Jill Smith 51
Eve Jackson 94
John Doe 80
ASCII (Girder):
//===========[]==========[]=====\\
|| Firstname || Lastname || Age ||
|]===========[]==========[]=====[|
|| Jill || Smith || 51 ||
|| Eve || Jackson || 94 ||
|| John || Doe || 80 ||
\\===========[]==========[]=====//
This script was based on https://github.com/ozh/ascii-tables (https://ozh.github.io/ascii-tables/)