Module: lib/generator

The gateway API for the entire script. Import this module into your own scripts to generate CSV data on-the-fly.

This function opens a fs stream and writes to the CSV file m records at a time. This can be controlled by setting options.chunks to a positive integer value.

Parameters:
Name Type Attributes Description
name string

The name of the output file.

columns Array.<string>

An array of functions to execute for each cell.

options object

Options to pass the function.

headers Array.<string> <optional>

An array of headers to add as the first row of the generated table.

Properties:
Name Type Description
options.headers string | Array.<string>

The headers to output as the first row of the CSV file.

options.rows number

The number of rows to generate as an integer.

options.chunks number

The number of rows to generate in one pass.

options.silent boolean

Set true to disable console output.

Version:
  • 1.0.0
Author:
Source:
Returns:

A Promise that is resolved then the stream closes.

Type
Promise
Example
const csvgen = require('csv-generator');
csvgen('foo.csv', ['name'], { rows: 10**6 });