md-table-parser
v0.0.1
Published
Parse markdown tables into structured data
Readme
md-table-parser
Parse markdown tables into structured data
Install
$ npm install md-table-parserUsage
import { parseMdTable, parseMdTables } from 'md-table-parser'
const md = `
# Users
Monthly member snapshot.
| Name | Age | City |
| ----- | --- | ------ |
| Alice | 30 | Tokyo |
| Bob | 25 | Osaka |
# Cities
Population reference:
| City | Country |
| ----- | ------- |
| Tokyo | Japan |
| Paris | France |
`
const table = parseMdTable(md)
// {
// headers: ['Name', 'Age', 'City'],
// rows: [
// ['Alice', '30', 'Tokyo'],
// ['Bob', '25', 'Osaka'],
// ],
// }
const tables = parseMdTables(md)
// [
// {
// headers: ['Name', 'Age', 'City'],
// rows: [
// ['Alice', '30', 'Tokyo'],
// ['Bob', '25', 'Osaka'],
// ],
// },
// {
// headers: ['City', 'Country'],
// rows: [
// ['Tokyo', 'Japan'],
// ['Paris', 'France'],
// ],
// },
// ]As objects
import { parseMdTableToObjects, parseMdTablesToObjects } from 'md-table-parser'
const objects = parseMdTableToObjects(md)
// [
// { Name: 'Alice', Age: '30', City: 'Tokyo' },
// { Name: 'Bob', Age: '25', City: 'Osaka' },
// ]
const allObjects = parseMdTablesToObjects(md)
// [
// [
// { Name: 'Alice', Age: '30', City: 'Tokyo' },
// { Name: 'Bob', Age: '25', City: 'Osaka' },
// ],
// [
// { City: 'Tokyo', Country: 'Japan' },
// { City: 'Paris', Country: 'France' },
// ],
// ]License
MIT
