CSVTransform for Node.js

IssuesGitHub

Callback API

The callback API transform all the records and buffers the results into a single dataset which is passed to a user provided function. As a consequence, the resulting dataset must fit into memory. It must be used only when the input source is not too big.

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

Example

In the callback example, the user function shift the cells of every records.

import { transform } from "stream-transform";
import assert from "node:assert";

transform(
  [
    ["1", "2", "3", "4"],
    ["a", "b", "c", "d"],
  ],
  function (record) {
    record.push(record.shift());
    return record;
  },
  function (err, output) {
    assert.deepEqual(output, [
      ["2", "3", "4", "1"],
      ["b", "c", "d", "a"],
    ]);
  },
);

This example is available with the command node samples/api.callback.js.

About

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