Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
csv-parse
Advanced tools
The csv-parse package is a flexible Node.js library that provides a parser converting CSV text input into arrays or objects. It implements the Node.js stream.Transform API. It is also capable of converting large datasets and supports many advanced features such as streaming and asynchronous processing.
Parsing CSV to Arrays
This feature allows you to parse CSV data into arrays. Each row in the CSV data becomes an array.
const parse = require('csv-parse');
const assert = require('assert');
const input = 'a,b,c\nd,e,f';
parse(input, function(err, output){
assert.deepEqual(output, [['a', 'b', 'c'], ['d', 'e', 'f']]);
});
Parsing CSV with Column Mapping
This feature allows you to map CSV columns to object properties, so each row in the CSV data becomes an object with named properties.
const parse = require('csv-parse');
const assert = require('assert');
const input = 'a,b,c\nd,e,f';
const parser = parse({columns: true}, function(err, records){
assert.deepEqual(records, [{a: 'd', b: 'e', c: 'f'}]);
});
parser.write(input);
parser.end();
Asynchronous Iteration
This feature allows for asynchronous iteration over the parsed records, which is useful for handling large CSV files or streams.
const parse = require('csv-parse');
const fs = require('fs');
const parser = fs.createReadStream('/path/to/csv-file.csv').pipe(parse({columns: true}));
(async () => {
for await (const record of parser) {
// Work with each record
}
})();
Papa Parse is a powerful CSV parser that can handle large files and malformed input gracefully. It works in both browser and server environments. Compared to csv-parse, Papa Parse has a more user-friendly API and can automatically detect delimiters.
Fast-csv is another CSV parsing and formatting library for Node.js. It provides a simple API and supports both stream and callback-based processing. It is known for its speed and efficiency, but csv-parse offers more advanced features and customization options.
csvtojson is a full-featured CSV parser library that converts CSV to JSON. One of its main differences from csv-parse is that it focuses on the JSON output format, whereas csv-parse provides more flexibility in handling the parsed data.
Part of the CSV module, this project is a parser converting CSV text input into arrays or objects. It implements the Node.js stream.Transform
API. It also provides a simple callback-based API for convenience. It is both extremely easy to use and powerful. It was first released in 2010 and is used against big data sets by a large community.
FAQs
CSV parsing implementing the Node.js `stream.Transform` API
The npm package csv-parse receives a total of 4,108,596 weekly downloads. As such, csv-parse popularity was classified as popular.
We found that csv-parse demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.