-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.hbs
121 lines (100 loc) · 3.93 KB
/
README.hbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
[![view on npm](https://badgen.net/npm/v/gfmt)](https://www.npmjs.org/package/gfmt)
[![npm module downloads](https://badgen.net/npm/dt/gfmt)](https://www.npmjs.org/package/gfmt)
[![Gihub repo dependents](https://badgen.net/github/dependents-repo/75lb/gfmt)](https://github.com/75lb/gfmt/network/dependents?dependent_type=REPOSITORY)
[![Gihub package dependents](https://badgen.net/github/dependents-pkg/75lb/gfmt)](https://github.com/75lb/gfmt/network/dependents?dependent_type=PACKAGE)
[![Build Status](https://travis-ci.org/75lb/gfmt.svg?branch=master)](https://travis-ci.org/75lb/gfmt)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](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.
<a name="exp_module_gfmt--gfmTable"></a>
### gfmTable(data, [options]) ⇒ <code>string</code> ⏏
Get a github-flavoured-markdown table instance
**Kind**: Exported function
| Param | Type | Description |
| --- | --- | --- |
| data | <code>object</code> | <code>Array.<object></code> | the input data |
| [options] | <code>object</code> | |
| [options.columns] | <code>Array.<object></code> | column definitions |
| [options.wrap] | <code>boolean</code> | wrap to fit into width |
| [options.width] | <code>boolean</code> | table width |
| [options.ignoreEmptyColumns] | <code>boolean</code> | 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-21 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).