CSVParse for Node.js

IssuesGitHub

Option rtrim

Table of Contents

The rtrim option ignore whitespace characters from the right 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 right side are trimmed while the other ones are preserved.

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

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