Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

rollup-plugin-dsv

rollup20MITdeprecated1.2.0

This module has been deprecated and is no longer maintained. Please use @rollup/plugin-dsv.

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

readme

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

changelog

rollup-plugin-dsv changelog

1.2.0

  • Pass id to processRow

1.1.2

  • Return a name

1.1.1

  • Add missing dependencies

1.1.0

  • Support options.processRow

1.0.1

  • Include correct files in package

1.0.0

  • First release