Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
The fast-csv npm package is a comprehensive library for working with CSV data in Node.js. It provides functionalities for parsing CSV files and strings, formatting data to CSV, and transforming data during the parse and format process.
Parsing CSV
This feature allows you to parse CSV files or strings. The code sample demonstrates how to read a CSV file using a stream, parse it with headers, and log each row to the console.
const fs = require('fs');
const fastcsv = require('fast-csv');
fs.createReadStream('data.csv')
.pipe(fastcsv.parse({ headers: true }))
.on('data', row => console.log(row))
.on('end', () => console.log('CSV file successfully processed'));
Formatting Data to CSV
This feature allows you to format JavaScript data arrays or streams to CSV. The code sample shows how to take an array of objects and write it to a CSV file with headers.
const fs = require('fs');
const fastcsv = require('fast-csv');
const data = [{ id: 1, name: 'John Doe' }, { id: 2, name: 'Jane Doe' }];
fastcsv
.write(data, { headers: true })
.pipe(fs.createWriteStream('out.csv'))
.on('finish', () => console.log('Write to out.csv successfully!'));
Transforming Data
This feature allows you to transform data during the parse or format process. The code sample demonstrates how to read a CSV file, transform each row by combining first and last names into a full name, and then write the transformed data to a new CSV file.
const fs = require('fs');
const fastcsv = require('fast-csv');
fs.createReadStream('data.csv')
.pipe(fastcsv.parse({ headers: true }))
.transform(row => ({ fullName: row.firstName + ' ' + row.lastName }))
.pipe(fastcsv.format({ headers: true }))
.pipe(fs.createWriteStream('out.csv'))
.on('finish', () => console.log('Transformed file successfully written.'));
PapaParse is a robust and powerful CSV parser for JavaScript with a similar feature set to fast-csv. It supports browser and server-side parsing, auto-detection of delimiters, and stream parsing. Compared to fast-csv, PapaParse has a stronger emphasis on browser-side parsing and provides a more user-friendly configuration for handling large files in the browser.
csv-parser is a Node.js module for parsing CSV data. It can handle large datasets and supports stream-based processing. While fast-csv offers both parsing and formatting capabilities, csv-parser focuses primarily on parsing CSV data and may be preferred for its simplicity when only parsing functionality is needed.
csv-writer is a CSV writing library for Node.js that provides functionality to serialize arrays and objects into CSV files. Unlike fast-csv, which offers both parsing and formatting, csv-writer is specialized for CSV output, making it a good choice if the primary requirement is to generate CSV files from data.
fast-csv
Package that combines both @fast-csv/format
and @fast-csv/parse
into a single package.
To get started with fast-csv
check out the docs
FAQs
CSV parser and writer
We found that fast-csv demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.