Node CSV version 0.2.1

Node CSV version 0.2.1

Do you like our work......we hire!

Never miss our publications about Open Source, big data and distributed systems, low frequency of one email every two months.

After the announcement of the version 0.2.0 of the Node.js CSV parser at the beginning of october, we are releasing today a new version 0.2.1. This is mostly a bug fix release with enhanced documentation. However it does introduce a few interesting functionalities as well. The parser documentation has been updated to reflect this new release.

Have from stream send pause/resume advisories from CSV to stream

See GitHub issue #52 and issue #54.
Thanks for Dan Kearns for discovering this bug and to Doug Wilson for providing such a great fix. This is an important correction and implies that all the users of the 0.2.0 release to migrate toward this release.

Asynchronous transformations

See GitHub issue #30.
This seems like the most requested/interested feature present in this release. The CSV parser may now support two types of callbacks, synchronous and asynchronous. The distinction is made after the callback argument signature. It expects to be called asynchronously if 3 arguments are defined, otherwise it will be run synchronously. The following two examples reverse the columns on each line.

Synchronous example:

csv()
.from('a,b\n1,2')
.to(console.log)
.transform (data, index, callback) ->
  data.reverse()

Asynchronous example:

csv()
.from('a,b\n1,2')
.to(console.log)
.transform (data, index, callback) ->
  process.nextTick ->
    callback null, data.reverse()

Line number in parsing error

See GitHub issue #40.
Thanks for E. Timothy Uy for raising the request. The idea is to enhance parsing error message with the line number where the error occur. Additionally, we introduce a new line number property accessible through csv().parser.lines.

Column property to column name

See GitHub issue #53.
This feature was request by Alex Zylman who needed a way to print custom column names in its output file. The retained solution was to allow the from.options.columns and to.options.columns options to be defined as an object. Here’s an example:

data = 'field1,field2,field3\nval1,val2,val3'
csv()
.from(data, columns: true)
.to (data) ->
  data.should.eql 'column1,column3\nval1,val3'
  next()
, columns: {field1: 'column1', field3: 'column3'}, header: true

Skip UTF BOM from first data event on UTF-8 decoded stream

See GitHub issue #36 and issue #55.
This feature was raised by E. Timothy Uy and fix by Doug Wilson who became a serious contributor to the project.

Update and improve samples

See GitHub issue #56.
Thanks to Kevin Old who took the time to pass through each sample and align them with the 0.2.0 API.

Backward compatibility width Node.js < 0.8.x

This is a minor bug introduce after the 0.2 updates and the migration toward Node.js version 0.8. The path.exists was renamed fs.exists. The fix was easy by creating the fs.exists function in case it doesn’t exist. Here’s an extract from the source code:

fs = require 'fs'
path = require 'path'
fs.exists ?= path.exists

And more…

Other enhancements describe in the change log are:

  • Pass options in the from and to functions
  • Function to.string receives the number of written records
  • Fix from array with the column options
  • Travis support
  • More doc about columns and transformation
Share this article

Canada - Morocco - France

We are a team of Open Source enthusiasts doing consulting in Big Data, Cloud, DevOps, Data Engineering, Data Science…

We provide our customers with accurate insights on how to leverage technologies to convert their use cases to projects in production, how to reduce their costs and increase the time to market.

If you enjoy reading our publications and have an interest in what we do, contact us and we will be thrilled to cooperate with you.

Support Ukrain