@origints/csv
CSV parsing with RFC 4180 support, header detection, predicate-based column lookup, and row filtering.
Installation
Section titled “Installation”npm install @origints/csv @origints/coreFeatures
Section titled “Features”- RFC 4180 support (quoted fields, embedded newlines)
- Header row detection and column-by-name access
- Predicate-based column lookup (
colWhere) - Row filtering (
rowsWhere) and row search (findRow) - Type coercion (number, boolean) on demand
- Custom delimiters, quote characters, comments, and trim
Usage with Planner
Section titled “Usage with Planner”Extract values from specific cells
Section titled “Extract values from specific cells”import { Planner, loadFile, run } from '@origints/core'import { parseCsv } from '@origints/csv'
const plan = new Planner() .in(loadFile('users.csv')) .mapIn(parseCsv({ header: true })) .emit((out, $) => out .add('firstName', $.row(0).col('name').string()) .add('firstAge', $.row(0).col('age').number()) ) .compile()
const result = await run(plan, { readFile, registry })// result.value: { firstName: 'Alice', firstAge: 30 }Iterate over all rows
Section titled “Iterate over all rows”const plan = new Planner() .in(loadFile('users.csv')) .mapIn(parseCsv({ header: true })) .emit((out, $) => out .add('users', $.rows(row => ({ kind: 'object', properties: { name: row.col('name').string(), age: row.col('age').number(), active: row.col('active').boolean(), }, }))) ) .compile()Column lookup by predicate
Section titled “Column lookup by predicate”Find a column by matching its header:
import { col } from '@origints/csv'
$.rows(row => ({ kind: 'object', properties: { revenue: row.colWhere(col.contains('Revenue')).number(), name: row.colWhere(col.equals('Company Name')).string(), },}))Filter rows by predicate
Section titled “Filter rows by predicate”import { rowCol, col } from '@origints/csv'
$.rowsWhere( rowCol('status', col.equals('active')), row => ({ kind: 'object', properties: { name: row.col('name').string(), dept: row.colWhere(col.contains('department')).string(), }, }))Find a specific row
Section titled “Find a specific row”import { rowCol, col } from '@origints/csv'
$.findRow(rowCol('id', col.equals('ABC-123'))).col('email').string()String predicates
Section titled “String predicates”import { col } from '@origints/csv'
col.equals('Revenue') // exact matchcol.contains('rev') // substring (case-insensitive)col.startsWith('Total') // prefixcol.endsWith('USD') // suffixcol.matches(/^Q[1-4] \d{4}$/) // regexcol.isEmpty() // empty stringcol.isNotEmpty() // non-empty
// Compositioncol.contains('revenue').and(col.startsWith('total'))col.equals('A').or(col.equals('B'))col.isEmpty().not()Standalone usage
Section titled “Standalone usage”import { parseCsvText } from '@origints/csv'
const table = parseCsvText('name,age\nAlice,30\nBob,25', { header: true })
for (const row of table) { const name = row.col('name') if (name.ok) console.log(name.value)}| Export | Description |
|---|---|
parseCsv(options?) | Transform AST for Planner.mapIn() |
parseCsvText(input, options?) | Parse CSV string directly |
registerCsvTransforms(registry) | Register CSV transforms |
CsvTable | Table with row/column/cell access |
CsvRow | Row with field access and type coercion |
toJson(table, options?) | Convert to JSON |
col | String predicate factory |
rowCol, rowAt | Row predicate factories |
License
Section titled “License”MIT