Function csvParseStream

  • Parse a Readable stream of CSV lines into an array of objects.

    Parameters

    • stream: Readable

      The Readable stream of CSV lines.

    • options: Options

      The options to pass to the CSV parser.

    Returns Promise<Record<string, string>[]>

    An array of objects, where each object represents a row in the CSV.

    Example

    // parse a CSV file
    const stream = fs.createReadStream('data.csv');
    const options = { separator: ';', strict: true };
    const data = await csvParseStream(stream, options);
    // parse a CSV string
    const stream = new StringSteam('Name;Age;Country\nJohn;25;USA\nAlice;30;Canada\n');
    const options = { separator: ';', strict: true };
    const data = await csvParseStream(stream, options);
    //=> [{Name:'John',Age:'25',Country:'USA'},{Name:'Alice',Age:'30',Country:'Canada'}]

Generated using TypeDoc