Skip to content

wbkd/dsv-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A webpack module to load dsv (e.g. .csv or .tsv) files.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published