{"id":15681029,"url":"https://github.com/fbiville/markdown-table-formatter","last_synced_at":"2025-05-07T10:36:50.511Z","repository":{"id":45387223,"uuid":"203209583","full_name":"fbiville/markdown-table-formatter","owner":"fbiville","description":"Markdown table formatter in Go","archived":false,"fork":false,"pushed_at":"2021-12-16T09:36:11.000Z","size":22,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-19T21:24:35.190Z","etag":null,"topics":["go","markdown"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fbiville.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-19T16:26:53.000Z","updated_at":"2025-02-21T22:10:08.000Z","dependencies_parsed_at":"2022-08-28T19:51:08.504Z","dependency_job_id":null,"html_url":"https://github.com/fbiville/markdown-table-formatter","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fbiville%2Fmarkdown-table-formatter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fbiville%2Fmarkdown-table-formatter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fbiville%2Fmarkdown-table-formatter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fbiville%2Fmarkdown-table-formatter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fbiville","download_url":"https://codeload.github.com/fbiville/markdown-table-formatter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252860667,"owners_count":21815548,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","markdown"],"created_at":"2024-10-03T16:48:24.026Z","updated_at":"2025-05-07T10:36:50.483Z","avatar_url":"https://github.com/fbiville.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Markdown table formatter\n\n## Import\n\n```sh\n $ go get github.com/fbiville/markdown-table-formatter/pkg/markdown \n```\n\n## Usage\n\n### Basic\n\n```go\npackage some_package\n\nimport (\n\t\"fmt\"\n\t\"github.com/fbiville/markdown-table-formatter/pkg/markdown\"\n)\n\nfunc someFunction() {\n\tbasicTable, err := markdown.NewTableFormatterBuilder().\n\t\tBuild(\"column 1\", \"column 2\", \"column 3\").\n\t\tFormat([][]string{\n\t\t\t{\"so\", \"much\", \"fun\"},\n\t\t\t{\"don't\", \"you\", \"agree\"},\n\t\t})\n\t\n\tif err != nil {\n\t\t// ... do your thing\n\t}\n\tfmt.Print(basicTable)\n}\n```\n\nThe output will be:\n```markdown\n| column 1 | column 2 | column 3 |\n| -------- | -------- | -------- |\n| so | much | fun |\n| don't | you | agree |\n```\n\n### Pretty-print\n\n```go\npackage some_package\n\nimport (\n\t\"fmt\"\n\t\"github.com/fbiville/markdown-table-formatter/pkg/markdown\"\n)\n\nfunc someFunction() {\n\tprettyPrintedTable, err := markdown.NewTableFormatterBuilder().\n\t\tWithPrettyPrint().\n\t\tBuild(\"column 1\", \"column 2\", \"column 3\").\n\t\tFormat([][]string{\n\t\t\t{\"so\", \"much\", \"fun\"},\n\t\t\t{\"don't\", \"you\", \"agree\"},\n\t\t})\n\t\n\tif err != nil {\n\t\t// ... do your thing\n\t}\n\tfmt.Print(prettyPrintedTable)\n}\n```\n\nThe output will be:\n```markdown\n| column 1 | column 2 | column 3 |\n| -------- | -------- | -------- |\n| so       | much     | fun      |\n| don't    | you      | agree    |\n```\n\n### Sort\n\nSorting by columns is disabled by default.\nIt is available to all formatters.\n\n#### Alphabetical order\n\nWhen using `markdown.ASCENDING_ORDER` or `markdown.DESCENDING_ORDER`, the associated string comparison algorithm\nis applied to **every** column, in column order.\n\n##### Ascending order\n\n```go\ntable, err := markdown.NewTableFormatterBuilder().\n    WithAlphabeticalSortIn(markdown.ASCENDING_ORDER).\n    Build(\"column 1\", \"column 2\", \"column 3\").\n    Format([][]string{\n        {\"don't\", \"you\", \"know\"},\n        {\"so\", \"much\", \"fun\"},\n        {\"don't\", \"you\", \"agree\"},\n    })\n\nif err != nil { \n    // ... do your thing \n}\nfmt.Print(table)\n```\n\nThe output will be:\n```markdown\n| column 1 | column 2 | column 3 |\n| -------- | -------- | -------- |\n| don't | you | agree |\n| don't | you | know |\n| so | much | fun |\n```\n\n##### Descending order\n\n```go\ntable, err := markdown.NewTableFormatterBuilder().\n    WithAlphabeticalSortIn(markdown.DESCENDING_ORDER).\n    // ... same as above ...\n    \nfmt.Print(basicTable)\n```\n\nThe output will be:\n```markdown\n| column 1 | column 2 | column 3 |\n| -------- | -------- | -------- |\n| so | much | fun |\n| don't | you | know |\n| don't | you | agree |\n```\n\n#### Custom sort functions\n\nThere can be at most `N` custom sort functions (where `N` is the number of columns).\n\nIf the array is made of 3 columns e.g., \n\n```go\nWithAlphabeticalSortIn(markdown.ASCENDING_ORDER)\n```\n\nis effectively equivalent to:\n\n```go\nWithCustomSort(markdown.ASCENDING_ORDER.StringCompare(0),\n               markdown.ASCENDING_ORDER.StringCompare(1),\n               markdown.ASCENDING_ORDER.StringCompare(2))\n```\n\nThis is **not** the same as:\n\n```go\nWithCustomSort(markdown.ASCENDING_ORDER.StringCompare(0))\n```\n\nIndeed, providing a single function triggers a comparison between values of the specified column, the other columns' values\nare not compared.\n\nIn other words, the following program:\n\n```go\ntable, err := markdown.NewTableFormatterBuilder().\n    WithCustomSort(markdown.ASCENDING_ORDER.StringCompare(0)).\n    // equivalent to:\n    // WithCustomSort(\n    //  SortFunction{\n    //      Fn: func(a, b string) int {\n    //          // you can plug *any* logic here\n    //          return strings.Compare(a, b)\n    //      },\n    //      Column: 0,\n    // })\n    WithPrettyPrint().\n    Build(\"column 1\", \"column 2\", \"column 3\").\n    Format([][]string{\n        {\"don't\", \"you\", \"know\"},\n        {\"so\", \"much\", \"fun\"},\n        {\"don't\", \"you\", \"agree\"},\n    })\n\nif err != nil { \n    // ... do your thing \n}\n\nfmt.Print(table)\n```\n\n... will yield:\n```markdown\n| column 1 | column 2 | column 3 |\n| -------- | -------- | -------- |\n| don't    | you      | know     |\n| don't    | you      | agree    |\n| so       | much     | fun      |\n```\n\nThe order of custom sort function is the order of **execution**.\nYou are free to sort columns by any order:\n\n```go\ntable, err := markdown.NewTableFormatterBuilder().\n    // sort third column first, then first column\n    WithCustomSort(markdown.ASCENDING_ORDER.StringCompare(2), markdown.DESCENDING_ORDER.StringCompare(0)).\n    WithPrettyPrint().\n    Build(\"column 1\", \"column 2\", \"column 3\").\n    Format([][]string{\n        {\"don't\", \"you\", \"know\"},\n        {\"so\", \"much\", \"agree\"},\n        {\"don't\", \"you\", \"agree\"},\n    })\n\nif err != nil { \n    // ... do your thing \n}\n\nfmt.Print(table)\n```\n\n... will yield:\n\n```markdown\n| column 1 | column 2 | column 3 |\n| -------- | -------- | -------- |\n| so       | much     | agree    |\n| don't    | you      | agree    |\n| don't    | you      | know     |\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffbiville%2Fmarkdown-table-formatter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffbiville%2Fmarkdown-table-formatter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffbiville%2Fmarkdown-table-formatter/lists"}