CSVParse for Node.js

IssuesGitHub

Option ltrim

The ltrim option ignore whitespace characters from the left side of a CSV field. Defaults to false. It does not remove whitespace present inside the quotes of a field.

Refer to the trim documentation to learn about which characters are interpreted as whitespaces.

Example

This example declare spaces around fields at multiple locations. The ones on the left side are trimmed while the other ones are preserved.

import assert from 'node:assert';
import { parse } from 'csv-parse/sync';

const data = [
  'a ,1',
  'b, 2 ',
  ' c,3'
].join('\n');
const records = parse(data, {
  ltrim: true
});
assert.deepStrictEqual(
  records, [
    [ 'a ', '1' ],
    [ 'b', '2 ' ],
    [ 'c', '3' ]
  ]
);

About

The Node.js CSV project is an open source product hosted on GitHub and developed by Adaltas.