パッケージの詳細

tablature

artdecocode11MIT1.2.0

Display Tabular Data.

tablature, table

readme

tablature

npm version

tablature Will Display Data In A Table In CLI.

yarn add tablature

Table Of Contents

API

The package is available by importing its default function:

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.

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 © Art Deco 2019 Tech Nation Visa Tech Nation Visa Sucks

更新履歴

2 August 2019

1.2.0

  • [package] Compile with Depack.

15 May 2019

1.1.1

  • [fix] Work with non-string data.

3 February 2019

1.1.0

  • [feature] Strip ansii if no replacement is given.
  • [feature] Support new lines.
  • [package] Upgrade structure to ÀLaMode.
  • [package] Export module field.

14 June 2018

1.0.0