A webpack module to load dsv (e.g. .csv or .tsv) files.
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore edit package.json Jan 13, 2015
README.md DSV-Loader Feb 28, 2018
index.js Add columns property to the serialised response. Oct 7, 2016
package.json update version and doku Dec 21, 2016

README.md

Webpack dsv loader

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

Installation

Install via npm:

npm install --save-dev dsv-loader

Usage

You can require dsv data like this:

const data = require('dsv-loader!./data.csv');

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: {
  rules: [{
    test: /\.(c|d|t)sv$/, // load all .csv, .dsv, .tsv files with dsv-loader
    use: ['dsv-loader'] // or dsv-loader?delimiter=,
  }]
}

Example

data.csv

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

Options

delimiter

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

Examples:

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

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

rows

Tells the loader if it should use the first row as columns row. Default: Yes

Examples:

const data = require('dsv-loader!./data.csv'); //[{"Hello": "42", "World": "fish"}, {"Hello": "foo", "World": "bar"}, columns: ["Hello", "World"]]

const data = require('dsv-loader?rows!./data.csv'); //[{"Hello": "World"}, { "42": "fish"},{ "foo": "bar"}

Credits

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