npm.io
0.0.4 • Published 2 years ago

esbuild-plugin-dsv

Licence
MIT
Version
0.0.4
Deps
3
Size
7 kB
Vulns
0
Weekly
0
Stars
2

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;
  }