CSVParse for Node.js


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.


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'
const records = parse(data, {
  rtrim: true
  records, [
    [ 'a', '1' ],
    [ 'b', ' 2' ],
    [ ' c', '3' ]