CSVTransform for Node.js


Sync API

Table of Contents

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.


The sync example illustrates how to use this API.

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

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

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