1 | import CSV from 'csv-string';
|
2 | import { writeTo } from './utils';
|
3 |
|
4 | function CSVParse(data, feed) {
|
5 | const separator = this.getParam('separator');
|
6 | const quote = this.getParam('quote');
|
7 | if (!this.handle) {
|
8 | this.handle = CSV.createStream({ separator, quote });
|
9 | this.handle.on('data', obj => feed.write(obj));
|
10 | }
|
11 | if (!this.isLast()) {
|
12 | writeTo(this.handle,
|
13 | data,
|
14 | () => feed.end());
|
15 | } else {
|
16 | this.handle.end(() => feed.close());
|
17 | }
|
18 | }
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | export default {
|
30 | CSVParse,
|
31 | };
|