CSVParse for Node.js

IssuesGitHub

Option to

The to option handles records until a requested number of records. Count is 1-based, for example, provides 1 (and not 0) to emit first record.

Inferred column names

When the column option is active, the first record is treated as a header. It is not accounted as a record. Thus, the first record is used to retrieve the properties names and the count start after the next record.

This example read the first a,b record to determine column names, return the first two records and skip the records afterward.

import assert from 'node:assert';
import { parse } from 'csv-parse';

parse(`
a,b
1,2
3,4
5,6
`.trim(), {
  columns: true,
  to: 2
}, function(err, records){
  console.info(err, records);
  assert.deepStrictEqual(
    records, [{
      a: '1',
      b: '2'
    }, {
      a: '3',
      b: '4'
    }]
  );
});

About

The Node.js CSV project is an open source product hosted on GitHub and developed by Adaltas.