Sync API
The sync API behave like pure functions. For a given input, it always produce the same output.
Because of its simplicity, this is the recommended approach if you don't need scalability and if your dataset fit in memory.
The module to import is csv/sync
. The sync example illustrate its usage.
import assert from "node:assert";
import { generate, parse, transform, stringify } from "csv/sync";
const input = generate({ seed: 1, columns: 2, length: 2 });
const rawRecords = parse(input);
const refinedRecords = transform(rawRecords, (data) =>
data.map((value) => value.toUpperCase())
);
const output = stringify(refinedRecords);
assert.equal(output, `OMH,ONKCHHJMJADOA\nD,GEACHIN\n`);