csv-simple-parser is a lightweight, fast, and highly configurable CSV parsing library for JavaScript and TypeScript. It offers robust functionality for converting CSV string data into either arrays of string arrays or arrays of objects (when headers are present). A key differentiator is its built-in, configurable type inference system, which can automatically convert string values to numbers, booleans, or nulls, or be customized with a user-defined inference function. The library is currently at version 2.0.2 and appears to have a stable, though not rapid, release cadence, focusing on simplicity and performance. It's suitable for both Node.js and browser environments, providing a straightforward API for common CSV parsing tasks without the overhead of more complex streaming parsers.
npm install csv-simple-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing CSV strings into objects with header and type inference, using custom delimiters, and also parsing into arrays of arrays.
Pass `{ header: true }` in the options object to the `parse` function.To enable automatic type inference, use `{ infer: true }` in the options. For custom logic, provide an `infer` function: `{ infer: (value, x, y, isQuoted) => { /* custom logic */ return value; } }`.Configure `delimiter` and `quote` options if your CSV differs from the standard: `parse(csv, { delimiter: ';', quote: "'" })`. For strict newline parsing, consider `optimistic: false`.Consult the official changelog or migration guide on the project's GitHub repository for `csv-simple-parser` to identify any specific breaking changes when upgrading to version 2.x or later.
Switch to ESM `import parse from 'csv-simple-parser';` or, if strictly in CommonJS, try `const parse = require('csv-simple-parser').default;` (though direct ESM import is preferred).Ensure the `header` option is set to `true`: `parse(csvString, { header: true })`. This instructs the parser to use the first row as keys for the resulting objects.Ensure that numeric, boolean, or null values in your CSV are *not* explicitly quoted if you want the default `infer: true` to convert them. If they must be quoted, provide a custom `infer` function that handles parsing within quoted contexts.
No dependency data recorded yet.