Table Parser Base Utilities
table-parser-base is a lightweight JavaScript utility library designed to facilitate the transformation of tabular data structures. Primarily, it offers functions to convert between an `ArrayTable` format (an object with separate `headers` and `rows` arrays) and an `ObjectTable` format (an array of objects, where each object represents a row). Currently at version 0.0.5, the package is in a very early stage of development, implying an ad-hoc release cadence without a fixed schedule and potential for rapid iteration on its API. Its core differentiation lies in providing simple, focused, and stream-capable utilities for these specific table data model conversions, often serving as foundational components for broader data parsing or manipulation pipelines. It emphasizes an asynchronous, iterable approach for processing object tables, which is suitable for potentially large datasets.
Common errors
-
SyntaxError: Cannot use import statement outside a module
cause You are attempting to use an ES Module `import` statement in a CommonJS context (e.g., a `.js` file without `"type": "module"` in `package.json` or a `.cjs` file).fixConfigure your project to use ES Modules by adding `"type": "module"` to your `package.json` file, or ensure the file containing the import is named with a `.mjs` extension. Alternatively, run Node.js with `--input-type=module`. -
TypeError: createObjectTable is not a function
cause This usually indicates an incorrect import, a misspelling, or attempting to destructure from the `require()` call which is not supported for ESM-only packages, or not `await`ing the dynamic import.fixVerify that `import { createObjectTable } from 'table-parser-base'` is correctly written. If using dynamic imports, ensure it's `const { createObjectTable } = await import('table-parser-base')` within an `async` function or at the top level of an ES Module.
Warnings
- breaking As a pre-1.0.0 package (version 0.0.5), `table-parser-base` does not adhere to semantic versioning strictly. Any minor or patch release can introduce breaking changes without prior notice, leading to unexpected behavior or API shifts.
- gotcha This package is exclusively designed for ES Module (ESM) environments. Attempting to use it with CommonJS `require()` syntax will result in errors.
- gotcha The API surface of `table-parser-base` is considered volatile due to its early development stage. Function signatures, names, or overall structure might change in future versions without extensive deprecation cycles.
Install
-
npm install table-parser-base -
yarn add table-parser-base -
pnpm add table-parser-base
Imports
- createObjectTable
const { createObjectTable } = require('table-parser-base')import { createObjectTable } from 'table-parser-base' - createArrayTable
const createArrayTable = require('table-parser-base').createArrayTableimport { createArrayTable } from 'table-parser-base'
Quickstart
import { createObjectTable } from 'table-parser-base'
const arrayTable = {
headers: ['id', 'name', 'email'],
rows: [
[1, 'John Doe', 'john-doe@gmail.com'],
[2, 'Peter Smith', 'petersmith22@outlook.com'],
[3, 'Julia Jones', 'jjones778@gmail.com']
]
}
async function processTable() {
const objectTable = await createObjectTable(arrayTable)
console.log('--- Converted to ObjectTable ---')
for await (const item of objectTable) {
console.log(item)
}
}
processTable()