@sdsjs/csv-parser
v1.0.7
Published
A csv parser for lazy parse csv file, it is a async iterator, based on papaparse
Downloads
13
Maintainers
Readme
@sdsjs/csv-parser
A csv parser for lazy parse csv file, it is a async iterator, based on papaparse. Support:
- http path
- fs path (for nodejs)
Install
$ npm install @sdsjs/csv-parser
Usage
example one,use through asyn iterator:
import { CsvParser } from "@sdsjs/csv-parser"; async function test () { const csvParser = new CsvParser({ path: [ "E:\\test.csv", // "http://xxx/test.csv" ], logger: console, chunkSize: 1400000, // default chunkSize is `1400000` byte,if this parameter is not set }); for await (let v of csvParser) { console.log(v) } } test();
example two,self call next:
import { CsvParser } from "@sdsjs/csv-parser"; async function test () { const csvParser = new CsvParser({ path: [ "E:\\test.csv", // "http://xxx/test.csv" ], logger: console, chunkSize: 1400000, // default chunkSize is `1400000` byte,if this parameter is not set }); const temp = []; let ret = await csvParser.next(); temp.push(...ret.value); while (!ret.done) { ret = await csvParser.next(); !ret.done && temp.push(...ret.value); } return temp; } test();