1.2.0 • Published 8 years ago

rollup-plugin-dsv v1.2.0

Weekly downloads
19
License
MIT
Repository
github
Last release
8 years ago

rollup-plugin-dsv

Convert .csv and .tsv files into JavaScript modules with d3-dsv.

Installation

npm install --save-dev rollup-plugin-dsv

Usage

import { rollup } from 'rollup';
import dsv from 'rollup-plugin-dsv';

rollup({
  entry: 'main.js',
  plugins: [ dsv() ]
}).then(...)

Inside your code, you can do this sort of thing:

# fruit.csv
type,count
apples,7
pears,4
bananas,5
// main.js
import fruit from './fruit.csv';

assert.deepEqual( fruit, [
	{ type: 'apples',  count: '7' },
	{ type: 'pears',   count: '4' },
	{ type: 'bananas', count: '5' }
]);

You can also import .tsv files.

Custom processors

You can supply a function that processes each row in the returned array – for example turning numeric values into numbers. The function can either manipulate the existing row object, or return an entirely new one.

rollup({
  entry: 'main.js',
  plugins: [
    dsv({
      processRow: function ( row, id ) {
        Object.keys( row ).forEach( key => {
          var value = row[ key ];
          row[ key ] = isNaN( +value ) ? value : +value;
        });
      }
    })
  ]
}).then(...)

License

MIT

1.2.0

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago