CSVTransform for Node.js

IssuesGitHub

Sync API

If you input and output datasets are not too large and fit into memory, the sync API provides a convenient function to transform your data.

The signature is const records = transform(records, [options], handler).

Due to its synchronous nature, not all options are honoured. The user handler function must only be written in synchronous mode, with expecting a callback in its second argument.

Example

The sync example illustrates how to use this API.

import { transform } from 'stream-transform/sync';
import assert from 'node:assert';

const records = transform([
  [ 'a', 'b', 'c', 'd' ],
  [ '1', '2', '3', '4' ]
], function(record){
  record.push(record.shift());
  return record;
});

assert.deepEqual(records, [
  [ 'b', 'c', 'd', 'a' ],
  [ '2', '3', '4', '1' ]
]);

About

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