Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

incremental-csv-parser

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

incremental-csv-parser

A simple, browser compatible, incremental CSV parser.

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.6K
decreased by-29.7%
Maintainers
1
Weekly downloads
 
Created
Source

Incremental CSV Parser

A fast & lightweight CSV parser with an incremental parsing api. No dependencies; browser compatible. Includes ESM and CJS builds. All column values are strings (numbers and dates will not automatically be parsed).

Fully compatible with rfc4180.

Basic parsing

import { parse } from 'incremental-csv-parser';


const results = await parse(`a,b,c,d
1,2,3,4
5,6,7,8
`);

console.log(results);
// [
//   { a: '1', b: '2', c: '3', d: '4' },
//   { a: '5', b: '6', c: '7', d: '8' },
// ]

Incremental parsing

import { CSVParser } from 'incremental-csv-parser';

const results = [];

const parser = new CSVParser((row) => {
  results.push(row);
});

parser.process('a,b,c,d\n');
parser.process('1,2,3,4\n');
console.log(results.shift()); // { a: '1', b: '2', c: '3', d: '4' }
parser.process('5,6,7,8');
parser.flush();
console.log(results.shift()); // { a: '5', b: '6', c: '7', d: '8' }

Typescript support

If column names are known ahead of time, they can be passed in via generics.

import { CSVParser } from 'incremental-csv-parser';

type ColumnName = 'a' | 'b' | 'c' | 'd';
const results: Record<ColumnName, string> = [];

const parser = new CSVParser<ColumName>((row) => {
  results.push(row);
});

CSV files without pre-defined headers

Both the parse function and CSVParser class have an optional second argument for explicitly providing column names for a csv.

import { CSVParser } from 'incremental-csv-parser';

const columns = ['a', 'b', 'c', 'd'];

const results = parse(`1,2,3,4
5,6,7,8`, columns);

console.log(results);
// [
//   { a: '1', b: '2', c: '3', d: '4' },
//   { a: '5', b: '6', c: '7', d: '8' },
// ]

FAQs

Package last updated on 22 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc