CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-csv-generate

CSV and object generation implementing the Node.js stream.Readable API

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

stream-generation.mddocs/

Stream Generation

Core streaming CSV generation using Node.js Readable streams for scalable, real-time data generation with comprehensive callback and event support.

Capabilities

Generate Function (Stream API)

Creates a new Generator instance for streaming CSV generation with optional callback support.

/**
 * Creates a new Generator instance for streaming CSV generation
 * @param options - Configuration options for generation
 * @param callback - Optional callback for collecting all generated data
 * @returns Generator instance extending stream.Readable
 */
function generate(options?: Options, callback?: Callback): Generator;

/**
 * Creates a new Generator instance with default options
 * @param callback - Callback for collecting all generated data  
 * @returns Generator instance extending stream.Readable
 */
function generate(callback?: Callback): Generator;

Usage Examples:

import { generate } from "csv-generate";

// Basic streaming with readable events
const generator = generate({
  columns: 3,
  length: 5,
  seed: 1
});

generator.on('readable', function() {
  let chunk;
  while ((chunk = generator.read()) !== null) {
    console.log(chunk.toString());
  }
});

generator.on('end', function() {
  console.log('Generation complete');
});

// Callback mode for collecting all data
generate({
  columns: 2,
  length: 3,
  objectMode: true
}, (err, records) => {
  if (err) throw err;
  console.log(records); // Array of objects
});

// String output callback mode
generate({
  columns: 2,
  length: 3
}, (err, csv) => {
  if (err) throw err;
  console.log(csv); // CSV string
});

Generator Class

Stream.Readable subclass providing CSV generation with full stream interface support.

/**
 * Generator class extending Node.js stream.Readable for CSV generation
 */
class Generator extends stream.Readable {
  /**
   * Create a new Generator instance
   * @param options - Configuration options for generation
   */
  constructor(options?: Options);
  
  /** Read-only access to the normalized options */
  readonly options: Options;
  
  /**
   * Manually stop the generation process
   * Pushes null to signal end of stream
   */
  end(): void;
}

Usage Examples:

import { Generator } from "csv-generate";

// Direct class instantiation
const generator = new Generator({
  columns: ['ascii', 'int', 'bool'],
  length: 10,
  seed: 42
});

// Pipe to destination
generator.pipe(process.stdout);

// Manual control
const gen = new Generator({
  columns: 2,
  objectMode: true
});

gen.on('data', (record) => {
  console.log('Generated record:', record);
  if (someCondition) {
    gen.end(); // Stop generation early
  }
});

Stream Events

Standard Node.js Readable stream events for handling generated data and lifecycle.

// Event handlers available on Generator instances
generator.on('readable', () => void);
generator.on('data', (chunk: Buffer | object) => void);
generator.on('end', () => void);
generator.on('error', (error: Error) => void);
generator.on('close', () => void);

Usage Examples:

const generator = generate({
  columns: 3,
  length: 100,
  objectMode: true
});

// Handle individual records
generator.on('data', (record) => {
  // Process each generated record
  processRecord(record);
});

// Handle completion
generator.on('end', () => {
  console.log('All records generated');
});

// Handle errors
generator.on('error', (err) => {
  console.error('Generation error:', err);
});

docs

configuration-options.md

index.md

stream-generation.md

synchronous-generation.md

web-streams-generation.md

tile.json