https://github.com/75lb/gfmt
A use-anywhere, github-flavoured-markdown table generator.
https://github.com/75lb/gfmt
github-flavored-markdown javascript markdown table text-formatting
Last synced: 8 months ago
JSON representation
A use-anywhere, github-flavoured-markdown table generator.
- Host: GitHub
- URL: https://github.com/75lb/gfmt
- Owner: 75lb
- License: mit
- Created: 2015-06-21T22:27:03.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2025-05-11T14:29:10.000Z (11 months ago)
- Last Synced: 2025-06-12T07:00:56.972Z (10 months ago)
- Topics: github-flavored-markdown, javascript, markdown, table, text-formatting
- Language: JavaScript
- Homepage:
- Size: 152 KB
- Stars: 10
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.hbs
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.npmjs.org/package/gfmt)
[](https://www.npmjs.org/package/gfmt)
[](https://github.com/75lb/gfmt/network/dependents?dependent_type=REPOSITORY)
[](https://github.com/75lb/gfmt/network/dependents?dependent_type=PACKAGE)
[](https://github.com/75lb/gfmt/actions/workflows/node.js.yml)
[](https://github.com/feross/standard)
# gfmt
A use-anywhere, github-flavoured-markdown table generator. Useful in markdown generators or for presenting table data in the terminal.
## Synopsis
Where `example/simple.json` looks like this:
```
[
{ "date": "10 Jun 2015", "downloads": 100 },
{ "date": "11 Jun 2015", "downloads": 120 },
{ "date": "12 Jun 2015", "downloads": 150 },
{ "date": "13 Jun 2015", "downloads": 120 },
{ "date": "14 Jun 2015", "downloads": 110 }
]
```
this command:
```sh
$ cat example/simple.json | gfmt
```
produces this output:
```
| date | downloads |
| ----------- | --------- |
| 10 Jun 2015 | 100 |
| 11 Jun 2015 | 120 |
| 12 Jun 2015 | 150 |
| 13 Jun 2015 | 120 |
| 14 Jun 2015 | 110 |
```
This command pipes cherry-picked fields from a github repo list into `gfmt`:
```sh
$ curl -s "https://api.github.com/users/jsdoc2md/repos" \
| jq 'map({repo:.name, stars:.stargazers_count, forks:.forks_count, issues:.open_issues_count}) | sort_by(.stargazers_count) | reverse' \
| gfmt
```
produces this output:
```
| repo | stars | forks | issues |
| ----------------------- | ----- | ----- | ------ |
| jsdoc-to-markdown | 133 | 20 | 18 |
| jsdoc-parse | 26 | 8 | 4 |
| jsdoc | 0 | 1 | 0 |
| gulp-jsdoc-to-markdown | 6 | 2 | 0 |
| grunt-jsdoc-to-markdown | 12 | 2 | 1 |
| ddata | 0 | 2 | 2 |
| dmd-locale-en-gb | 0 | 0 | 0 |
| dmd-bitbucket | 0 | 1 | 0 |
| dmd | 13 | 10 | 5 |
| dhtml | 0 | 0 | 0 |
| dmd-plugin-example | 0 | 1 | 0 |
```
## Install
As a library:
```
$ npm install gfmt --save
```
As a command-line tool:
```
$ npm install -g gfmt
```
Run `gfmt --help` to see the command-line options.
## API Reference
A use-anywhere, github-flavoured-markdown table generator.
### gfmTable(data, [options]) ⇒ string ⏏
Get a github-flavoured-markdown table instance
**Kind**: Exported function
| Param | Type | Description |
| --- | --- | --- |
| data | object | Array.<object> | the input data |
| [options] | object | |
| [options.columns] | Array.<object> | column definitions |
| [options.wrap] | boolean | wrap to fit into width |
| [options.width] | boolean | table width |
| [options.ignoreEmptyColumns] | boolean | table width |
**Example**
```js
> gfmt = require("gfmt")
> table = gfmt([
{ "date": "10 Jun 2015", "downloads": 100 },
{ "date": "11 Jun 2015", "downloads": 120 },
{ "date": "12 Jun 2015", "downloads": 150 },
{ "date": "13 Jun 2015", "downloads": 120 },
{ "date": "14 Jun 2015", "downloads": 110 }
])
> console.log(table.getTable())
| date | downloads |
| ----------- | --------- |
| 10 Jun 2015 | 100 |
| 11 Jun 2015 | 120 |
| 12 Jun 2015 | 150 |
| 13 Jun 2015 | 120 |
| 14 Jun 2015 | 110 |
```
* * *
© 2015-25 Lloyd Brookes \. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).