@sdsjs/csv-parser
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

@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();

Package Sidebar

Install

npm i @sdsjs/csv-parser

Weekly Downloads

5

Version

1.0.7

License

MIT

Unpacked Size

63.3 kB

Total Files

18

Last publish

Collaborators

  • sdsjs