node-csvify

CSV and TSV transformations for Browserify v2

npm install node-csvify
2 downloads in the last week
7 downloads in the last month

node-csvify

Version 0.0.0

Require CSV/TSV files directly in Browserify v2

When bundling an app using Browserify, it's often convenient to be able to include your .csv (comma-delimited) or .tsv (tab-delimited) files just as you would .json files (which Node natively understands). This small script allows you to require() them directly.

Installation

npm install node-csvify

Usage

Simply require your data files as you might anything else:

var states = require('./states.csv');
var countries = require('./countries.tsv');

Then, when running browserify, pass this module as a transformation on the command line.

browserify -t node-csvify script.js > bundle.js

How it works

This module uses d3's CSV and TSV parsing functions to convert the files to Javascript objects. d3 is very smart about converting headers to property names. For example, this:

first,last
Chris,Wilson
Mike,Bostock
Miles,Davis

Becomes this:

[ { first: 'Chris', last: 'Wilson' },
  { first: 'Mike', last: 'Bostock' },
  { first: 'Miles', last: 'Davis' } ]
npm loves you