Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/dsv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

## Requirements

This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v14.0.0+) and Rollup v1.20.0+.
This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v14.0.0+) and Rollup v2.78.0+.

## Install

Expand Down
2 changes: 1 addition & 1 deletion packages/dsv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"rollup-plugin"
],
"peerDependencies": {
"rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0"
"rollup": "^2.78.0||^3.0.0||^4.0.0"
},
"peerDependenciesMeta": {
"rollup": {
Expand Down
34 changes: 22 additions & 12 deletions packages/dsv/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,39 @@ import { createFilter } from '@rollup/pluginutils';
import stripBom from 'strip-bom';

const parsers = { '.csv': csvParse, '.tsv': tsvParse };
const idFilter = new RegExp(
`\\.(?:${Object.keys(parsers)
.map((ext) => ext.slice(1))
.join('|')})$`
);

export default function dsv(options = {}) {
const filter = createFilter(options.include, options.exclude);

return {
name: 'dsv',

transform(code, id) {
if (!filter(id)) return null;
transform: {
filter: {
id: idFilter
},
handler(code, id) {
if (!filter(id)) return null;

const ext = extname(id);
if (!(ext in parsers)) return null;
const ext = extname(id);
if (!(ext in parsers)) return null;

let rows = parsers[ext](stripBom(code));
let rows = parsers[ext](stripBom(code));

if (options.processRow) {
rows = rows.map((row) => options.processRow(row, id) || row);
}
if (options.processRow) {
rows = rows.map((row) => options.processRow(row, id) || row);
}

return {
code: `export default ${toSource(rows)};`,
map: { mappings: '' }
};
return {
code: `export default ${toSource(rows)};`,
map: { mappings: '' }
};
}
}
};
}
Loading