martonlederer / esbuild-plugin-dsv

Use .tsv and .csv files as ES6 modules

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

esbuild-plugin-dsv

Use .tsv and .csv files as ES6 modules.

Install

yarn add -D esbuild-plugin-dsv

or

npm i -D esbuild-plugin-dsv

Usage

Add to your esbuild plugins list:

const esbuild = require("esbuild");
const { dsvPlugin } = require("esbuild-plugin-dsv");

esbuild.build({
  ...
  plugins: [
    dsvPlugin()
  ]
  ...
});

Options

You can customize how esbuild-plugin-dsv parses .tsv and .csv files the following way:

dsvPlugin({
  // options
});

transform

With this function, you can mutate the parsed/resolved .tsv and .csv files:

  transform(data, extension) {
    // transform the file
    // the data holds a "DSVRowArray" type data
    // parsed from the imported file
    // read more about it here:
    // https://github.com/d3/d3-dsv#csvParse
    // https://github.com/d3/d3-dsv#tsvParse
    // the extension can be "TSV" or "CSV"
    return data;
  }

About

Use .tsv and .csv files as ES6 modules

License:MIT License


Languages

Language:TypeScript 66.9%Language:JavaScript 33.1%