parse-markdown-table
v0.0.6
Published
Convert a markdown table from text to JavaScript objects
Downloads
6,529
Readme
Parse Markdown Table
Convert a markdown table from text to JavaScript objects
Usage
ArrayTable
const { createMarkdownArrayTable } = await import('parse-markdown-table')
const markdown = `
| id | name | email |
|----|-------------|--------------------------|
| 1 | John Doe | [email protected] |
| 2 | Peter Smith | [email protected] |
| 3 | Julia Jones | [email protected] |
`
// this function can take string, string[], Iterable<string>, and AsyncIterable<string>
const table = await createMarkdownArrayTable(markdown)
console.info('headers', table.headers)
for await (const row of table.rows) {
console.info('row', row)
}
Output:
headers [ 'id', 'name', 'email' ]
row [ '1', 'John Doe', '[email protected]' ]
row [ '2', 'Peter Smith', '[email protected]' ]
row [ '3', 'Julia Jones', '[email protected]' ]
ObjectTable
const { createMarkdownObjectTable } = await import('parse-markdown-table')
const markdown = `
| id | name | email |
|----|-------------|--------------------------|
| 1 | John Doe | [email protected] |
| 2 | Peter Smith | [email protected] |
| 3 | Julia Jones | [email protected] |
`
// this function can take string, string[], Iterable<string>, or AsyncIterable<string>
const table = createMarkdownObjectTable(markdown)
for await (const row of table) {
console.info('row', row)
}
Output:
row { id: '1', name: 'John Doe', email: '[email protected]' }
row { id: '2', name: 'Peter Smith', email: '[email protected]' }
row { id: '3', name: 'Julia Jones', email: '[email protected]' }