space-log

1.1.0 • Public • Published

🛸 Space Log

Space Log is a simple function which logs tabular data, similar to that of yarn outdated.

Regions of Japan

How to use Space Log?

Space Log exposes a function, spaceLog, which can be imported as a named or default export. Both commonJS and ESM are supported.

The spaceLog function has two arguments;

  • config.columnKeys: An array of keys, i.e. the data[key] of each column.

  • config.headings: An optional array of headings, i.e. the title of each column. If no headings are provided, only the data will be output.

  • data: An array of objects containing the data to log.

    • A "theme" can be provided for a corresponding key by adding a property in the format ${key}Theme. In the code below, populationTheme uses chalk to render green text to indicate that the most populous region of Japan is Kantō.
import chalk from chalk
import { spaceLog } from 'space-log'

spaceLog({
  columnKeys: ['name', 'population', 'area'],
  headings: ['Region', 'Population', 'Area (km²)'],
}, [
  { name: 'Hokkaidō', population: '5.4 million', area: '83,000', areaTheme: chalk.green },
  { name: 'Tōhoku', population: '8.9 million', area: '67,000' },
  { name: 'Kantō', population: '43.3 million', area: '32,000', populationTheme: chalk.green },
  { name: 'Chūbu', population: '21.4 million', area: '67,000' },
  { name: 'Kansai', population: '22.5 million', area: '33,000' },
  { name: 'Chūgoku', population: '7.3 million', area: '32,000' },
  { name: 'Shikoku', population: '3.8 million', area: '19,000' },
  { name: 'Kyūshū & Okinawa', population: '14 million', area: '44,000' },
])

Package Sidebar

Install

npm i space-log

Weekly Downloads

1

Version

1.1.0

License

ISC

Unpacked Size

6.67 kB

Total Files

4

Last publish

Collaborators

  • patchfalcon