CSV To Markdown Table Converter
This is a utility tool used to convert Comma-separated values (CSV) files to a Markdown table. The tool was written with Go, a programming language known for being fantastic with string processing, great performance and a collection of other great features.
Table Of Contents
Usage
The easiest and recommended way to use this tool is through the command line. Download the .exe executable file and run the tool from a terminal of your choice.
An example command to run the tool can look like this:
import (
"github.com/phamduylong/csv-to-md"
"fmt"
"errors"
)
func convertMyCSV() (string, error) {
var cfg Config
cfg.URL = "https://raw.githubusercontent.com/askmedia/datalogue/master/olympics/winter_olympics_medals.csv"
cfg.Align = Center
cfg.VerboseLogging = true
table, err := Convert(cfg)
fmt.Println(table)
}
Configuration Options
The program offers a range of different configuration options to customize the tool to best fit your use case.
Align
(Optional)
This option decides should text be aligned in the table. Available choices:
- 0 - Center (default)
- 1 - Left
- 2 - Right
Delimiter
(Optional)
Set the delimiter character for the CSV parser. If not given, the comma , character will be used. This can come in handy when your CSV file use different delimiters than the popular comma.
The path to the input CSV file to be converted. This can be either absolute or relative path.
NOTE: This should be used mutual exclusively with URL (meaning only one of them should be used at a time)
URL
The URL from which the CSV data can be fetched from. For this to work, the HTTPS response sent by the server must set the Media Type to text/csv; charset=utf-8 and the return status code must be in range of success (200-299) or redirection (300-399). Last but not least, the response body should contain only the CSV data and nothing else.
NOTE: This should be used mutual exclusively with Input File (meaning only one of them should be used at a time).
Verbose Logging
(Optional)
Should detailed diagnostic messages be logged? By default, these messages are kept out of the process to avoid polluting the program output and prevent unnecessary information from confusing users. It could be helpful to track down the problem when the program execution went wrong.
I did not create a very proper setup to measure the performance. Ran it with my own PC so take it with a grain of salt.
| Rows |
Columns |
Average Execution Time (5 runs) |
| 1.000 |
10 |
29ms |
| 10.000 |
10 |
2,1s |
| 50.000 |
10 |
48,2s |
| 100.000 |
10 |
3 minutes |