https://github.com/artdecocode/tablature
Display Tabular Data For CLI Apps.
https://github.com/artdecocode/tablature
Last synced: about 2 months ago
JSON representation
Display Tabular Data For CLI Apps.
- Host: GitHub
- URL: https://github.com/artdecocode/tablature
- Owner: artdecocode
- License: mit
- Created: 2018-06-14T11:53:21.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-08-01T21:48:19.000Z (over 6 years ago)
- Last Synced: 2025-02-25T15:51:55.903Z (11 months ago)
- Language: JavaScript
- Homepage:
- Size: 90.8 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# tablature
[](https://npmjs.org/package/tablature)
`tablature` Will Display Data In A Table In CLI.
```sh
yarn add tablature
```
## Table Of Contents
- [Table Of Contents](#table-of-contents)
- [API](#api)
- [`tablature(config: Config): string`](#tablatureconfig-config-string)
* [`Replacement`](#type-replacement)
* [`Config`](#type-config)
* [Replacement](#replacement)
- [Copyright](#copyright)
## API
The package is available by importing its default function:
```js
import tablature from 'tablature'
```
## `tablature(`
`config: Config,`
`): string`
Returns a string representation of data as a table.
`(value: string) => {value: string, length: number}` __`Replacement`__: The function to use to replace values for display.
__`Config`__: Options for the program.
Name
Type & Description
keys*
!Array<string>
Keys to print as columns.
data*
!Array<!Object<string, string>>
The array of data items to prints as rows.
headings
!Object<string, string>
The display names for each column.
replacements
!Object<string, Replacement>
The map of replacement functions which will run against data items.
centerValues
!Array<string>
Centre values of these column (use original keys, not headings).
centerHeadings
!Array<string>
Center headings of these column (use original keys, not headings).
SourceOutput
```js
import tablature from 'tablature'
const DATA = [
{
name: 'hello',
when: 'yesterday',
},
{
name: 'world',
when: 'now',
},
]
const res = tablature({
keys: ['name', 'when'],
data: DATA,
centerValues: ['when'],
centerHeadings: ['when'],
headings: {
name: 'Name',
when: 'When',
},
})
console.log(res)
```
```
Name When
hello yesterday
world now
```
### Replacement
A replacement function must return an object containing `value` and `length` property. When replacements are not given, the ANSI codes are removed by _Tablature_, however, the replacement must always return the value along with its length.
```js
const isEnabled = (value) => {
if (value == 'ENABLED') return { value: `\x1b[32mOK\x1b[0m`, length: 2 }
if (value == 'NOTPRESENT') return { value: `\x1b[31m--\x1b[0m`, length: 2 }
return { value, length: value.length }
}
const replacements = {
enabled: isEnabled,
}
```
## Copyright
© Art Deco 2019
Tech Nation Visa Sucks