https://github.com/codedotjs/omd
:feather: :feet: Convert arrays and objects to Markdown tables.
https://github.com/codedotjs/omd
Last synced: 9 months ago
JSON representation
:feather: :feet: Convert arrays and objects to Markdown tables.
- Host: GitHub
- URL: https://github.com/codedotjs/omd
- Owner: CodeDotJS
- License: mit
- Created: 2024-05-27T07:24:44.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-05-31T06:42:22.000Z (over 1 year ago)
- Last Synced: 2025-03-20T00:41:18.709Z (9 months ago)
- Language: JavaScript
- Homepage: https://omd.vercel.app/
- Size: 52.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# omd
:feather: :feet: Convert arrays and objects to Markdown tables.
## Install
```
npm install ohmd
```
## API
### `omd(data, options)`
- `data`: The data to be converted into a Markdown table. It can be:
- A single array.
- An object with header and table properties.
- A 2D array where the first sub-array is the header and the remaining sub-arrays are the table rows.
- `options`: Configuration options for the table formatting. It's optional.
- `align` - Specifies the alignment for each column. Valid values are `left`, `center`, and `right`. If not provided, the default alignment is used.
### Examples
- __Markdown for a single array:__
```js
const omd = require('ohmd');
const arrayData = ['Jon', 'Doe'];
console.log(omd(arrayData));
// | --- |
// | Jon |
// | Doe |
```
```js
console.log(omd(arrayData, { align: ['left'] }));
// | :--- |
// | Jon |
// | Doe |
```
- __Markdown for an object with different alignments:__
```js
const objectData = {
header: ['Day', 'Rank', 'Grade'],
table: [['Tuesday', 7, "C Minus"], ['Friday', 1, "A Plus"], ['Dryday', 4, "B Minus"]],
};
console.log(omd(objectData, { align: ['left', 'center', 'right'] }));
// | Day | Rank | Grade |
// | :--- | :---: | ---: |
// | Tuesday | 7 | C Minus |
// | Friday | 1 | A Plus |
// | Dryday | 4 | B Minus |
```
- __Markdown for an object with no header:__
```js
const objectWithoutHeader = {
"table": [
["Alice", 30, "New York"],
["Bob", 25, "San Francisco"],
["Charlie", 35, "Los Angeles"]
]
}
// | Alice | 30 | New York |
// | Bob | 25 | San Francisco |
// | Charlie | 35 | Los Angeles |
```
- __Markdown for an object with single alignment:__
```js
console.log(omd(objectData, { align: ['center'] }));
// | Day | Rank | Grade |
// | :---: | :---: | :---: |
// | Tuesday | 7 | C Minus |
// | Friday | 1 | A Plus |
// | Dryday | 4 | B Minus |
```
- __Markdown for a 2D array with different alignments:__
```js
const twoDArrayData = [
['name', 'class', 'number'],
['Jon', 7, 99],
['Ron', 13, 233],
['Akon', 12, 13],
];
console.log(omd(twoDArrayData, { align: ['center', 'left', 'right'] }));
// | name | class | number |
// | :---: | :--- | ---: |
// | Jon | 7 | 99 |
// | Ron | 13 | 233 |
// | Akon | 12 | 13 |
```
- __Markdown for a 2D array with single alignment:__
```js
console.log(omd(twoDArrayData, { align: ['center'] }));
// | name | class | number |
// | :---: | :---: | :---: |
// | Jon | 7 | 99 |
// | Ron | 13 | 233 |
// | Akon | 12 | 13 |
```
# Contributing
If you find any bugs or have suggestions for improvements, please feel free to submit a pull request or open an issue.
# License
[MIT](LICENSE)