{"id":13326,"library":"incremental-csv-parser","title":"Incremental CSV Parser","description":"Incremental CSV Parser is a fast, lightweight, and dependency-free library for parsing Comma Separated Values (CSV) data in both browser and Node.js environments. It currently stands at stable version 1.1.1, with recent updates (like v1.1.0 adding `.headers()`) indicating active maintenance, though a strict release cadence is not specified. Key differentiators include its incremental parsing API, full compliance with RFC4180, and minimal footprint due to zero external dependencies. A crucial aspect of its design is that all parsed column values are returned as strings, meaning it does not automatically parse numbers, dates, or other data types, requiring explicit conversion by the consumer. It provides both ESM and CJS builds and ships with TypeScript type definitions for enhanced developer experience.","status":"active","version":"1.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/AllAwesome497/incremental-csv-parser","tags":["javascript","typescript"],"install":[{"cmd":"npm install incremental-csv-parser","lang":"bash","label":"npm"},{"cmd":"yarn add incremental-csv-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add incremental-csv-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Use for parsing an entire CSV string at once. While a CJS build is provided, modern usage prefers ESM imports.","wrong":"const { parse } = require('incremental-csv-parser');","symbol":"parse","correct":"import { parse } from 'incremental-csv-parser';"},{"note":"This class enables incremental parsing of CSV data, processing chunks as they arrive. Modern usage prefers ESM imports.","wrong":"const { CSVParser } = require('incremental-csv-parser');","symbol":"CSVParser","correct":"import { CSVParser } from 'incremental-csv-parser';"},{"note":"Leverage TypeScript generics to define expected column names and types, providing compile-time safety and better autocompletion for parsed rows.","symbol":"CSVParser (with generics)","correct":"import { CSVParser } from 'incremental-csv-parser'; type MyColumns = 'id' | 'name'; const parser = new CSVParser<MyColumns>(row => console.log(row));"}],"quickstart":{"code":"import { CSVParser } from 'incremental-csv-parser';\n\n// Simulating a readable stream or chunked data input\nconst csvDataChunks = [\n  'header1,header2,header3\\n',\n  'valueA1,valueA2,valueA3\\n',\n  'valueB1,valueB2,valueB3\\n',\n  'valueC1,valueC2,valueC3\\n',\n  'valueD1,valueD2,valueD3' // last chunk without a trailing newline\n];\n\nconst parsedRows = [];\nconst parser = new CSVParser((row) => {\n  parsedRows.push(row);\n  console.log('Parsed Row:', row); // Log each row as it's parsed\n});\n\nconsole.log('Starting incremental CSV parsing...');\n\nfor (const chunk of csvDataChunks) {\n  parser.process(chunk);\n}\n\n// After processing all chunks, call flush to ensure any buffered data is emitted\nparser.flush();\n\nconsole.log('Incremental parsing complete. All rows:', parsedRows);\n\n// Verify the parsed headers from the latest version (v1.1.0)\nconsole.log('Parsed Headers (if available):', parser.headers());","lang":"javascript","description":"Demonstrates how to use the `CSVParser` class for incremental processing of CSV data chunks, collecting parsed rows, and accessing headers."},"warnings":[{"fix":"Implement explicit type conversion logic for specific columns after receiving the parsed row objects (e.g., `parseInt(row.id, 10)`, `new Date(row.timestamp)`).","message":"All column values are strictly treated as strings. Numbers, dates, booleans, or other data types will not be automatically parsed or converted, requiring manual transformation post-parsing.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Prefer `import` statements (e.g., `import { parse } from 'incremental-csv-parser';`) in ESM projects. If strictly using CommonJS, ensure your environment correctly handles the CJS build.","message":"Attempting to use `require()` for imports in an environment configured for ESM (e.g., Node.js with `\"type\": \"module\"` in `package.json`) can lead to module resolution errors or incorrect module loading.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure your project uses `import { CSVParser } from 'incremental-csv-parser';` when operating in an ESM environment. If using CommonJS, verify correct `const { CSVParser } = require('incremental-csv-parser');` usage and project setup.","cause":"Using `require()` syntax in an ESM context for a module that is primarily ESM-first or has conflicting module exports.","error":"TypeError: (0 , incremental_csv_parser__WEBPACK_IMPORTED_MODULE_0__.CSVParser) is not a constructor"},{"fix":"Define a union type for your column names (e.g., `type MyColumns = 'id' | 'name';`) and pass it as a generic to the parser: `new CSVParser<MyColumns>(...)` or `parse<MyColumns>(...)`.","cause":"When using TypeScript, the parser defaults to `Record<string, string>` for row types. Direct property access (e.g., `row.myColumn`) will fail unless specific column types are provided.","error":"Property 'myColumn' does not exist on type '{ [key: string]: string; }'."},{"fix":"After parsing, explicitly convert the string values to the desired data type using standard JavaScript functions like `Number()`, `parseInt()`, `parseFloat()`, or `new Date()`.","cause":"The parser's design principle is to treat all CSV cell values as strings, adhering to its lightweight and no-automatic-conversion philosophy.","error":"Expected numerical values are returned as strings (e.g., '123' instead of 123)."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null}