Option to_line

Table of Contents

The to_line option handles records until a requested line number is reached. It is disabled by default with the value -1.

  • Type: number
  • Coercion: string to number
  • Optional
  • Default: -1
  • Since: 4.0.0
  • Related: from_line, from, to — see Available Options

The line matching the value is parsed and the record is including the output. If the record does not end on the line, for example when the new line character is escaped or quoted, it will be disregarded.


This example return the first two lines and skip all the following records.

const parse = require('csv-parse/lib/sync')
const assert = require('assert')

const records = parse(`
`.trim(), {
  to_line: 2
  records, [
    [ 'a', '1' ],
    [ 'b', '1' ]