A webpack module to load dsv (e.g. .csv or .tsv) files.
JavaScript
Latest commit e5c9864 Dec 21, 2016 @stefankeil stefankeil committed on GitHub Merge pull request #10 from lennerd/fix-columns
Add columns property to the serialised response.

README.md

Webpack dsv loader

A Webpack plugin for loading dsv files (for example .csv).

Installation

Install via npm:

npm install --save dsv-loader

Usage

You can require dsv data like this:

var data = require('dsv!./data.csv');
// => returns data.csv content as json parsed object

The loader will translate the data.csv file into a JSON Object.

Usage with webpack.config

To require dsv files like this: require('data.csv') , you can add the dsv-loader to your webpack config:

module : {
  loaders : [
    { test: /\.csv$/, loader: 'dsv-loader' } //will load all .csv files with dsv-loader by default
  ]
}

Options

delimiter

Tells the loader which delimiter is used to seperate the data. Default: ','

Examples:

var data = require('dsv?delimiter=;!./data.csv'); //load data seperated by semicolon

var data = require('dsv?delimiter=x!./data.csv'); //load data seperated by an 'x'

Example

data.csv

Hello World
42 "fish"
foo bar
var data = require(data.csv) //[{"Hello": "42", "World": "fish"}, {"Hello": "foo", "World": "bar"}, columns: ["Hello", "World"]]

Credits

  • Inspired by webpack's json-loader
  • DSV parsing done with dsv by Mike Bostock