Skip to content

OpenINF/openinf-util-md-table

OpenINF logo

@openinf/util-md-table

Common Markdown table-related utilities


'View on npm' 'License: MIT/Apache-2.0'


The high-level goal of @openinf/util-md-table is to serve as a Node.js package containing utilities for common operations on Markdown tables allowing users to make use of them in new ways. We are constantly working to improve this repository, so please feel free to contribute if you notice any omissions or errors.

Thanks!


Platform: Node.js LTS

Supported Node.js Environments

  • v4:Argon (Ar)
  • v6:Boron (B)
  • v8:Carbon (C)
  • v10:Dubnium (Db)
  • v12:Erbium (Er)
  • v14:Fermium (Fm)
  • v16:Gallium (Ga)
  • v18:Hydrogen (H)

Code Style: Prettier Commit Style: Conventional Commits Chat on Matrix





Table of Contents





Installation Corepack logo


@openinf/util-md-table runs on supported versions of Node.js and is available via npm, pnpm, or yarn.

Using the npm CLI

See the official documentation for this command for more information.

npm i @openinf/util-md-table

Using the pnpm CLI

See the official documentation for this command for more information.

pnpm add @openinf/util-md-table

Using the Yarn 1 CLI (Classic)

See the official documentation for this command for more information.

yarn add @openinf/util-md-table

Usage

import { mdTbl2json } from '@openinf/util-md-table';

const sampleTable = [
  '| Col1  | Col2  | Col3  | Col4  |',
  '|:-----:|:-----:|:-----:|:-----:|',
  '| one   | two   | three | four  |',
  '| Fee   | Fie   | Foe   | Fum   |',
].join('\n');

const sampleTblObject = mdTbl2json(sampleTable, (v) => v.toLowerCase());

console.log(sampleTblObject);
[
  { col1: 'one', col2: 'two', col3: 'three', col4: 'four' },
  { col1: 'fee', col2: 'fie', col3: 'foe', col4: 'fum' }
]



API

Tip

This API will be deprecated in the next release in favor of one that follows Web Platform Design Principles.

mdTbl2json(mdTbl, cellTransform, attribCellTransform) ⇒ Array<Object>

Kind: global function

Param Type Description
mdTbl string A markdown table as a string.
cellTransform function | undefined A function run on contents of each cell.
attribCellTransform function | undefined A transform only for attribute cells.





Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. If for whatever reason you spot something to fix but cannot patch it yourself, please open an issue.


License

This project is licensed under either of

at your option.

The SPDX license identifier for this project is MIT OR Apache-2.0.





Show Your Support


If you like the project (or want to bookmark it) —
— give it a star ⭐️ — it will greatly encourage us.



The OpenINF logo