An open API service indexing awesome lists of open source software.

https://github.com/openinf/openinf-util-md-table

Common Markdown table-related utilities
https://github.com/openinf/openinf-util-md-table

commonjs commonjs-module commonjs-package helpers helpers-library javascript javascript-library json markdown nodejs nodejs-module npm npm-package table typescript typescript-library typescript-package utilities

Last synced: 8 months ago
JSON representation

Common Markdown table-related utilities

Awesome Lists containing this project

README

          


OpenINF logo

## `@openinf/util-md-table`

> Common Markdown table-related utilities


[!['View on npm'][npm-badge--shields]][npm-badge-url]
[!['License: MIT/Apache-2.0'][license-badge--shields]][license-badge-url]


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](#contributing) 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)
- [x] v14:Fermium (Fm)
- [x] v16:Gallium (Ga)
- [x] v18:Hydrogen (H)


[![Code Style: Prettier][prettier-badge]][prettier-url]
[![Commit Style: Conventional Commits][conventional-commits-badge]][conventional-commits-url]
[![Chat on Matrix][matrix-badge--shields]][matrix-url]



---


### Table of Contents

- [Installation](#installation)
- [Usage](#usage)
- [API](#api)
- [Contributing](#contributing)
- [License](#license)



---



Installation Corepack logo


`@openinf/util-md-table` runs on
[supported versions of Node.js](#platform--node-js-lts) and is available via
**`npm`**, **`pnpm`**, or **`yarn`**.

**Using the npm CLI**

See the
[official documentation for this command](https://docs.npmjs.com/cli/commands/npm-install)
for more information.

```shell
npm i @openinf/util-md-table
```

**Using the pnpm CLI**

See the [official documentation for this command](https://pnpm.io/cli/add)
for more information.

```shell
pnpm add @openinf/util-md-table
```

**Using the Yarn 1 CLI (Classic)**

See the
[official documentation for this command](https://classic.yarnpkg.com/en/docs/cli/add)
for more information.

```shell
yarn add @openinf/util-md-table
```


### Usage

```ts
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);
```

```console
[
{ 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](https://github.com/OpenINF/openinf-util-md-table/issues/187).

#### 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

- [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0)
- [MIT license](https://opensource.org/licenses/MIT)

at your option.

The [SPDX](https://spdx.dev) 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

[conventional-commits-badge]: https://img.shields.io/badge/commit%20style-Conventional-%23fa6673?logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzMCAzMCI+PHBhdGggc3R5bGU9ImZpbGw6ICNGRkYiIGQ9Ik0xNSwyQTEzLDEzLDAsMSwxLDIsMTUsMTMsMTMsMCwwLDEsMTUsMm0wLTJBMTUsMTUsMCwxLDAsMzAsMTUsMTUsMTUsMCwwLDAsMTUsMFoiLz48L3N2Zz4K 'Commit Style: Conventional Commits'
[conventional-commits-url]: https://www.conventionalcommits.org 'Commit Style: Conventional Commits'
[give it a star ⭐️]: https://github.com/OpenINF/openinf-util-md-table/stargazers
[license-badge--shields]: https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg?logo=github 'License: MIT/Apache 2.0'
[license-badge-url]: #license 'License: MIT/Apache 2.0'
[matrix-badge--shields]: https://img.shields.io/badge/matrix-join%20chat-%2346BC99?logo=matrix 'Chat on Matrix'
[matrix-url]: https://matrix.to/#/#openinf-space:matrix.org 'You're invited to talk on Matrix'
[npm-badge--shields]: https://img.shields.io/npm/v/@openinf/util-md-table/latest.svg?logo=npm&color=fe7d37 'View on npm'
[npm-badge-url]: https://www.npmjs.com/package/@openinf/util-md-table#top 'View on npm'
[open an issue]: https://github.com/OpenINF/openinf-util-md-table/issues
[prettier-badge]: https://img.shields.io/badge/code_style-Prettier-ff69b4.svg?logo=prettier 'Code Style: Prettier'
[prettier-url]: https://prettier.io/playground 'Code Style: Prettier'
[project-status-badge]: https://img.shields.io/badge/project%20status-under%20construction-orange 'Project Status: Under construction badge'