table-parser-base
v0.0.5
Published
Utilities for table parser packages
Downloads
6,513
Readme
Table Parser Base
Utilities for table parser packages
Usage
Convert an ArrayTable
to an ObjectTable
const { createObjectTable } = await import('table-parser-base')
const arrayTable = {
headers: ['id', 'name', 'email'],
rows: [
[1, 'John Doe', '[email protected]'],
[2, 'Peter Smith', '[email protected]'],
[3, 'Julia Jones', '[email protected]']
]
}
const objectTable = createObjectTable(arrayTable)
for await (const item of objectTable) {
console.log(item)
}
Output:
{ id: 1, name: 'John Doe', email: '[email protected]' }
{ id: 2, name: 'Peter Smith', email: '[email protected]' }
{ id: 3, name: 'Julia Jones', email: '[email protected]' }
Convert an ObjectTable
to an ArrayTable
const { createArrayTable } = await import('table-parser-base')
const objectTable = [
{ id: 1, name: 'John Doe', email: '[email protected]' },
{ id: 2, name: 'Peter Smith', email: '[email protected]' },
{ id: 3, name: 'Julia Jones', email: '[email protected]' }
]
const arrayTable = await createArrayTable(objectTable)
console.log(arrayTable)
Output:
{
headers: [ 'id', 'name', 'email' ],
rows: [
[ 1, 'John Doe', '[email protected]' ],
[ 2, 'Peter Smith', '[email protected]' ],
[ 3, 'Julia Jones', '[email protected]' ]
]
}