July 19, 2024


Technology can't be beat

CSV package for Node.js version 6

CSV package for Node.js version 6

Version 6 of the csv package for Node.js is released along its sub projects. Here are the latest versions:

There has been a lot of commits since the last package was released, around 100, way to many to my opinion. Most of the efforts were on migrating to ECMAScript modules (ESM) and providing a robust build infrastructure based on Rollup. The website has been updated and enriched with many examples.

Before presenting the new features, here are the breaking changes first. Some module names have changed depending on your targeted environment. The documentation now provides extensive information and samples on this topic. Also, some options were renamed in the csv-parse package. There aren’t too many:

  • CommonJS users shall update the path to the sync modules, from package_name/lib/sync to package_name/sync.
  • Imports are always destructed, eg import parse from 'csv-parse', there are now default exports.
  • In the csv-parse package, option relax was renamed relax_quotes.
  • In the csv-parse package, option skip_lines_with_empty_values was renamed skip_records_with_empty_values.
  • In the csv-parse package, option skip_lines_with_error was renamed skip_records_with_error.

Here are the main features:

  • All projects and modules are now written as ECMAScript modules.
  • Transparent usage between CommonJS and ESM with package.json exports property
  • Wrote many samples integrated with the documentation website
  • Replace the browser distribution with the IIFE distribution generated by Rollup
  • New UMD distribution
  • Integrate lint rules on all js and coffee files
  • Backport compatibility with Node.js 8 in csv-stringify
  • In csv-parse, print current buffer with options skip_line_with_errors and raw
  • In csv-parse, option objname can now refer to index position
  • A few TypeScript enhancements

Here is a quick example illustrating some of the changes, using the csv-parse/lib/sync module. In the previous release, the code looked like:

const parse = require('csv-parse/lib/sync');
const records = parse('a, "b" ,c', 
  relax: true

In the latest release, the updated code is now:

// `parse` is now destructured, it is consistent with
// `const parse = require('csv/sync');` if you are using the `csv` package.
// Also, the path to the sync module is now 'csv-parse/sync'
const parse = require('csv-parse/sync');
const records = parse('a, "b" ,c', 
  // `relax` was renamed `relax_quotes`, this is one of the few options from
  // `csv-parse` which were renamed.
  relax_quotes: true

Please report bugs and propose features to the CSV repository on GitHub.